-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.js
69 lines (58 loc) · 1.66 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
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
// Imports
var Commands = require('./modules/CommandList');
var GameServer = require('./GameServer');
// Init variables
var showConsole = true;
// Start msg
console.log("[Game] Ogar3 - An open source Agar.io server implementation based on ogar!");
// Handle arguments
process.argv.forEach(function(val) {
if (val == "--noconsole") {
showConsole = false;
} else if (val == "--help") {
console.log("Proper Usage: node index.js");
console.log(" --noconsole Disables the console");
console.log(" --help Help menu.");
console.log("");
}
});
// Run Ogar
var gameServer = new GameServer();
exports.gameServer = gameServer;
gameServer.start();
// Add command handler
gameServer.commands = Commands.list;
// Initialize the server console
if (showConsole) {
var readline = require('readline');
var in_ = readline.createInterface({
input: process.stdin,
output: process.stdout
});
setTimeout(prompt, 100);
}
// Console functions
function prompt() {
in_.question(">", function(str) {
parseCommands(str);
return prompt(); // Too lazy to learn async
});
}
function parseCommands(str) {
// Log the string
gameServer.log.onCommand(str);
// Don't process ENTER
if (str === '')
return;
// Splits the string
var split = str.split(" ");
// Process the first string value
var first = split[0].toLowerCase();
// Get command function
var execute = gameServer.commands[first];
if (typeof execute != 'undefined') {
execute(gameServer, split);
} else {
console.log("[Console] Invalid Command!");
}
}