mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 11:10:44 +00:00
Fix chatting
This commit is contained in:
parent
6cec112004
commit
6c39ef1b3f
1 changed files with 9 additions and 1 deletions
10
app.js
10
app.js
|
|
@ -7,6 +7,7 @@ var options = {
|
||||||
'max-players': 20,
|
'max-players': 20,
|
||||||
port: 25565,
|
port: 25565,
|
||||||
'online-mode': false,
|
'online-mode': false,
|
||||||
|
reducedDebugInfo: false
|
||||||
};
|
};
|
||||||
|
|
||||||
var world = new World();
|
var world = new World();
|
||||||
|
|
@ -19,6 +20,7 @@ for (var x = 0; x < 16;x++) {
|
||||||
var server = mc.createServer(options);
|
var server = mc.createServer(options);
|
||||||
|
|
||||||
server.on('login', function(client) {
|
server.on('login', function(client) {
|
||||||
|
|
||||||
broadcast({ text: client.username + ' joined the game.', color: "yellow" });
|
broadcast({ text: client.username + ' joined the game.', color: "yellow" });
|
||||||
var addr = client.socket.remoteAddress + ':' + client.socket.remotePort;
|
var addr = client.socket.remoteAddress + ':' + client.socket.remotePort;
|
||||||
console.log(client.username + ' connected', '(' + addr + ')');
|
console.log(client.username + ' connected', '(' + addr + ')');
|
||||||
|
|
@ -37,12 +39,15 @@ server.on('login', function(client) {
|
||||||
difficulty: 0,
|
difficulty: 0,
|
||||||
maxPlayers: server.maxPlayers
|
maxPlayers: server.maxPlayers
|
||||||
});
|
});
|
||||||
|
|
||||||
var chunkBulk = world.packMapChunkBulk([0,0], function(err, packetData) {
|
var chunkBulk = world.packMapChunkBulk([0,0], function(err, packetData) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
client.write('map_chunk_bulk', packetData);
|
client.write('map_chunk_bulk', packetData);
|
||||||
|
|
||||||
client.write('position', {
|
client.write('position', {
|
||||||
x: 6,
|
x: 6,
|
||||||
y: 53,
|
y: 53,
|
||||||
|
|
@ -51,6 +56,7 @@ server.on('login', function(client) {
|
||||||
pitch: 0,
|
pitch: 0,
|
||||||
flags: 0x00
|
flags: 0x00
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("Written position, player should spawn");
|
console.log("Written position, player should spawn");
|
||||||
|
|
||||||
client.write('flying', {
|
client.write('flying', {
|
||||||
|
|
@ -63,11 +69,13 @@ server.on('login', function(client) {
|
||||||
gameMode: 1
|
gameMode: 1
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on([states.PLAY, 'chat'], 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);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('packet', function(packet) {
|
client.on('packet', function(packet) {
|
||||||
console.log(packet);
|
console.log(packet);
|
||||||
})
|
})
|
||||||
|
|
@ -126,7 +134,7 @@ function broadcast(message, exclude, username) {
|
||||||
message
|
message
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
client.write('chat', {message: JSON.stringify(msg)});
|
client.write('chat', { message: JSON.stringify(msg), position: 0 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue