mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-13 19:41:24 +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;
|
||||
}
|
||||
|
||||
function MCServer() {
|
||||
EventEmitter.call(this);
|
||||
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);
|
||||
class MCServer extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
this._server = null;
|
||||
}
|
||||
|
||||
if(options.logging == true) {
|
||||
self.createLog();
|
||||
connect(options) {
|
||||
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