Allow beforePing to receive a callback to call with its result when

it accepts three arguements. Allows async processing while
calculating response.
This commit is contained in:
Rob Blanckaert 2015-09-29 21:11:02 -04:00
parent df2caf74cb
commit 16452d4a4c

View File

@ -100,15 +100,25 @@ function createServer(options) {
"favicon": server.favicon
};
function answerToPing(err, response) {
if ( err ) return;
client.write('server_info', {response: JSON.stringify(response)});
}
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.write('ping', {time: packet.time});
client.end();
});
client.write('server_info', {response: JSON.stringify(response)});
}
function onLogin(packet) {