-
Notifications
You must be signed in to change notification settings - Fork 4
/
server.js
226 lines (193 loc) · 5.61 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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
var gui = require('nw.gui'),
http = require('http'),
debug = false;
// Get the current window
var win = gui.Window.get();
win.width=screen.width;
win.height=screen.height;
win.setAlwaysOnTop(true);
console.info('\n\n\n%chttps://github.com/RedSparr0w/csgo-hud%c\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', `
font-family: "Avant Garde", Avantgarde, "Century Gothic", CenturyGothic, "AppleGothic", sans-serif;
font-size: 20px;
padding: 20px 20px 210px 20px;
text-decoration: none;
text-align: center;
text-transform: uppercase;
text-rendering: optimizeLegibility;
color: #131313;
letter-spacing: .15em;
background-image: url(http://csgo.redsparr0w.com/ak47.svg);
background-size: contain;
background-position: center;
background-repeat: no-repeat;
`,null);
server = http.createServer(function(req, res) {
if (req.method == 'POST') {
res.writeHead(200, {
'Content-Type': 'text/html'
});
var body='';
req.on('data', function(data) {
body += data;
});
req.on('end', function() {
if (!!debug) {
console.debug("POST payload: " + body);
}
update(JSON.parse(body));
res.end('');
});
} else {
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.end("Nothing to see here!");
}
});
var map,
player;
var round = {
phase: "",
timestart: 0,
time: 0,
maxTime: 0,
bomb: {
planted: false,
timestart: 0,
time: 0,
maxTime: 40
}
};
function update(json) {
if (json.player.activity!="playing" || json.round.phase=="warmup"){
$("#player-container").css("bottom","-100px");
$("#ammo-container").css("bottom","-100px");
} else {
$("#player-container").css("bottom","0px");
$("#ammo-container").css("bottom","0px");
}
if (json.round) {
if (!(round.phase === json.round.phase)) {
round.timestart = json.provider.timestamp;
round.phase = json.round.phase;
}
var maxTime = 0;
if (json.round.phase === 'live') {
maxTime = 115;
} else if (round.phase === 'freezetime') {
maxTime = 15;
} else if (round.phase === 'warmup') {
maxTime = 300;
} else {
maxTime = 7;
}
round.time = maxTime - (new Date().getTime() / 1000 - round.timestart);
round.maxTime = maxTime;
if (!round.bomb.planted && json.round.bomb === 'planted') {
round.bomb.planted = true;
round.bomb.timestart = json.provider.timestamp;
} else if (round.bomb.planted && json.round.bomb !== 'planted') {
round.bomb.planted = false;
}
if (round.bomb.planted) {
round.bomb.time = 40 - (new Date().getTime() / 1000 - round.bomb.timestart);
}
json.extra = {};
json.extra.round = round;
}
updatePage(JSON.stringify(json));
}
function updatePage(data) {
json = JSON.parse(data);
if (typeof json.extra == "undefined") return;
roundtime = json.extra.round.timestart;
bombtime = json.extra.round.bomb.timestart;
/* HEALTH */
var health = json.player.state.health;
var healthColor;
if (health <= 15) {healthColor="#e74c3c";}else if (health <= 50) {healthColor="#f39c12";} else{healthColor="#2ecc71";}
$("#health-text").html(health);
$("#health").css("color",healthColor);
$("#health .level").css("left","-"+(100-health)+"%").css("background-color",healthColor);
/* ARMOR */
var armor = json.player.state.armor;
var armorColor;
!json.player.state.helmet ? $("#armor .fa-stack").html('<i class="fa fa-shield fa-stack-2x"></i>') : $("#armor .fa-stack").html('<i class="fa fa-shield fa-stack-2x"></i><i class="fa fa-plus fa-stack-1x"></i>') ;
if (armor == 0) {armorColor="rgba(0,0,0,0.65)";}else if (armor <= 15) {armorColor="#e74c3c";} else{armorColor="#3498db";}
$("#armor-text").html(armor);
$("#armor").css("color",armorColor);
$("#armor .level").css("left","-"+(100-armor)+"%").css("background-color",armorColor);
/* AMMO */
for (var key in json.player.weapons) {
var weapon = json.player.weapons[key];
if (weapon.state=="active" || weapon.state=="reloading") {
if (weapon.type=="Grenade" || weapon.type=="C4" || weapon.type=="Knife" || health == 0) {
$(".clip").html("");
$(".reserve").html("");
return;
}
$(".clip").html(weapon.ammo_clip+"/");
$(".reserve").html(weapon.ammo_reserve);
return;
}
}
if(!tickinterval) {
tickinterval = setInterval(tick, 300);
}
}
server.listen(1337);
var json;
var tickinterval;
var roundtime = 0;
var bombtime = 0;
var flashing = false;
function tick() {
var btime = json.extra.round.bomb.maxTime - parseInt(new Date().getTime() / 1000 - bombtime);
var rtime = json.extra.round.maxTime - parseInt(new Date().getTime() / 1000 - roundtime);
if (json.extra.round.bomb.planted) {
$(".time").html(btime);
$(".timelabel").html("Bomb Planted");
if (btime < 0) {
flashing = false;
} else if (btime <= 5) {
flash();
} else if (btime <= 10) {
$("#timer").css('color', "#e74c3c");
} else {
$("#timer").css('color', '#f39c12');
}
} else {
$(".timelabel").html("");
$(".time").html("");
/*
win.setAlwaysOnTop(true);
var min = 0;
var sec = 0;
if (rtime > 59) {
min = 1;
sec = rtime - 59;
} else {
sec = rtime;
}
sec < 10 ? pre_sec = "0" : pre_sec = "";
$(".time").css("font-size", "7em");
if (json.round.phase === 'warmup') {
$(".timelabel").html("Warmup");
} else if (json.round.phase === 'freezetime') {
$(".timelabel").html("Freeze Time");
} else if (json.round.phase === 'live') {
$(".timelabel").html("Round Time");
} else if (json.round.phase === 'over') {
$(".timelabel").html("Round Over");
}
$(".time").html(min > 0 ? min + ":" + pre_sec + sec : sec);
$("#timer").css('color', 'lightblue');
*/
}
}
function flash() {
$("#timer").css('color', function() {
this.switch = !this.switch;
return this.switch ? "#e74c3c" : "#f39c12";
});
}