-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
206 lines (177 loc) · 5.88 KB
/
server.js
File metadata and controls
206 lines (177 loc) · 5.88 KB
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
const Discord = require('discord.js');
const dclient = new Discord.Client();
var tochannel = dclient.channels.find('name','csgospam');
var bombMessage = 0;
var bombTimerExists = 0;
var scoreCounted = 0;
let nmsg;
const token = '<BOT TOKEN HERE>';
dclient.on('ready', () => {
var tochannel = dclient.channels.find('name','csgospam');
tochannel.send('Online!');
});
http = require('http');
fs = require('fs');
var version = "1.0.6";
var csgoport = 3000;
var webport = 30120; //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");
console.log()
console.log("\tStarting Discord Integration by MickyDNet");
console.log("\thttps://github.com/MickyDNet/CSGO-HUD-Discord");
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;
//console.log("round.phase: " + round.phase);
}
var maxTime = 0;
if (json.round.phase === 'live') {
scoreCounted = 0;
maxTime = 115;
} else if (round.phase === 'freezetime') {
maxTime = 15;
let messagecount = parseInt('4');
if (scoreCounted === 0) {
var tochannel = dclient.channels.find('name','csgospam');
tochannel.fetchMessages({ limit: 100 }).then(messages => tochannel.bulkDelete(messages.filter(m => m.author.id === dclient.user.id)));
const embed = {
"title": "Round over",
"color": 16381126,
"footer": {
"icon_url": "http://topscheats.ru/templates/Green/images/logo.png",
"text": "CS:GO Discord - By MickyDNet"
},
"thumbnail": {
"url": "https://worldgaming.com/events/images/csgo/csgo-logo.png"
},
"author": {
"name": "CS:GO Discord",
"url": "https://github.com/MickyDNet/CSGO-HUD-Discord",
"icon_url": "http://topscheats.ru/templates/Green/images/logo.png"
},
"fields": [
{
"name": "CT",
"value": json.map.team_ct.score,
"inline": true
},
{
"name": "T",
"value": json.map.team_t.score,
"inline": true
}
]
};
tochannel.send({ embed });
tochannel.send("Round over - CT: " + json.map.team_ct.score + " - T:" + json.map.team_t.score, {tts: true})
//tochannel.fetchMessages({ limit: 1 }).then(messages => tochannel.bulkDelete(messages.filter(m => m.author.id === dclient.user.id)));
scoreCounted = 1;
}
} 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;
bombMessage = 0;
bombTimerExists = 0;
}
if (round.bomb.planted) {
round.bomb.time = 40 - (new Date().getTime() / 1000 - round.bomb.timestart);
if (bombMessage !== 1) {
var tochannel = dclient.channels.find('name','csgospam');
tochannel.send('The bomb has been planted!', {tts: true});
bombMessage = 1;
bombTimer = 39;
function fctBombTimer() {
setTimeout(function () {
if (bombMessage !== 0) {
var tochannel = dclient.channels.find('name','csgospam');
if (bombTimerExists == 0) {
//tochannel.send(bombTimer).then(nmsg => nmsg.edit(bombTimer));
tochannel.send("Bomb Timer: ~" + bombTimer).then(msg => {
nmsg = msg
msg.edit("Bomb Timer: ~" + bombTimer
)})
bombTimerExists = 1;
} else {
nmsg.edit("Bomb Timer: ~" + bombTimer);
}
bombTimer = bombTimer - 1;
fctBombTimer();
}
}, 1000);
}
fctBombTimer();
}
}
json.extra = {};
json.extra.round = round;
}
io.emit("update", JSON.stringify(json));
}
server.listen(csgoport);
dclient.login(token);