-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathserver.js
118 lines (94 loc) · 3.09 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
http = require('http');
fs = require('fs');
var version = "1.0.4";
var csgoport = 3000;
var webport = 2626;
var app = require('express')();
var express = require('http').Server(app);
var io = require('socket.io')(express);
console.log()
console.log("\tStarting CSGO Data Integration HUD "+version+" by Double0negative");
console.log("\thttps://github.com/Double0negative/CSGO-HUD");
app.set('view engine', 'jade');
app.get('/', function(req, res) {
res.render('index');
});
app.get('/main.js', function(req, res) {
res.sendFile(__dirname +'/public/js/main.js');
});
app.get('/style.css', function(req, res) {
res.sendFile(__dirname +'/public/css/style.css');
});
io.on('connection', function(socket) {
});
express.listen(webport, function() {
console.log('\n\tOpen http://localhost:'+webport+' in a browser to connect to HUD');
console.log('\n');
});
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() {
//console.log("POST payload: " + body);
update(JSON.parse(body));
res.end('');
});
} else {
res.writeHead(200, {
'Content-Type': 'text/html'
});
var html = 'yes';
res.end(html);
}
});
var map;
var player;
var round = {
phase: "",
timestart: 0,
time: 0,
maxTime: 0,
bomb: {
planted: false,
timestart: 0,
time: 0,
maxTime: 40
}
};
function update(json) {
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 {
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;
}
io.emit("update", JSON.stringify(json));
}
server.listen(csgoport);