mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-11-29 18:55:40 -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')
|
||||
, EventEmitter = require('events').EventEmitter
|
||||
, util = require('util')
|
||||
, Client = require('./client')
|
||||
, states = require('./transforms/serializer').states
|
||||
;
|
||||
var net = require('net');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var Client = require('./client');
|
||||
var states = require('./transforms/serializer').states;
|
||||
|
||||
module.exports = Server;
|
||||
|
||||
function Server() {
|
||||
EventEmitter.call(this);
|
||||
class Server extends EventEmitter
|
||||
{
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.socketServer = null;
|
||||
this.cipher = null;
|
||||
this.decipher = null;
|
||||
this.clients = {};
|
||||
}
|
||||
util.inherits(Server, EventEmitter);
|
||||
}
|
||||
|
||||
Server.prototype.listen = function(port, host) {
|
||||
listen(port, host) {
|
||||
var self = this;
|
||||
var nextId = 0;
|
||||
self.socketServer = net.createServer();
|
||||
|
@ -51,9 +48,9 @@ Server.prototype.listen = function(port, host) {
|
|||
self.emit('listening');
|
||||
});
|
||||
self.socketServer.listen(port, host);
|
||||
};
|
||||
}
|
||||
|
||||
Server.prototype.close = function() {
|
||||
close() {
|
||||
var client;
|
||||
for(var clientId in this.clients) {
|
||||
if(!this.clients.hasOwnProperty(clientId)) continue;
|
||||
|
@ -62,4 +59,7 @@ Server.prototype.close = function() {
|
|||
client.end('ServerShutdown');
|
||||
}
|
||||
this.socketServer.close();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Server;
|
||||
|
|
Loading…
Reference in a new issue