This repository has been archived by the owner on Sep 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
server.js
executable file
·90 lines (81 loc) · 3.55 KB
/
server.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var fs = require('fs');
var configFileName = "config.json";
var versionFileName = "./client/data.js";
function loadFile(filename) {
var file = null;
if (fs.existsSync(filename)) {
file = fs.readFileSync(filename, 'utf8');
console.log("Loaded '" + filename + "'");
return file;
}
else if (filename == "config.json") {
file = fs.readFileSync("config-sample.json", 'utf8');
console.log("Loaded default config-sample.json file");
configFileName = "config-sample.json";
return file;
}
console.log("File " + filename + "does not exists");
return file;
}
function main() {
var config = JSON.parse(loadFile(configFileName));
var version = loadFile(versionFileName).match(/"([0-9]+)"/)[1];
console.log("Running version " + version);
var chatServerBase = require("./server.ChatServerBase.js")();
var AutoMod = require("./server.AutoMod.js");
var AutoMod = new AutoMod(config.AutoMod);
chatServerBase.initialize(config.base, version, AutoMod);
if (config.webSocketServer && config.webSocketServer.enabled) {
var webSocketServer = require("./server.WebSocketServer.js")();
webSocketServer.initialize(config.webSocketServer);
webSocketServer.run(chatServerBase);
}
if (config.ircServer && config.ircServer.enabled) {
var ircServer = require("./server.IrcServer.js")();
ircServer.initialize(config.ircServer);
ircServer.run(chatServerBase);
}
if (config.restApiServer && config.restApiServer.enabled) {
var restApiServer = require("./server.RestApiServer.js")();
restApiServer.initialize(config.restApiServer);
restApiServer.run(chatServerBase);
}
if (config.webSocketServer && config.webSocketServer.enabled && config.client && config.client.enabled) {
var client = require("./server.client.js")();
config.client.socketPort = config.webSocketServer.port;
client.initialize(config.client);
client.run();
}
else if (config.bouncer && config.bouncer.enabled && config.bouncer.hasOwnProperty("wss")) {
var bouncer = require("./server.Bouncer.js")();
bouncer.initialize(config.bouncer, AutoMod);
bouncer.run();
if (config.bouncer.client) {
var client = require("./server.client")();
config.client.socketPort = config.bouncer.socketPort;
config.client.port = config.bouncer.port;
config.client.domain = config.bouncer.domain;
client.initialize(config.client);
client.run();
}
}
fs.watchFile(configFileName, {
persistent: false
}, function () {
config = JSON.parse(loadFile(configFileName));
chatServerBase.initialize(config.base, version, AutoMod);
if (config.webSocketServer.enabled) webSocketServer.initialize(config.webSocketServer);
if (config.ircServer.enabled) ircServer.initialize(config.ircServer);
});
fs.watchFile(versionFileName, {
persistent: false
}, function () {
version = loadFile(versionFileName).match(/"([0-9]+)"/)[1];
console.log("Running version " + version);
chatServerBase.initialize(config.base, version, AutoMod);
if (config.webSocketServer && config.webSocketServer.enabled) webSocketServer.initialize(config.webSocketServer);
if (config.ircServer && config.ircServer.enabled) ircServer.initialize(config.ircServer);
if (config.restApiServer && config.restApiServer.enabled) ircServer.initialize(config.ircServer);
});
}
main();