Merge pull request #259 from basicer/thenable-before-ping

Allow beforePing to receive a callback.
This commit is contained in:
Robin Lambertz 2015-10-04 22:13:40 +02:00
commit d7e74f7f9e

View File

@ -101,15 +101,25 @@ function createServer(options) {
"favicon": server.favicon "favicon": server.favicon
}; };
function answerToPing(err, response) {
if ( err ) return;
client.write('server_info', {response: JSON.stringify(response)});
}
if(beforePing) { if(beforePing) {
response = beforePing(response, client) || response; if ( beforePing.length > 2 ) {
beforePing(response, client, answerToPing);
} else {
answerToPing(null, beforePing(response, client) || response);
}
} else {
answerToPing(null, response);
} }
client.once('ping', function(packet) { client.once('ping', function(packet) {
client.write('ping', {time: packet.time}); client.write('ping', {time: packet.time});
client.end(); client.end();
}); });
client.write('server_info', {response: JSON.stringify(response)});
} }
function onLogin(packet) { function onLogin(packet) {