mirror of
https://github.com/Threnklyn/MinecraftChat.git
synced 2026-05-28 08:48:30 +02:00
Core vanilla functionality
The client now understands chat events, command usage events, death events, teleport events, and join/leave events
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
var escapeHtml = require('../../utils').escapeHtml;
|
||||
|
||||
module.exports = function(socket) {
|
||||
|
||||
socket.mcbot.on('chat', function(username, message) {
|
||||
var text = '<' + username + '> ' + message;
|
||||
socket.emit('bot:message', escapeHtml(text));
|
||||
});
|
||||
|
||||
};
|
||||
@@ -1,4 +1,7 @@
|
||||
var stringToCode = require('../../utils').stringToCode;
|
||||
var parseVanilla = require('../../parsers/vanilla');
|
||||
var parseExtra = require('../../parsers/extra');
|
||||
|
||||
|
||||
var escapeHtml = require('../../utils').escapeHtml;
|
||||
|
||||
module.exports = function(socket) {
|
||||
@@ -9,76 +12,30 @@ module.exports = function(socket) {
|
||||
// empty buffer
|
||||
var buffer = '';
|
||||
|
||||
// modded servers match here
|
||||
|
||||
|
||||
|
||||
// parse for json objects with 'extra'
|
||||
if (message.extra) {
|
||||
buffer = parseExtra(message.extra);
|
||||
|
||||
// for each piece of text
|
||||
message.extra.forEach(function(data) {
|
||||
|
||||
// get the text out of the element
|
||||
var text;
|
||||
if (typeof data === 'string') {
|
||||
text = data;
|
||||
} else if (typeof data === 'object') {
|
||||
text = data.text;
|
||||
}
|
||||
|
||||
// if text is available
|
||||
if (text) {
|
||||
text = text.replace(/§k/ig, ''); // remove crazy format
|
||||
text = text.replace(/§l/ig, ''); // remove bold format
|
||||
buffer += '§' + stringToCode(data.color) + text; // add the text to the buffer
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// vanilla server matches here
|
||||
} else if (message.with) {
|
||||
var text;
|
||||
|
||||
switch (message.translate) {
|
||||
case 'chat.type.announcement':
|
||||
text = '§d[' + message.with[0].text + '] ';
|
||||
message.with[1].extra.forEach(function(x) {
|
||||
text += x;
|
||||
});
|
||||
break;
|
||||
case 'chat.type.admin':
|
||||
if (message.with[1].translate === 'commands.op.success') {
|
||||
text = '§eOpped ' + message.with[1].with;
|
||||
}
|
||||
break;
|
||||
case 'commands.players.list':
|
||||
text = '§eThere are ' + message.with[0] + '/' + message.with[1] + ' players online.';
|
||||
break;
|
||||
case 'commands.kick.success':
|
||||
text = '§e' + message.with[0] + ' kicked!';
|
||||
break;
|
||||
case 'commands.whitelist.add.success':
|
||||
text = '§f' + message.with[0] + ' whitelisted';
|
||||
break;
|
||||
case 'commands.whitelist.remove.success':
|
||||
text = '§f' + message.with[0] + ' removed from whitelist';
|
||||
break;
|
||||
case 'commands.whitelist.list':
|
||||
text = '§f' + message.with[0] + ' players in the whitelist';
|
||||
break;
|
||||
case 'commands.generic.usage':
|
||||
text = '§cInvalid command usage';
|
||||
break;
|
||||
}
|
||||
|
||||
buffer += text || '[i] [MinecraftChat] Unknown data received from server. [Unsuported Server]';
|
||||
|
||||
// if the text comes clean
|
||||
} else if (message.text) {
|
||||
buffer += message.text;
|
||||
buffer = message.text;
|
||||
|
||||
// if the message is vanilla
|
||||
} else if (message.translate) {
|
||||
buffer = parseVanilla(message);
|
||||
|
||||
// the message format is not handled (yet)
|
||||
} else {
|
||||
console.log(message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if none of the parsers returned anything, stop here
|
||||
if (!buffer) return;
|
||||
|
||||
// escape any html in the buffer
|
||||
buffer = escapeHtml(buffer);
|
||||
|
||||
@@ -4,6 +4,7 @@ module.exports = function(socket) {
|
||||
require('./events/login')(socket);
|
||||
require('./events/spawn')(socket);
|
||||
require('./events/message')(socket);
|
||||
// require('./events/chat')(socket);
|
||||
require('./events/end')(socket);
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user