-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (58 loc) · 2.03 KB
/
app.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
const express = require('express');
const readline = require('readline');
const config = require('config');
const Gateway = require('./config/Gateway');
const { TribalWarsInfoType, GatewayOPCodes } = require('./config/Enums');
const Command = require('./commands/Command');
const WorldSettings = require('./commands/World_Settings');
const WorldBuildings = require('./commands/World_Buildings');
const WorldUnits = require('./commands/World_Units');
const Player = require('./commands/Player');
const Ally = require('./commands/Ally');
const TribalWars = require('./TribalWars/TribalWars');
const Villages = require('./TribalWars/Villages');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on('line', (input) => {
Command.checkCommand(input);
});
const PORT = process.env.PORT || 3000;
const INDEX = '/index.html';
const server = express()
.use((req, res) => res.sendFile(INDEX, { root: __dirname }))
.listen(PORT, () => {
console.log(`Server running on port ${PORT}\n[DEBUG MODE]: ${config.get('debugMode')}`);
Gateway.initialize();
loadData();
timerRefreshData();
});
function loadData() {
TribalWars.getInfo(TribalWarsInfoType.WORLD, 'xml').then((result) => {
WorldSettings.loadInfo(result.config);
TribalWars.getInfo(TribalWarsInfoType.BUILDINGS, 'xml').then((result) => {
WorldBuildings.loadInfo(result.config);
TribalWars.getInfo(TribalWarsInfoType.UNITS, 'xml').then((result) => {
WorldUnits.loadInfo(result.config);
TribalWars.getInfo(TribalWarsInfoType.PLAYER).then((result) => {
Player.fillList(result);
TribalWars.getInfo(TribalWarsInfoType.ALLY).then((result) => {
Ally.fillList(result);
TribalWars.getInfo(TribalWarsInfoType.VILLAGE).then((result) => {
Villages.getVillages(result);
TribalWars.getInfo(TribalWarsInfoType.CONQUER).then((result) => {
TribalWars.getConquers(result);
});
});
});
});
});
});
});
}
function timerRefreshData() {
setInterval(() => {
loadData();
}, 600000);
}