From 79e9313d1671c255ca036d27f9c0f60b7c7eee10 Mon Sep 17 00:00:00 2001 From: Gautam Anand Date: Mon, 28 Oct 2024 07:52:13 -0500 Subject: [PATCH 1/4] Antispam --- ws/ws.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/ws/ws.js b/ws/ws.js index fe9846aa..936848a3 100644 --- a/ws/ws.js +++ b/ws/ws.js @@ -121,13 +121,13 @@ if (!process.env.MONGODB) { function log(...args) { console.log(new Date().toLocaleString("en-US", { timeZone: "America/Chicago" }), ...args); - if(!dev) { + // if(!dev) { if(process.env.DISCORD_WEBHOOK_WS) { const hook = new Webhook(process.env.DISCORD_WEBHOOK_WS); hook.setUsername("Logs"); hook.send(args.join(' ')); } - } + // } } @@ -308,6 +308,11 @@ if (process.env.MAINTENANCE_SECRET) { const bannedIps = new Set(); const ipConnectionCount = new Map(); +const ipDuelRequestsLast10 = new Map(); + +setInterval(() => { + ipDuelRequestsLast10.clear(); +}, 10000); app.ws('/wg', { /* Options */ @@ -396,6 +401,29 @@ app.ws('/wg', { console.log('public duel requested by', player.username, player.ip); player.inQueue = true; playersInQueue.add(player.id); + if(!player.ip === 'unknown' && player.ip.includes('.')) { + + const ipOctets = player.ip.split('.').slice(0, 3).join('.'); + log('Duel requests from ip', ipOctets, ipDuelRequestsLast10.get(ipOctets)); + + if (!ipDuelRequestsLast10.has(ipOctets)) { + ipDuelRequestsLast10.set(ipOctets, 1); + } else { + ipDuelRequestsLast10.set(ipOctets, ipDuelRequestsLast10.get(ipOctets) + 1); + } + + if (ipDuelRequestsLast10.get(ipOctets) > 100) { + log('Banned IP due to spam', ipOctets); + bannedIps.add(ipOctets); + ws.close(); + + for(const player of players.values()) { + if(player.ip.includes(ipOctets)) { + player.ws.close(); + } + } + } + } } if (json.type === 'leaveQueue' && player.inQueue) { From dd03c3f06a81fe6ac5eeec3e0cb2957684ecd681 Mon Sep 17 00:00:00 2001 From: Gautam Anand Date: Mon, 28 Oct 2024 07:52:45 -0500 Subject: [PATCH 2/4] Fix --- ws/ws.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ws/ws.js b/ws/ws.js index 936848a3..377e96a5 100644 --- a/ws/ws.js +++ b/ws/ws.js @@ -423,6 +423,8 @@ app.ws('/wg', { } } } + } else { + log('Unknown ip req duel', player.ip, player.id, player.username); } } From e438c56ea50b28349c6c479a9ed396e3c7ceb54d Mon Sep 17 00:00:00 2001 From: Gautam Anand Date: Mon, 28 Oct 2024 07:53:25 -0500 Subject: [PATCH 3/4] Separatedev logs --- ws/ws.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ws/ws.js b/ws/ws.js index 377e96a5..c671c747 100644 --- a/ws/ws.js +++ b/ws/ws.js @@ -124,7 +124,7 @@ function log(...args) { // if(!dev) { if(process.env.DISCORD_WEBHOOK_WS) { const hook = new Webhook(process.env.DISCORD_WEBHOOK_WS); - hook.setUsername("Logs"); + hook.setUsername("Logs"+(dev ? ' - Dev' : '')); hook.send(args.join(' ')); } // } From 7ac6a8189278dd67d21ac3f2b557480b6a55bf02 Mon Sep 17 00:00:00 2001 From: Gautam Anand Date: Mon, 28 Oct 2024 10:32:06 -0500 Subject: [PATCH 4/4] Css fix --- styles/globals.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles/globals.scss b/styles/globals.scss index 87b6103b..fbb07c4c 100644 --- a/styles/globals.scss +++ b/styles/globals.scss @@ -1194,7 +1194,7 @@ screen and (pointer:coarse) { animation: fadeInLb 1s ease-in-out forwards; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1); - z-index: 110; + z-index: 1100; }