add endpoint to kick players from a game given admin token, game id & client id

This commit is contained in:
evan
2025-05-09 13:00:39 -07:00
parent e2c97d8d51
commit c5152f035f
5 changed files with 89 additions and 1 deletions
+33
View File
@@ -57,6 +57,8 @@ export class GameServer {
private _hasPrestarted = false;
private kickedClients: Set<ClientID> = new Set();
constructor(
public readonly id: string,
readonly log_: Logger,
@@ -103,6 +105,12 @@ export class GameServer {
}
public addClient(client: Client, lastTurn: number) {
if (this.kickedClients.has(client.clientID)) {
this.log.warn(`cannot add client, already kicked`, {
clientID: client.clientID,
});
return;
}
this.log.info("client (re)joining game", {
clientID: client.clientID,
persistentID: client.persistentID,
@@ -492,6 +500,31 @@ export class GameServer {
return this.gameConfig.gameType == GameType.Public;
}
public kickClient(clientID: ClientID): void {
if (this.kickedClients.has(clientID)) {
this.log.warn(`cannot kick client, already kicked`, {
clientID,
});
return;
}
const client = this.activeClients.find((c) => c.clientID === clientID);
if (client) {
this.log.info("Kicking client from game", {
clientID: client.clientID,
persistentID: client.persistentID,
});
client.ws.close(1000, "Kicked from game");
this.activeClients = this.activeClients.filter(
(c) => c.clientID !== clientID,
);
this.kickedClients.add(clientID);
} else {
this.log.warn(`cannot kick client, not found in game`, {
clientID,
});
}
}
private handleSynchronization() {
if (this.activeClients.length <= 1) {
return;