@@ -121,13 +121,13 @@ if (!process.env.MONGODB) {
121
121
function log ( ...args ) {
122
122
console . log ( new Date ( ) . toLocaleString ( "en-US" , { timeZone : "America/Chicago" } ) , ...args ) ;
123
123
124
- if ( ! dev ) {
124
+ // if(!dev) {
125
125
if ( process . env . DISCORD_WEBHOOK_WS ) {
126
126
const hook = new Webhook ( process . env . DISCORD_WEBHOOK_WS ) ;
127
- hook . setUsername ( "Logs" ) ;
127
+ hook . setUsername ( "Logs" + ( dev ? ' - Dev' : '' ) ) ;
128
128
hook . send ( args . join ( ' ' ) ) ;
129
129
}
130
- }
130
+ // }
131
131
}
132
132
133
133
@@ -308,6 +308,11 @@ if (process.env.MAINTENANCE_SECRET) {
308
308
309
309
const bannedIps = new Set ( ) ;
310
310
const ipConnectionCount = new Map ( ) ;
311
+ const ipDuelRequestsLast10 = new Map ( ) ;
312
+
313
+ setInterval ( ( ) => {
314
+ ipDuelRequestsLast10 . clear ( ) ;
315
+ } , 10000 ) ;
311
316
312
317
app . ws ( '/wg' , {
313
318
/* Options */
@@ -396,6 +401,31 @@ app.ws('/wg', {
396
401
console . log ( 'public duel requested by' , player . username , player . ip ) ;
397
402
player . inQueue = true ;
398
403
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
+ }
399
429
}
400
430
401
431
if ( json . type === 'leaveQueue' && player . inQueue ) {
0 commit comments