Update hex to string

This commit is contained in:
mhsjlw 2015-08-23 10:58:59 -04:00
parent a3a24eeee8
commit 6cec112004
2 changed files with 54 additions and 32 deletions

80
app.js
View file

@ -29,10 +29,10 @@ server.on('login', function(client) {
}); });
// send init data so client will start rendering world // send init data so client will start rendering world
client.write(0x01, { client.write('chat', {
entityId: client.id, entityId: client.id,
levelType: 'default', levelType: 'default',
gameMode: 1, gameMode: 0,
dimension: 0, dimension: 0,
difficulty: 0, difficulty: 0,
maxPlayers: server.maxPlayers maxPlayers: server.maxPlayers
@ -42,26 +42,28 @@ server.on('login', function(client) {
console.log(err); console.log(err);
return; return;
} }
client.write(0x26, packetData); client.write('map_chunk_bulk', packetData);
client.write(0x08, { client.write('position', {
x: 6, x: 6,
y: 53, y: 53,
z: 6, z: 6,
yaw: 0, yaw: 0,
pitch: 0, pitch: 0,
onGround: true flags: 0x00
}); });
console.log("Written position, player should spawn"); console.log("Written position, player should spawn");
client.write(0x03, {
client.write('flying', {
age: [0,0], age: [0,0],
time: [0,1] time: [0,1]
}); });
client.write(0x2B, {
client.write('game_state_change', {
reason: 3, reason: 3,
gameMode: 1 gameMode: 1
}); });
}); });
client.on([states.PLAY, 0x01], function(data) { client.on([states.PLAY, 'chat'], function(data) {
var message = '<'+client.username+'>' + ' ' + data.message; var message = '<'+client.username+'>' + ' ' + data.message;
broadcast(message, client.username); broadcast(message, client.username);
console.log(message); console.log(message);
@ -79,32 +81,52 @@ server.on('listening', function() {
console.log('Server listening on port', server.socketServer.address().port); console.log('Server listening on port', server.socketServer.address().port);
}); });
function broadcast(message, username) { // function broadcast(message, username) {
// var client, translate;
// translate = username ? 'chat.type.announcement' : 'chat.type.text';
// username = username || 'Server';
// for (var clientId in server.clients) {
// if (!server.clients.hasOwnProperty(clientId)) continue;
// client = server.clients[clientId];
// var msg = {
// translate: translate,
// "with": [
// username
// ]
// };
// if (typeof message === "string") {
// msg["with"].push(message);
// } else {
// Object.keys(message).forEach(function(key) {
// if (key === "text") {
// msg["with"].push(message[key]);
// } else {
// msg[key] = message[key];
// }
// });
// }
// client.write('success', { message: JSON.stringify(msg) });
// }
function broadcast(message, exclude, username) {
var client, translate; var client, translate;
translate = username ? 'chat.type.announcement' : 'chat.type.text'; translate = username ? 'chat.type.announcement' : 'chat.type.text';
username = username || 'Server'; username = username || 'Server';
for (var clientId in server.clients) { for(var clientId in server.clients) {
if (!server.clients.hasOwnProperty(clientId)) continue; if(!server.clients.hasOwnProperty(clientId)) continue;
client = server.clients[clientId]; client = server.clients[clientId];
var msg = { if(client !== exclude) {
translate: translate, var msg = {
"with": [ translate: translate,
username "with": [
] username,
}; message
if (typeof message === "string") { ]
msg["with"].push(message); };
} else { client.write('chat', {message: JSON.stringify(msg)});
Object.keys(message).forEach(function(key) {
if (key === "text") {
msg["with"].push(message[key]);
} else {
msg[key] = message[key];
}
});
} }
client.write(0x02, { message: JSON.stringify(msg) });
} }
} }

View file

@ -141,7 +141,7 @@ ChunkColumn.prototype.unpack_section = function(buff, section, mask) {
} }
ChunkColumn.prototype.pack = function() { ChunkColumn.prototype.pack = function() {
var bufs = new []; var bufs = [];
var mask1 = 0; var mask1 = 0;
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
if (this.chunks[i] !== null) { if (this.chunks[i] !== null) {
@ -163,7 +163,7 @@ ChunkColumn.prototype.pack = function() {
} }
ChunkColumn.prototype.pack_section = function(section) { ChunkColumn.prototype.pack_section = function(section) {
var bufs = new []; var bufs = [];
for (var i = 0; i < 16; i++) { for (var i = 0; i < 16; i++) {
if (this.chunks[i] !== null) if (this.chunks[i] !== null)
bufs.push(this.chunks[i][section].pack()); bufs.push(this.chunks[i][section].pack());
@ -192,7 +192,7 @@ World.prototype.unpack = function(packetData) {
} }
World.prototype.packMapChunkBulk = function() { World.prototype.packMapChunkBulk = function() {
var bufs = new []; var bufs = [];
var metadatas = []; var metadatas = [];
var cb = arguments[arguments.length - 1]; var cb = arguments[arguments.length - 1];