mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-08 12:20:26 -04:00
fix incorrect playerCount in ping. closes #41
This commit is contained in:
parent
8daacd3b08
commit
adc47b0f62
3 changed files with 9 additions and 7 deletions
|
@ -6,6 +6,7 @@ var options = {
|
|||
motd: 'Vox Industries',
|
||||
'max-players': 127,
|
||||
port: 25565,
|
||||
'online-mode': false,
|
||||
};
|
||||
|
||||
var server = mc.createServer(options);
|
||||
|
|
5
index.js
5
index.js
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue