mirror of
https://github.com/danbulant/flying-squid
synced 2026-07-05 03:00:46 +00:00
use a class for MCServer
This commit is contained in:
parent
888fa21b7b
commit
733ca45a46
1 changed files with 11 additions and 23 deletions
34
src/index.js
34
src/index.js
|
|
@ -19,29 +19,17 @@ function createMCServer(options) {
|
||||||
return mcServer;
|
return mcServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function MCServer() {
|
class MCServer extends EventEmitter {
|
||||||
EventEmitter.call(this);
|
constructor() {
|
||||||
this._server = null;
|
super();
|
||||||
}
|
this._server = null;
|
||||||
util.inherits(MCServer, EventEmitter);
|
|
||||||
|
|
||||||
MCServer.prototype.connect = function(options) {
|
|
||||||
var self = this;
|
|
||||||
self._server = mc.createServer(options);
|
|
||||||
|
|
||||||
for(var pluginName in serverPlugins) {
|
|
||||||
serverPlugins[pluginName](self, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(options.logging == true) {
|
connect(options) {
|
||||||
self.createLog();
|
this._server = mc.createServer(options);
|
||||||
|
Object.keys(serverPlugins).forEach(pluginName => serverPlugins[pluginName](this, options));
|
||||||
|
if(options.logging == true) this.createLog();
|
||||||
|
this._server.on('error', error => this.emit('error',error));
|
||||||
|
this._server.on('listening', () => this.emit('listening',this._server.socketServer.address().port));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
self._server.on('error', function(error) {
|
|
||||||
self.emit('error',error);
|
|
||||||
});
|
|
||||||
|
|
||||||
self._server.on('listening', function() {
|
|
||||||
self.emit('listening',self._server.socketServer.address().port);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
Loading…
Reference in a new issue