implement TCP server, reimplement maxConnections except it now kicks the oldest connection

This commit is contained in:
Elijah R
2024-05-27 00:06:05 -04:00
parent 7053973205
commit 8add016b60
7 changed files with 115 additions and 6 deletions

View File

@@ -119,6 +119,12 @@ export default class CollabVMServer {
}
public addUser(user: User) {
let sameip = this.clients.filter(c => c.IP.address === user.IP.address);
if (sameip.length >= this.Config.collabvm.maxConnections) {
// Kick the oldest client
// I think this is a better solution than just rejecting the connection
sameip[0].kick();
}
this.clients.push(user);
user.socket.on('msg', (msg: string) => this.onMessage(user, msg));
user.socket.on('disconnect', () => this.connectionClosed(user));