-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsi.js
196 lines (173 loc) · 4.09 KB
/
gsi.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const http = require("http")
const config = require("./loadconfig")
const host = "localhost"
let oldPhase = false
let infernosOnMap = [] //initial molotov status
let server = http.createServer((req, res) => {
if (req.method != "POST") {
res.writeHead(405)
return res.end("Only POST requests are allowed")
}
let body = ""
req.on("data", data => {
body += data
})
req.on("end", () => {
res.end("")
let game = JSON.parse(body)
if (game.provider) {
let connObject = {
status: "up"
}
if (game.player) {
if (game.player.activity != "playing") {
connObject.player = game.player.name
}
}
process.send({
type: "connection",
data: connObject
})
}
if (game.map) {
process.send({
type: "map",
data: game.map.name
})
}
if (game.allplayers) {
let playerArr = []
for (let id in game.allplayers) {
if (!Number.isInteger(game.allplayers[id].observer_slot)) continue
let player = game.allplayers[id]
let pos = player.position.split(", ")
let angle = 0
let hasBomb = false
let bombActive = false
let isActive = false
let rawAngle = player.forward.split(", ")
if (parseFloat(rawAngle[0]) > 0) {
angle = 90 + parseFloat(rawAngle[1]) * -1 * 90
}
else {
angle = 270 + parseFloat(rawAngle[1]) * 90
}
if (game.player) {
if (game.player.observer_slot == player.observer_slot) {
isActive = true
}
}
for (let t in player.weapons) {
if (player.weapons[t].name == "weapon_c4") {
hasBomb = true
bombActive = player.weapons[t].state == "active"
}
}
playerArr.push({
id: id,
num: player.observer_slot,
team: player.team,
alive: player.state.health > 0,
active: isActive,
bomb: hasBomb,
bombActive: bombActive,
angle: angle,
position: {
x: parseFloat(pos[0]),
y: parseFloat(pos[1]),
z: parseFloat(pos[2])
}
})
}
process.send({
type: "players",
data: {
players: playerArr
}
})
}
if (game.grenades) {
let smokes = []
let nades = []
let infernos = []
for (let nadeID in game.grenades) {
let nade = game.grenades[nadeID]
if (nade.type == "smoke" && nade.velocity == "0.00, 0.00, 0.00") {
let pos = nade.position.split(", ")
smokes.push({
id: nadeID,
time: nade.effecttime,
position: {
x: parseFloat(pos[0]),
y: parseFloat(pos[1]),
z: parseFloat(pos[2])
}
})
}
if (nade.type == "inferno") {
if (!!nade.flames) {
let flamesPos = []
let flamesNum = Object.values(nade.flames).length
for (var i = 0; i < flamesNum; i++) {
flamesPos.push({
x: parseFloat(Object.values(nade.flames)[i].split(", ")[0]),
y: parseFloat(Object.values(nade.flames)[i].split(", ")[1]),
z: parseFloat(Object.values(nade.flames)[i].split(", ")[2]),
})
}
infernos.push({
id: nadeID,
flamesNum: flamesNum,
flamesPosition: flamesPos
})
if (infernosOnMap.indexOf(nadeID) == -1 ) {infernosOnMap.push(nadeID)}
}
else{
}
}
}
for (let infernoOnMap of infernosOnMap) {
if (!game.grenades[infernoOnMap]) {
process.send({
type: "infernoRemove",
data: infernoOnMap
})
}// check if molotov exist in game
}
process.send({
type: "smokes",
data: smokes
})
process.send({
type: "infernos",
data: infernos
})
}
if (game.round) {
process.send({
type: "round",
data: game.round.phase
})
if (oldPhase == "over" && game.round.phase == "freezetime") {
infernosOnMap = [] //clear molotov status every round
}
}
if (game.bomb) {
let pos = game.bomb.position.split(", ")
process.send({
type: "bomb",
data: {
state: game.bomb.state,
player: game.bomb.player,
position: {
x: parseFloat(pos[0]),
y: parseFloat(pos[1]),
z: parseFloat(pos[2])
}
}
})
}
})
})
server.listen(config.game.networkPort, host)
console.info(`GSI input expected at http://${host}:${config.game.networkPort}`)