mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 06:30:42 +00:00
delete games older than 1 hour
This commit is contained in:
Vendored
+20
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Program",
|
||||||
|
"skipFiles": [
|
||||||
|
"<node_internals>/**"
|
||||||
|
],
|
||||||
|
"program": "${workspaceFolder}/src/server/GameManager.ts",
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceFolder}/**/*.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -15,7 +15,9 @@
|
|||||||
* improve front page DONE 8/12/2024
|
* improve front page DONE 8/12/2024
|
||||||
* attacks cancel out DONE 8/13/2024
|
* attacks cancel out DONE 8/13/2024
|
||||||
* upload and start server DONE 8/13/2024
|
* upload and start server DONE 8/13/2024
|
||||||
* fix multiplayer
|
* fix multiplayer DONE 8/14/2024
|
||||||
|
* fix server resource leak
|
||||||
|
* balance attacks/expansions better
|
||||||
* better algorithm for name render placement
|
* better algorithm for name render placement
|
||||||
* make boats larger
|
* make boats larger
|
||||||
* have boats not get close to shore
|
* have boats not get close to shore
|
||||||
|
|||||||
@@ -43,12 +43,6 @@ export class GameManager {
|
|||||||
this.games.set(game.id, game)
|
this.games.set(game.id, game)
|
||||||
}
|
}
|
||||||
|
|
||||||
startGame(lobby: Lobby) {
|
|
||||||
const gs = new GameServer(this.random.nextID(), lobby.clients, defaultConfig)
|
|
||||||
this.games.set(gs.id, gs)
|
|
||||||
gs.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
tick() {
|
tick() {
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
|
|
||||||
@@ -56,7 +50,7 @@ export class GameManager {
|
|||||||
const expired = this.lobbies().filter(l => l.isExpired(now - 2000))
|
const expired = this.lobbies().filter(l => l.isExpired(now - 2000))
|
||||||
this._lobbies = new Map(active.map(lobby => [lobby.id, lobby]));
|
this._lobbies = new Map(active.map(lobby => [lobby.id, lobby]));
|
||||||
expired.forEach(lobby => {
|
expired.forEach(lobby => {
|
||||||
const game = new GameServer(lobby.id, lobby.clients, this.settings)
|
const game = new GameServer(lobby.id, now, lobby.clients, this.settings)
|
||||||
this.games.set(game.id, game)
|
this.games.set(game.id, game)
|
||||||
game.start()
|
game.start()
|
||||||
})
|
})
|
||||||
@@ -65,5 +59,15 @@ export class GameManager {
|
|||||||
this.lastNewLobby = now
|
this.lastNewLobby = now
|
||||||
this.addLobby(new Lobby(this.random.nextID(), this.settings.lobbyLifetime()))
|
this.addLobby(new Lobby(this.random.nextID(), this.settings.lobbyLifetime()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const activeGames: Map<GameID, GameServer> = new Map()
|
||||||
|
for (const [id, game] of this.games) {
|
||||||
|
if (game.isActive()) {
|
||||||
|
activeGames.set(id, game)
|
||||||
|
} else {
|
||||||
|
game.endGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//this.games = activeGames
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ export class GameServer {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public readonly id: GameID,
|
public readonly id: GameID,
|
||||||
|
private startTime: number,
|
||||||
private clients: Map<ClientID, Client>,
|
private clients: Map<ClientID, Client>,
|
||||||
private settings: Config,
|
private settings: Config,
|
||||||
) {
|
) {
|
||||||
@@ -67,8 +68,18 @@ export class GameServer {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private tick(event: TickEvent) {
|
public isActive(): boolean {
|
||||||
|
return Date.now() - this.startTime < 1000 * 60 * 60 // 1 hour
|
||||||
|
}
|
||||||
|
|
||||||
|
endGame() {
|
||||||
|
// Close all WebSocket connections
|
||||||
|
this.clients.forEach(client => {
|
||||||
|
client.ws.removeAllListeners('message');
|
||||||
|
if (client.ws.readyState === WebSocket.OPEN) {
|
||||||
|
client.ws.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user