This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
maplejs.js
63 lines (52 loc) · 1.92 KB
/
maplejs.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
global.ServerConfig = require('./config.json');
var startLoginServers = true;
var startChannelServers = true;
for (var i = 2; i < process.argv.length; i++) {
switch (process.argv[i]) {
case 'no_logins': startLoginServers = false; break;
case 'no_channels': startChannelServers = false; break;
}
}
// Start servers
var child_process = require('child_process');
function spawnInstance(pLoggerName, pProcessName, arguments) {
console.log('Spawning ' + pProcessName + ' ' + arguments.join(' '));
var instance = child_process.spawn(pProcessName, arguments);
instance.stdout.setEncoding('utf8');
instance.stdout.on('data', function (pData) {
var lines = pData.split("\n");
lines.forEach(function (pLine) {
if (pLine == '') return;
console.log('[' + pLoggerName +'] ' + pLine);
});
});
instance.stderr.setEncoding('utf8');
instance.stderr.on('data', function (pData) {
var lines = pData.split("\n");
lines.forEach(function (pLine) {
if (pLine == '') return;
console.log('[' + pLoggerName +'][ERROR] ' + pLine);
});
});
instance.on('close', function (code) {
console.log('[' + pLoggerName +'][EXIT] code ' + code);
});
}
var instances = {};
if (startLoginServers) {
for (var index in ServerConfig.loginservers) {
var instanceName = 'loginserver-' + index;
var loginserver = ServerConfig.loginservers[index];
instances[instanceName] = spawnInstance('Login-' + (parseInt(index) + 1), 'node', ['login_server', instanceName, loginserver.port]);
}
}
if (startChannelServers) {
for (var worldName in ServerConfig.worlds) {
var world = ServerConfig.worlds[worldName];
var instanceName = 'world-' + worldName + '-';
for (var i = 0; i < world.channels; i++) {
instances[instanceName + i] = spawnInstance(worldName + '-' + (i + 1), 'node', ['channel_server', instanceName + i, world.portStart + i, world.id, i]);
}
}
}
console.log('Ready...');