mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 14:00:54 +00:00
Changed from lastping to ws.close
This commit is contained in:
@@ -235,10 +235,12 @@ export class GameServer {
|
||||
this.activeClients = this.activeClients.filter(
|
||||
(c) => c.clientID !== client.clientID,
|
||||
);
|
||||
this.markClientDisconnected(client, true);
|
||||
});
|
||||
client.ws.on("error", (error: Error) => {
|
||||
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
|
||||
client.ws.close(1002);
|
||||
this.markClientDisconnected(client, true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -359,7 +361,6 @@ export class GameServer {
|
||||
this.intents = [];
|
||||
|
||||
this.handleSynchronization();
|
||||
this.checkDisconnectedStatus();
|
||||
|
||||
let msg = "";
|
||||
try {
|
||||
@@ -444,6 +445,7 @@ export class GameServer {
|
||||
});
|
||||
if (client.ws.readyState === WebSocket.OPEN) {
|
||||
client.ws.close(1000, "no heartbeats received, closing connection");
|
||||
this.markClientDisconnected(client, true);
|
||||
}
|
||||
} else {
|
||||
alive.push(client);
|
||||
@@ -529,6 +531,7 @@ export class GameServer {
|
||||
persistentID: client.persistentID,
|
||||
});
|
||||
client.ws.close(1000, "Kicked from game");
|
||||
this.markClientDisconnected(client, true);
|
||||
this.activeClients = this.activeClients.filter(
|
||||
(c) => c.clientID !== clientID,
|
||||
);
|
||||
@@ -540,27 +543,6 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
private checkDisconnectedStatus() {
|
||||
if (this.turns.length % 5 !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const now = Date.now();
|
||||
for (const [clientID, client] of this.allClients) {
|
||||
if (
|
||||
client.isDisconnected === false &&
|
||||
now - client.lastPing > this.disconnectedTimeout
|
||||
) {
|
||||
this.markClientDisconnected(client, true);
|
||||
} else if (
|
||||
client.isDisconnected &&
|
||||
now - client.lastPing < this.disconnectedTimeout
|
||||
) {
|
||||
this.markClientDisconnected(client, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private markClientDisconnected(client: Client, isDisconnected: boolean) {
|
||||
client.isDisconnected = isDisconnected;
|
||||
this.addIntent({
|
||||
|
||||
Reference in New Issue
Block a user