mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-13 17:59:28 +00:00
show how many players in lobby
This commit is contained in:
@@ -42,6 +42,15 @@ export class GameServer {
|
||||
console.warn(`client ${clientMsg.clientID} sent to wrong game`)
|
||||
}
|
||||
}
|
||||
if (clientMsg.type == "leave") {
|
||||
const toRemove = this.clients.filter(c => c.id)
|
||||
if (toRemove.length == 0) {
|
||||
return
|
||||
}
|
||||
toRemove[0].ws.close()
|
||||
console.log(`client ${toRemove[0].id} left game`)
|
||||
this.clients = this.clients.filter(c => c.id != clientMsg.clientID)
|
||||
}
|
||||
})
|
||||
|
||||
// In case a client joined the game late and missed the start message.
|
||||
@@ -50,6 +59,10 @@ export class GameServer {
|
||||
}
|
||||
}
|
||||
|
||||
public numClients(): number {
|
||||
return this.clients.length
|
||||
}
|
||||
|
||||
public startTime(): number {
|
||||
return this.createdAt + this.config.lobbyLifetime()
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ const gm = new GameManager(getConfig())
|
||||
// New GET endpoint to list lobbies
|
||||
app.get('/lobbies', (req, res) => {
|
||||
res.json({
|
||||
lobbies: gm.gamesByPhase(GamePhase.Lobby).map(g => ({id: g.id, startTime: g.startTime()})),
|
||||
lobbies: gm.gamesByPhase(GamePhase.Lobby).map(g => ({id: g.id, startTime: g.startTime(), numClients: g.numClients()})),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user