Skip to content

Commit

Permalink
Merge branch 'bottomad' of https://github.com/codergautam/worldguessr
Browse files Browse the repository at this point in the history
  • Loading branch information
codergautam committed Oct 28, 2024
2 parents 549e085 + 7ac6a81 commit a0bf388
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion styles/globals.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
36 changes: 33 additions & 3 deletions ws/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.setUsername("Logs"+(dev ? ' - Dev' : ''));
hook.send(args.join(' '));
}
}
// }
}


Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -396,6 +401,31 @@ 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();
}
}
}
} else {
log('Unknown ip req duel', player.ip, player.id, player.username);
}
}

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

0 comments on commit a0bf388

Please sign in to comment.