Merge pull request #175 from rom1504/remove_write_cb

remove write callback
This commit is contained in:
Robin Lambertz 2015-05-23 01:14:43 +02:00
commit 31d8f05b9a
3 changed files with 19 additions and 38 deletions

View File

@ -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) {

View File

@ -125,11 +125,8 @@ function createServer(options) {
}
client.once([states.STATUS, 0x01], function(packet) {
client.write(0x01, {time: packet.time},function(err){
if(err)
throw err;
client.end();
});
client.write(0x01, {time: packet.time});
client.end();
});
client.write(0x00, {response: JSON.stringify(response)});
}
@ -215,22 +212,19 @@ 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.state = states.PLAY;
loggedIn = true;
startKeepAlive();
client.write(0x02, {uuid: client.uuid, username: client.username});
client.state = states.PLAY;
loggedIn = true;
startKeepAlive();
clearTimeout(loginKickTimer);
loginKickTimer = null;
clearTimeout(loginKickTimer);
loginKickTimer = null;
server.playerCount += 1;
client.once('end', function() {
server.playerCount -= 1;
});
server.emit('login', client);
server.playerCount += 1;
client.once('end', function() {
server.playerCount -= 1;
});
server.emit('login', client);
}
});
server.listen(port, host);
@ -301,13 +295,10 @@ 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
});
});
client.state = states.LOGIN;
client.write(0x00, {
username: client.username
});
}
@ -366,9 +357,6 @@ function createClient(options) {
client.write(0x01, {
sharedSecret: encryptedSharedSecretBuffer,
verifyToken: encryptedVerifyTokenBuffer,
},function(err){
if(err)
throw err;
});
client.setEncryption(sharedSecret);
}

View File

@ -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);