Skip to content

Commit 7050bd0

Browse files
committed
dfg
1 parent 478da2e commit 7050bd0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

ws/ws.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ if (process.env.MAINTENANCE_SECRET) {
297297
res.end('ok');
298298
console.log('Unbanned ip', ip);
299299
});
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+
300307
}
301308

302309
const bannedIps = new Set();
@@ -843,6 +850,9 @@ app.ws('/wg', {
843850
},
844851
close: (ws, code, message) => {
845852
ipConnectionCount.set(ws.ip, ipConnectionCount.get(ws.ip) - 1);
853+
if(ipConnectionCount.get(ws.ip) < 1) {
854+
ipConnectionCount.delete(ws.ip);
855+
}
846856

847857
if (players.has(ws.id)) {
848858
const player = players.get(ws.id);
@@ -1003,9 +1013,7 @@ app.ws('/wg', {
10031013

10041014
if(!dev && dbEnabled) {
10051015
setInterval(() => {
1006-
try {
1007-
console.log(ipConnectionCount, players.size);
1008-
} catch(e) {}
1016+
10091017
const memUsage = process.memoryUsage().heapUsed;
10101018
const gameCnt = games.size;
10111019
const playerCnt = players.size;

0 commit comments

Comments
 (0)