mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-02 03:56:54 -05:00
transform server.js into an es6 class
This commit is contained in:
parent
78ff667c1f
commit
6e399122bf
1 changed files with 63 additions and 63 deletions
|
@ -1,23 +1,20 @@
|
||||||
var net = require('net')
|
var net = require('net');
|
||||||
, EventEmitter = require('events').EventEmitter
|
var EventEmitter = require('events').EventEmitter;
|
||||||
, util = require('util')
|
var Client = require('./client');
|
||||||
, Client = require('./client')
|
var states = require('./transforms/serializer').states;
|
||||||
, states = require('./transforms/serializer').states
|
|
||||||
;
|
|
||||||
|
|
||||||
module.exports = Server;
|
class Server extends EventEmitter
|
||||||
|
{
|
||||||
function Server() {
|
constructor() {
|
||||||
EventEmitter.call(this);
|
super();
|
||||||
|
|
||||||
this.socketServer = null;
|
this.socketServer = null;
|
||||||
this.cipher = null;
|
this.cipher = null;
|
||||||
this.decipher = null;
|
this.decipher = null;
|
||||||
this.clients = {};
|
this.clients = {};
|
||||||
}
|
}
|
||||||
util.inherits(Server, EventEmitter);
|
|
||||||
|
|
||||||
Server.prototype.listen = function(port, host) {
|
listen(port, host) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var nextId = 0;
|
var nextId = 0;
|
||||||
self.socketServer = net.createServer();
|
self.socketServer = net.createServer();
|
||||||
|
@ -51,9 +48,9 @@ Server.prototype.listen = function(port, host) {
|
||||||
self.emit('listening');
|
self.emit('listening');
|
||||||
});
|
});
|
||||||
self.socketServer.listen(port, host);
|
self.socketServer.listen(port, host);
|
||||||
};
|
}
|
||||||
|
|
||||||
Server.prototype.close = function() {
|
close() {
|
||||||
var client;
|
var client;
|
||||||
for(var clientId in this.clients) {
|
for(var clientId in this.clients) {
|
||||||
if(!this.clients.hasOwnProperty(clientId)) continue;
|
if(!this.clients.hasOwnProperty(clientId)) continue;
|
||||||
|
@ -62,4 +59,7 @@ Server.prototype.close = function() {
|
||||||
client.end('ServerShutdown');
|
client.end('ServerShutdown');
|
||||||
}
|
}
|
||||||
this.socketServer.close();
|
this.socketServer.close();
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Server;
|
||||||
|
|
Loading…
Reference in a new issue