-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
38 lines (32 loc) · 1.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const mc = require('minecraft-classic-protocol');
const cpe = require('minecraft-classic-protocol-extension');
const EventEmitter = require('events').EventEmitter;
const path = require('path');
const requireIndex = require('requireindex');
function createMCServer(options) {
options = options || {};
const mcServer = new MCServer();
options.customPackets = cpe.protocol;
mcServer.connect(options);
return mcServer;
}
class MCServer extends EventEmitter {
constructor() {
super();
this._server = null;
}
connect(options) {
const plugins = requireIndex(path.join(__dirname, 'src', 'plugins'));
this._server = mc.createServer(options);
Object.keys(plugins)
.filter(pluginName => plugins[pluginName].server != undefined)
.forEach(pluginName => plugins[pluginName].server(this, options));
this._server.on('error', error => this.emit('error', error));
this._server.on('clientError', error => this.emit('error', error));
this._server.on('listening', () => this.emit('listening', this._server.socketServer.address().port));
this.emit('asap');
}
}
module.exports = {
createMCServer: createMCServer
};