mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:32:41 +00:00
used msUntil start because server has different time than client
This commit is contained in:
@@ -71,7 +71,7 @@ class Client {
|
||||
|
||||
if (nameElement) nameElement.textContent = `Game ${lobby.id}`;
|
||||
if (timerElement) {
|
||||
const timeRemaining = Math.max(0, Math.floor((lobby.startTime - Date.now()) / 1000));
|
||||
const timeRemaining = Math.max(0, Math.floor((lobby.msUntilStart) / 1000));
|
||||
timerElement.textContent = `Starts in: ${timeRemaining}s`;
|
||||
}
|
||||
if (playerCountElement) playerCountElement.textContent = `Players: ${lobby.numClients}`;
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ export type ClientLeaveMessage = z.infer<typeof ClientLeaveMessageSchema>
|
||||
|
||||
export interface Lobby {
|
||||
id: string;
|
||||
startTime: number;
|
||||
msUntilStart: number;
|
||||
numClients: number;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +115,6 @@ export class GameServer {
|
||||
this.clients.forEach(c => {
|
||||
c.ws.send(msg)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
endGame() {
|
||||
|
||||
@@ -24,8 +24,11 @@ const gm = new GameManager(getConfig())
|
||||
|
||||
// New GET endpoint to list lobbies
|
||||
app.get('/lobbies', (req, res) => {
|
||||
const now = Date.now()
|
||||
res.json({
|
||||
lobbies: gm.gamesByPhase(GamePhase.Lobby).map(g => ({id: g.id, startTime: g.startTime(), numClients: g.numClients()})),
|
||||
lobbies: gm.gamesByPhase(GamePhase.Lobby)
|
||||
.map(g => ({id: g.id, msUntilStart: g.startTime() - now, numClients: g.numClients()}))
|
||||
// .sort((a, b) => a.startTime - b.startTime),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user