mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-16 21:40:04 +00:00
revert gameserver
This commit is contained in:
@@ -35,8 +35,6 @@ export class GameServer {
|
||||
|
||||
private maxGameDuration = 3 * 60 * 60 * 1000; // 3 hours
|
||||
|
||||
private disconnectedTimeout = 1 * 30 * 1000; // 30 seconds
|
||||
|
||||
private turns: Turn[] = [];
|
||||
private intents: Intent[] = [];
|
||||
public activeClients: Client[] = [];
|
||||
@@ -147,6 +145,7 @@ export class GameServer {
|
||||
existingIP: ipAnonymize(conflicting.ip),
|
||||
existingPersistentID: conflicting.persistentID,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,11 +164,7 @@ export class GameServer {
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
client.isDisconnected = existing.isDisconnected;
|
||||
client.lastPing = existing.lastPing;
|
||||
|
||||
existing.ws.removeAllListeners();
|
||||
existing.ws.removeAllListeners("message");
|
||||
this.activeClients = this.activeClients.filter((c) => c !== existing);
|
||||
}
|
||||
|
||||
@@ -180,6 +175,7 @@ export class GameServer {
|
||||
this.allClients.set(client.clientID, client);
|
||||
|
||||
client.ws.removeAllListeners();
|
||||
|
||||
client.ws.on(
|
||||
"message",
|
||||
gatekeeper.wsHandler(client.ip, async (message: string) => {
|
||||
@@ -201,12 +197,6 @@ export class GameServer {
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (clientMsg.intent.type === "mark_disconnected") {
|
||||
this.log.warn(
|
||||
`Should not receive mark_disconnected intent from client`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.addIntent(clientMsg.intent);
|
||||
}
|
||||
if (clientMsg.type === "ping") {
|
||||
@@ -237,7 +227,6 @@ export class GameServer {
|
||||
}
|
||||
}),
|
||||
);
|
||||
client.ws.removeAllListeners("close");
|
||||
client.ws.on("close", () => {
|
||||
this.log.info("client disconnected", {
|
||||
clientID: client.clientID,
|
||||
@@ -247,7 +236,6 @@ export class GameServer {
|
||||
(c) => c.clientID !== client.clientID,
|
||||
);
|
||||
});
|
||||
client.ws.removeAllListeners("error");
|
||||
client.ws.on("error", (error: Error) => {
|
||||
if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") {
|
||||
client.ws.close(1002);
|
||||
@@ -371,7 +359,6 @@ export class GameServer {
|
||||
this.intents = [];
|
||||
|
||||
this.handleSynchronization();
|
||||
this.checkDisconnectedStatus();
|
||||
|
||||
let msg = "";
|
||||
try {
|
||||
@@ -552,36 +539,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({
|
||||
type: "mark_disconnected",
|
||||
clientID: client.clientID,
|
||||
isDisconnected: isDisconnected,
|
||||
});
|
||||
}
|
||||
|
||||
private archiveGame() {
|
||||
this.log.info("archiving game", {
|
||||
gameID: this.id,
|
||||
|
||||
Reference in New Issue
Block a user