mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-04 04:29:43 +00:00
better websocket handling
This commit is contained in:
@@ -111,6 +111,7 @@ export class GameServer {
|
||||
this.log.warn(`cannot add client, already kicked`, {
|
||||
clientID: client.clientID,
|
||||
});
|
||||
client.ws.close(1002, "Kicked from game");
|
||||
return;
|
||||
}
|
||||
this.log.info("client (re)joining game", {
|
||||
@@ -174,6 +175,7 @@ export class GameServer {
|
||||
client.lastPing = existing.lastPing;
|
||||
|
||||
existing.ws.removeAllListeners();
|
||||
existing.ws.close(1000);
|
||||
this.activeClients = this.activeClients.filter((c) => c !== existing);
|
||||
}
|
||||
|
||||
@@ -183,7 +185,6 @@ export class GameServer {
|
||||
|
||||
this.allClients.set(client.clientID, client);
|
||||
|
||||
client.ws.removeAllListeners();
|
||||
client.ws.on(
|
||||
"message",
|
||||
gatekeeper.wsHandler(client.ip, async (message: string) => {
|
||||
|
||||
@@ -442,6 +442,8 @@ export function startWorker() {
|
||||
clientMsg.pattern,
|
||||
);
|
||||
|
||||
// Remove all listeners because we are passing ws ownership to the GameServer.
|
||||
ws.removeAllListeners();
|
||||
const wasFound = gm.addClient(
|
||||
client,
|
||||
clientMsg.gameID,
|
||||
@@ -452,7 +454,8 @@ export function startWorker() {
|
||||
log.info(
|
||||
`game ${clientMsg.gameID} not found on worker ${workerId}`,
|
||||
);
|
||||
// Handle game not found case
|
||||
ws.close(1002, "Game not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle other message types
|
||||
|
||||
Reference in New Issue
Block a user