mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 06:03:33 -04:00
Merge pull request #175 from rom1504/remove_write_cb
remove write callback
This commit is contained in:
commit
31d8f05b9a
@ -168,11 +168,7 @@ Client.prototype.setCompressionThreshold = function(threshold) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function noop(err) {
|
Client.prototype.write = function(packetId, params) {
|
||||||
if(err) throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
Client.prototype.write = function(packetId, params, cb = noop) {
|
|
||||||
if(Array.isArray(packetId)) {
|
if(Array.isArray(packetId)) {
|
||||||
if(packetId[0] !== this.state)
|
if(packetId[0] !== this.state)
|
||||||
return false;
|
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];
|
var packetName = protocol.packetNames[this.state][this.isServer ? "toClient" : "toServer"][packetId];
|
||||||
debug("writing packetId " + this.state + "." + packetName + " (0x" + packetId.toString(16) + ")");
|
debug("writing packetId " + this.state + "." + packetName + " (0x" + packetId.toString(16) + ")");
|
||||||
debug(params);
|
debug(params);
|
||||||
this.serializer.write({ packetId, params }, cb);
|
this.serializer.write({ packetId, params });
|
||||||
};
|
};
|
||||||
|
|
||||||
Client.prototype.writeRaw = function(buffer) {
|
Client.prototype.writeRaw = function(buffer) {
|
||||||
|
44
src/index.js
44
src/index.js
@ -125,11 +125,8 @@ function createServer(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.once([states.STATUS, 0x01], function(packet) {
|
client.once([states.STATUS, 0x01], function(packet) {
|
||||||
client.write(0x01, {time: packet.time},function(err){
|
client.write(0x01, {time: packet.time});
|
||||||
if(err)
|
client.end();
|
||||||
throw err;
|
|
||||||
client.end();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
client.write(0x00, {response: JSON.stringify(response)});
|
client.write(0x00, {response: JSON.stringify(response)});
|
||||||
}
|
}
|
||||||
@ -215,22 +212,19 @@ function createServer(options) {
|
|||||||
}
|
}
|
||||||
//client.write('compress', { threshold: 256 }); // Default threshold is 256
|
//client.write('compress', { threshold: 256 }); // Default threshold is 256
|
||||||
//client.compressionThreshold = 256;
|
//client.compressionThreshold = 256;
|
||||||
client.write(0x02, {uuid: client.uuid, username: client.username},function(err){
|
client.write(0x02, {uuid: client.uuid, username: client.username});
|
||||||
if(err)
|
client.state = states.PLAY;
|
||||||
throw err;
|
loggedIn = true;
|
||||||
client.state = states.PLAY;
|
startKeepAlive();
|
||||||
loggedIn = true;
|
|
||||||
startKeepAlive();
|
|
||||||
|
|
||||||
clearTimeout(loginKickTimer);
|
clearTimeout(loginKickTimer);
|
||||||
loginKickTimer = null;
|
loginKickTimer = null;
|
||||||
|
|
||||||
server.playerCount += 1;
|
server.playerCount += 1;
|
||||||
client.once('end', function() {
|
client.once('end', function() {
|
||||||
server.playerCount -= 1;
|
server.playerCount -= 1;
|
||||||
});
|
|
||||||
server.emit('login', client);
|
|
||||||
});
|
});
|
||||||
|
server.emit('login', client);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
server.listen(port, host);
|
server.listen(port, host);
|
||||||
@ -301,13 +295,10 @@ function createClient(options) {
|
|||||||
serverHost: host,
|
serverHost: host,
|
||||||
serverPort: port,
|
serverPort: port,
|
||||||
nextState: 2
|
nextState: 2
|
||||||
},function(err){
|
});
|
||||||
if(err)
|
client.state = states.LOGIN;
|
||||||
throw err;
|
client.write(0x00, {
|
||||||
client.state = states.LOGIN;
|
username: client.username
|
||||||
client.write(0x00, {
|
|
||||||
username: client.username
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,9 +357,6 @@ function createClient(options) {
|
|||||||
client.write(0x01, {
|
client.write(0x01, {
|
||||||
sharedSecret: encryptedSharedSecretBuffer,
|
sharedSecret: encryptedSharedSecretBuffer,
|
||||||
verifyToken: encryptedVerifyTokenBuffer,
|
verifyToken: encryptedVerifyTokenBuffer,
|
||||||
},function(err){
|
|
||||||
if(err)
|
|
||||||
throw err;
|
|
||||||
});
|
});
|
||||||
client.setEncryption(sharedSecret);
|
client.setEncryption(sharedSecret);
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,8 @@ function ping(options, cb) {
|
|||||||
serverHost: host,
|
serverHost: host,
|
||||||
serverPort: port,
|
serverPort: port,
|
||||||
nextState: 1
|
nextState: 1
|
||||||
},function(err){
|
|
||||||
if(err)
|
|
||||||
throw err;
|
|
||||||
client.state = states.STATUS;
|
|
||||||
});
|
});
|
||||||
|
client.state = states.STATUS;
|
||||||
});
|
});
|
||||||
|
|
||||||
client.connect(port, host);
|
client.connect(port, host);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user