Skip to content

Commit a0bf388

Browse files
committed
Merge branch 'bottomad' of https://github.com/codergautam/worldguessr
2 parents 549e085 + 7ac6a81 commit a0bf388

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

styles/globals.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ screen and (pointer:coarse) {
11941194
animation: fadeInLb 1s ease-in-out forwards;
11951195

11961196
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
1197-
z-index: 110;
1197+
z-index: 1100;
11981198
}
11991199

12001200

ws/ws.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ if (!process.env.MONGODB) {
121121
function log(...args) {
122122
console.log(new Date().toLocaleString("en-US", { timeZone: "America/Chicago" }), ...args);
123123

124-
if(!dev) {
124+
// if(!dev) {
125125
if(process.env.DISCORD_WEBHOOK_WS) {
126126
const hook = new Webhook(process.env.DISCORD_WEBHOOK_WS);
127-
hook.setUsername("Logs");
127+
hook.setUsername("Logs"+(dev ? ' - Dev' : ''));
128128
hook.send(args.join(' '));
129129
}
130-
}
130+
// }
131131
}
132132

133133

@@ -308,6 +308,11 @@ if (process.env.MAINTENANCE_SECRET) {
308308

309309
const bannedIps = new Set();
310310
const ipConnectionCount = new Map();
311+
const ipDuelRequestsLast10 = new Map();
312+
313+
setInterval(() => {
314+
ipDuelRequestsLast10.clear();
315+
}, 10000);
311316

312317
app.ws('/wg', {
313318
/* Options */
@@ -396,6 +401,31 @@ app.ws('/wg', {
396401
console.log('public duel requested by', player.username, player.ip);
397402
player.inQueue = true;
398403
playersInQueue.add(player.id);
404+
if(!player.ip === 'unknown' && player.ip.includes('.')) {
405+
406+
const ipOctets = player.ip.split('.').slice(0, 3).join('.');
407+
log('Duel requests from ip', ipOctets, ipDuelRequestsLast10.get(ipOctets));
408+
409+
if (!ipDuelRequestsLast10.has(ipOctets)) {
410+
ipDuelRequestsLast10.set(ipOctets, 1);
411+
} else {
412+
ipDuelRequestsLast10.set(ipOctets, ipDuelRequestsLast10.get(ipOctets) + 1);
413+
}
414+
415+
if (ipDuelRequestsLast10.get(ipOctets) > 100) {
416+
log('Banned IP due to spam', ipOctets);
417+
bannedIps.add(ipOctets);
418+
ws.close();
419+
420+
for(const player of players.values()) {
421+
if(player.ip.includes(ipOctets)) {
422+
player.ws.close();
423+
}
424+
}
425+
}
426+
} else {
427+
log('Unknown ip req duel', player.ip, player.id, player.username);
428+
}
399429
}
400430

401431
if (json.type === 'leaveQueue' && player.inQueue) {

0 commit comments

Comments
 (0)