mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 14:13:45 -04:00
remove write callback
knowing when the packet has been sent is not an useful information : the fact that it's sent doesn't mean it is received and what we usually want is that the packets are in the proper order no when they are sent
This commit is contained in:
parent
f82f037f29
commit
3c61f24991
@ -168,11 +168,7 @@ Client.prototype.setCompressionThreshold = function(threshold) {
|
||||
}
|
||||
}
|
||||
|
||||
function noop(err) {
|
||||
if(err) throw err;
|
||||
}
|
||||
|
||||
Client.prototype.write = function(packetId, params, cb = noop) {
|
||||
Client.prototype.write = function(packetId, params) {
|
||||
if(Array.isArray(packetId)) {
|
||||
if(packetId[0] !== this.state)
|
||||
return false;
|
||||
@ -183,7 +179,7 @@ Client.prototype.write = function(packetId, params, cb = noop) {
|
||||
var packetName = protocol.packetNames[this.state][this.isServer ? "toClient" : "toServer"][packetId];
|
||||
debug("writing packetId " + this.state + "." + packetName + " (0x" + packetId.toString(16) + ")");
|
||||
debug(params);
|
||||
this.serializer.write({ packetId, params }, cb);
|
||||
this.serializer.write({ packetId, params });
|
||||
};
|
||||
|
||||
Client.prototype.writeRaw = function(buffer) {
|
||||
|
18
src/index.js
18
src/index.js
@ -125,12 +125,9 @@ function createServer(options) {
|
||||
}
|
||||
|
||||
client.once([states.STATUS, 0x01], function(packet) {
|
||||
client.write(0x01, {time: packet.time},function(err){
|
||||
if(err)
|
||||
throw err;
|
||||
client.write(0x01, {time: packet.time});
|
||||
client.end();
|
||||
});
|
||||
});
|
||||
client.write(0x00, {response: JSON.stringify(response)});
|
||||
}
|
||||
|
||||
@ -215,9 +212,7 @@ function createServer(options) {
|
||||
}
|
||||
//client.write('compress', { threshold: 256 }); // Default threshold is 256
|
||||
//client.compressionThreshold = 256;
|
||||
client.write(0x02, {uuid: client.uuid, username: client.username},function(err){
|
||||
if(err)
|
||||
throw err;
|
||||
client.write(0x02, {uuid: client.uuid, username: client.username});
|
||||
client.state = states.PLAY;
|
||||
loggedIn = true;
|
||||
startKeepAlive();
|
||||
@ -230,7 +225,6 @@ function createServer(options) {
|
||||
server.playerCount -= 1;
|
||||
});
|
||||
server.emit('login', client);
|
||||
});
|
||||
}
|
||||
});
|
||||
server.listen(port, host);
|
||||
@ -301,14 +295,11 @@ function createClient(options) {
|
||||
serverHost: host,
|
||||
serverPort: port,
|
||||
nextState: 2
|
||||
},function(err){
|
||||
if(err)
|
||||
throw err;
|
||||
});
|
||||
client.state = states.LOGIN;
|
||||
client.write(0x00, {
|
||||
username: client.username
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function onCompressionRequest(packet) {
|
||||
@ -366,9 +357,6 @@ function createClient(options) {
|
||||
client.write(0x01, {
|
||||
sharedSecret: encryptedSharedSecretBuffer,
|
||||
verifyToken: encryptedVerifyTokenBuffer,
|
||||
},function(err){
|
||||
if(err)
|
||||
throw err;
|
||||
});
|
||||
client.setEncryption(sharedSecret);
|
||||
}
|
||||
|
@ -37,11 +37,8 @@ function ping(options, cb) {
|
||||
serverHost: host,
|
||||
serverPort: port,
|
||||
nextState: 1
|
||||
},function(err){
|
||||
if(err)
|
||||
throw err;
|
||||
client.state = states.STATUS;
|
||||
});
|
||||
client.state = states.STATUS;
|
||||
});
|
||||
|
||||
client.connect(port, host);
|
||||
|
Loading…
x
Reference in New Issue
Block a user