mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-18 17:20:25 -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',
|
motd: 'Vox Industries',
|
||||||
'max-players': 127,
|
'max-players': 127,
|
||||||
port: 25565,
|
port: 25565,
|
||||||
|
'online-mode': false,
|
||||||
};
|
};
|
||||||
|
|
||||||
var server = mc.createServer(options);
|
var server = mc.createServer(options);
|
||||||
|
|
5
index.js
5
index.js
|
@ -36,6 +36,7 @@ function createServer(options) {
|
||||||
var serverKey = ursa.generatePrivateKey(1024);
|
var serverKey = ursa.generatePrivateKey(1024);
|
||||||
|
|
||||||
var server = new Server(options);
|
var server = new Server(options);
|
||||||
|
server.playerCount = 0;
|
||||||
server.onlineModeExceptions = {};
|
server.onlineModeExceptions = {};
|
||||||
server.maxPlayers = maxPlayers;
|
server.maxPlayers = maxPlayers;
|
||||||
server.on("connection", function(client) {
|
server.on("connection", function(client) {
|
||||||
|
@ -191,6 +192,10 @@ function createServer(options) {
|
||||||
clearTimeout(loginKickTimer);
|
clearTimeout(loginKickTimer);
|
||||||
loginKickTimer = null;
|
loginKickTimer = null;
|
||||||
|
|
||||||
|
server.playerCount += 1;
|
||||||
|
client.once('end', function() {
|
||||||
|
server.playerCount -= 1;
|
||||||
|
});
|
||||||
server.emit('login', client);
|
server.emit('login', client);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,8 +9,6 @@ module.exports = Server;
|
||||||
function Server() {
|
function Server() {
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
this.playerCount = 0
|
|
||||||
|
|
||||||
this.socketServer = null;
|
this.socketServer = null;
|
||||||
this.cipher = null;
|
this.cipher = null;
|
||||||
this.decipher = null;
|
this.decipher = null;
|
||||||
|
@ -26,9 +24,9 @@ Server.prototype.listen = function(port, host) {
|
||||||
var client = new Client(true);
|
var client = new Client(true);
|
||||||
client._end = client.end;
|
client._end = client.end;
|
||||||
client.end = function end(endReason) {
|
client.end = function end(endReason) {
|
||||||
client.write(0xff, {reason: endReason});
|
client.write(0xff, {reason: endReason});
|
||||||
client._end(endReason);
|
client._end(endReason);
|
||||||
}
|
};
|
||||||
client.id = nextId++;
|
client.id = nextId++;
|
||||||
self.clients[client.id] = client;
|
self.clients[client.id] = client;
|
||||||
client.on('error', function(err) {
|
client.on('error', function(err) {
|
||||||
|
@ -36,9 +34,7 @@ Server.prototype.listen = function(port, host) {
|
||||||
});
|
});
|
||||||
client.on('end', function() {
|
client.on('end', function() {
|
||||||
delete self.clients[client.id];
|
delete self.clients[client.id];
|
||||||
this.playerCount -= 1;
|
|
||||||
});
|
});
|
||||||
this.playerCount += 1;
|
|
||||||
client.setSocket(socket);
|
client.setSocket(socket);
|
||||||
self.emit('connection', client);
|
self.emit('connection', client);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue