fix incorrect playerCount in ping. closes

This commit is contained in:
Andrew Kelley 2013-02-10 17:51:47 -05:00
parent 8daacd3b08
commit adc47b0f62
3 changed files with 9 additions and 7 deletions

View file

@ -6,6 +6,7 @@ var options = {
motd: 'Vox Industries',
'max-players': 127,
port: 25565,
'online-mode': false,
};
var server = mc.createServer(options);

View file

@ -36,6 +36,7 @@ function createServer(options) {
var serverKey = ursa.generatePrivateKey(1024);
var server = new Server(options);
server.playerCount = 0;
server.onlineModeExceptions = {};
server.maxPlayers = maxPlayers;
server.on("connection", function(client) {
@ -191,6 +192,10 @@ function createServer(options) {
clearTimeout(loginKickTimer);
loginKickTimer = null;
server.playerCount += 1;
client.once('end', function() {
server.playerCount -= 1;
});
server.emit('login', client);
}
});

View file

@ -9,8 +9,6 @@ module.exports = Server;
function Server() {
EventEmitter.call(this);
this.playerCount = 0
this.socketServer = null;
this.cipher = null;
this.decipher = null;
@ -26,9 +24,9 @@ Server.prototype.listen = function(port, host) {
var client = new Client(true);
client._end = client.end;
client.end = function end(endReason) {
client.write(0xff, {reason: endReason});
client._end(endReason);
}
client.write(0xff, {reason: endReason});
client._end(endReason);
};
client.id = nextId++;
self.clients[client.id] = client;
client.on('error', function(err) {
@ -36,9 +34,7 @@ Server.prototype.listen = function(port, host) {
});
client.on('end', function() {
delete self.clients[client.id];
this.playerCount -= 1;
});
this.playerCount += 1;
client.setSocket(socket);
self.emit('connection', client);
});