change online counter to unique IPs

This commit is contained in:
HF 2021-03-18 21:10:57 +01:00
parent 7f817b5cc8
commit d46d528535
2 changed files with 6 additions and 2 deletions

View File

@ -87,7 +87,7 @@ class SocketServer extends WebSocketEvents {
cheapDetector(user.ip); cheapDetector(user.ip);
ws.send(OnlineCounter.dehydrate({ ws.send(OnlineCounter.dehydrate({
online: this.wss.clients.size || 0, online: ipCounter.amount() || 0,
})); }));
const ip = getIPFromRequest(req); const ip = getIPFromRequest(req);
@ -282,7 +282,7 @@ class SocketServer extends WebSocketEvents {
} }
onlineCounterBroadcast() { onlineCounterBroadcast() {
const online = this.wss.clients.size || 0; const online = ipCounter.amount() || 0;
webSockets.broadcastOnlineCounter(online); webSockets.broadcastOnlineCounter(online);
} }

View File

@ -11,6 +11,10 @@ export default class Counter<T> {
this.map = new Map(); this.map = new Map();
} }
amount(): number {
return this.map.size;
}
get(item: T): number { get(item: T): number {
const count = this.map.get(item) || 0; const count = this.map.get(item) || 0;
return count; return count;