mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-14 17:56:05 +00:00
feat: Prevent GameServer from restarting after ending by introducin… (#2923)
If this PR fixes an issue, link it below. If not, delete these two lines. Resolves #(issue number) #2919 In GameManager.tick(), when a game becomes active but hasn't started, a setTimeout for game.start() is scheduled with a 2-second delay. If the game finishes or is cancelled within those 2 seconds, game.end() is called, which clears the existing interval. However: 1.The 2-second timeout still fires. game.start() executes. 2. A NEW setInterval is created for turn execution. 3.Since the game is already ending/finished, it's removed from GameManager.games, but the interval continues to run forever in the background ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: codimo
This commit is contained in:
@@ -71,6 +71,8 @@ export class GameServer {
|
||||
{ winner: ClientSendWinnerMessage; ips: Set<string> }
|
||||
> = new Map();
|
||||
|
||||
private _hasEnded = false;
|
||||
|
||||
public desyncCount = 0;
|
||||
|
||||
constructor(
|
||||
@@ -536,7 +538,7 @@ export class GameServer {
|
||||
}
|
||||
|
||||
public start() {
|
||||
if (this._hasStarted) {
|
||||
if (this._hasStarted || this._hasEnded) {
|
||||
return;
|
||||
}
|
||||
this._hasStarted = true;
|
||||
@@ -639,9 +641,11 @@ export class GameServer {
|
||||
}
|
||||
|
||||
async end() {
|
||||
this._hasEnded = true;
|
||||
// Close all WebSocket connections
|
||||
if (this.endTurnIntervalID) {
|
||||
clearInterval(this.endTurnIntervalID);
|
||||
this.endTurnIntervalID = undefined;
|
||||
}
|
||||
this.websockets.forEach((ws) => {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
|
||||
Reference in New Issue
Block a user