diff --git a/.gitignore b/.gitignore index c2658d7..5a451dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +*.log \ No newline at end of file diff --git a/app.js b/app.js index 98cd0e6..71af4e6 100644 --- a/app.js +++ b/app.js @@ -70,6 +70,8 @@ server.start(function() { // Attach our listeners. client.on('disconnect', function(client) { connectedClients -= 1; + + logger.log('info', 'Client disconnected, total clients: %d', connectedClients); }); }); }); \ No newline at end of file diff --git a/lib/logger.js b/lib/logger.js index 0c01c20..2c616f1 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -8,8 +8,8 @@ winston.add(winston.transports.File, { winston.add(winston.transports.Console, { 'timestamp': function() { var date = new Date(); - - return date.toLocaleTimeString() + " " + date.getDate() + "/" + (date.getMonth() + 1) + "/" + date.getFullYear().toString().substring(2, 4); + + return date.toLocaleTimeString() + ' ' + date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear().toString().substring(2, 4); }, 'colorize': true }); diff --git a/lib/ping.js b/lib/ping.js index 91494ea..b016132 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -5,6 +5,12 @@ function pingMinecraftPC(host, port, timeout, callback) { var client = new net.Socket(); var milliseconds = (new Date).getTime(); + client.setTimeout(timeout, function() { + client.destroy(); + + callback(new Error('timeout'), null); + }); + client.connect(port, host, function() { // Write out handshake packet. var handshakeBuffer = mcpc.createBuffer(); @@ -69,11 +75,6 @@ function pingMinecraftPC(host, port, timeout, callback) { client.on('error', function(err) { callback(err, null); }); - - // Make sure we don't go overtime. - setTimeout(function() { - client.end(); - }, timeout); } // Wraps our Buffer into another to fit the Minecraft protocol.