-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (49 loc) · 1.71 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
// #region Libraries
var fs = require('fs');
var net = require('net');
require(__dirname + '/resources/config.js');
require('./packet.js');
// #region Initialisers
var init_files = fs.readdirSync(__dirname + "/initialisers");
init_files.forEach(function(initFile) {
// console.log("Packing initialiser file, " + initFile + ".");
require(__dirname + "/initialisers/" + initFile);
});
// #endregion
// #region Maps
maps = {};
var map_files = fs.readdirSync(config.data_paths.maps);
map_files.forEach(function(mapFile) {
// console.log("Packing map file, " + mapFile + ".");
var map = require(config.data_paths.maps + mapFile);
maps[map.room] = map;
});
// #endregion
// #region NPCs
npcs = {};
var npc_files = fs.readdirSync(config.data_paths.npcs);
npc_files.forEach(function(npcFile) {
// console.log("Packing map file, " + npcFile + ".");
var npc = require(config.data_paths.npcs + npcFile);
npcs[npc.id] = npc;
});
// #endregion
// #region Models
var model_files = fs.readdirSync(__dirname + "/models");
model_files.forEach(function(modelFile) {
// console.log("Packing model file, " + modelFile + ".");
require(__dirname + "/models/" + modelFile);
});
// #endregion
// #endregion
net.createServer(function(socket) {
var clientInstance = new require('./client.js');
var thisClient = new clientInstance();
thisClient.socket = socket;
thisClient.initiate();
socket.on('error', thisClient.error);
socket.on('end', thisClient.end);
socket.on('data', thisClient.data);
}).listen(config.port);
// Log that the server is running on a specified port.
console.log("The server is running on port " + config.port + " in the " + config.environment + " environment.");