@@ -297,6 +297,13 @@ if (process.env.MAINTENANCE_SECRET) {
297
297
res . end ( 'ok' ) ;
298
298
console . log ( 'Unbanned ip' , ip ) ;
299
299
} ) ;
300
+ app . get ( `/getIpCounts/${ maintenanceSecret } ` , ( res ) => {
301
+ const ipCounts = [ ...ipConnectionCount . entries ( ) ] . map ( ( [ ip , cnt ] ) => ( { ip, cnt } ) ) ;
302
+ setCorsHeaders ( res ) ;
303
+ res . writeHeader ( 'Content-Type' , 'application/json' ) ;
304
+ res . end ( JSON . stringify ( ipCounts ) ) ;
305
+ } ) ;
306
+
300
307
}
301
308
302
309
const bannedIps = new Set ( ) ;
@@ -843,6 +850,9 @@ app.ws('/wg', {
843
850
} ,
844
851
close : ( ws , code , message ) => {
845
852
ipConnectionCount . set ( ws . ip , ipConnectionCount . get ( ws . ip ) - 1 ) ;
853
+ if ( ipConnectionCount . get ( ws . ip ) < 1 ) {
854
+ ipConnectionCount . delete ( ws . ip ) ;
855
+ }
846
856
847
857
if ( players . has ( ws . id ) ) {
848
858
const player = players . get ( ws . id ) ;
@@ -1003,9 +1013,7 @@ app.ws('/wg', {
1003
1013
1004
1014
if ( ! dev && dbEnabled ) {
1005
1015
setInterval ( ( ) => {
1006
- try {
1007
- console . log ( ipConnectionCount , players . size ) ;
1008
- } catch ( e ) { }
1016
+
1009
1017
const memUsage = process . memoryUsage ( ) . heapUsed ;
1010
1018
const gameCnt = games . size ;
1011
1019
const playerCnt = players . size ;
0 commit comments