forked from boltgolt/boltobserv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (65 loc) · 1.95 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
70
71
72
73
74
75
76
77
78
// ================================================================================
//
// PLEASE READ:
// This project is under a GPL-3 license, you are REQUIRED to publicly publish any
// changes or upgrades you make to the codebase, it strengthens the community.
// Contact the maintainer if you have any questions regarding the license.
//
// ================================================================================
const path = require("path")
const child_process = require("child_process")
const config = require("./loadconfig")()
const window = require("./window")
let hasMap = false
let connTimeout = false
var win = false
let gsi = child_process.fork(`${__dirname}/gsi.js`)
let http = child_process.fork(`${__dirname}/http.js`)
let socket = child_process.fork(`${__dirname}/socket.js`)
function setActivePage(page, win) {
if (window.win !== false) window.win.loadFile(`html/${page}.html`)
http.send(page)
socket.send({
type: "pageUpdate"
})
}
gsi.on("message", (message) => {
socket.send(message)
if (message.type == "connection") {
if (message.data.status == "up" && connTimeout === false && config.game.connectionTimout >= 0) {
console.info("CSGO has pinged server, connection established")
}
}
else if (!hasMap) {
if (message.type == "map") {
setActivePage("map", win)
hasMap = true
console.info(`Map ${message.data} selected`)
}
}
if (config.game.connectionTimout >= 0) {
clearTimeout(connTimeout)
connTimeout = setTimeout(() => {
hasMap = false
setActivePage("waiting", win)
}, config.game.connectionTimout * 1000)
}
})
if (!config.debug.terminalOnly) {
window.gsi = gsi
window.http = http
window.socket = socket
window.build()
}
else {
console.info("Not opening window, terminal only mode is enabled")
}
function cleanup() {
gsi.kill()
http.kill()
socket.kill()
window.app.quit()
}
for (let signal of ["exit", "SIGINT", "SIGUSR1", "SIGUSR2"]) {
process.on(signal, cleanup)
}