mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-02 01:13:30 +00:00
Can select map on private lobbies
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {ClientMessage, ClientMessageSchema, Intent, ServerStartGameMessage, ServerStartGameMessageSchema, ServerTurnMessageSchema, Turn} from "../core/Schemas";
|
||||
import {ClientMessage, ClientMessageSchema, GameConfig, Intent, ServerStartGameMessage, ServerStartGameMessageSchema, ServerTurnMessageSchema, Turn} from "../core/Schemas";
|
||||
import {Config} from "../core/configuration/Config";
|
||||
import {Client} from "./Client";
|
||||
import WebSocket from 'ws';
|
||||
@@ -23,13 +23,21 @@ export class GameServer {
|
||||
|
||||
private endTurnIntervalID
|
||||
|
||||
|
||||
constructor(
|
||||
public readonly id: string,
|
||||
public readonly createdAt: number,
|
||||
public readonly isPublic: boolean,
|
||||
private config: Config,
|
||||
private gameConfig: GameConfig,
|
||||
) { }
|
||||
|
||||
public updateGameConfig(gameConfig: GameConfig): void {
|
||||
if (gameConfig.gameMap != null) {
|
||||
this.gameConfig.gameMap = gameConfig.gameMap
|
||||
}
|
||||
}
|
||||
|
||||
public addClient(client: Client, lastTurn: number) {
|
||||
console.log(`game ${this.id} adding client ${client.id}`)
|
||||
slog('client_joined_game', `client ${client.id} (re)joining game ${this.id}`, {
|
||||
@@ -93,7 +101,8 @@ export class GameServer {
|
||||
ws.send(JSON.stringify(ServerStartGameMessageSchema.parse(
|
||||
{
|
||||
type: "start",
|
||||
turns: this.turns.slice(lastTurn)
|
||||
turns: this.turns.slice(lastTurn),
|
||||
config: this.gameConfig
|
||||
}
|
||||
)))
|
||||
}
|
||||
@@ -137,7 +146,7 @@ export class GameServer {
|
||||
if (!this.isPublic) {
|
||||
if (this._hasStarted) {
|
||||
if (this.clients.length == 0) {
|
||||
console.log(`game ${this.id} is finisehd`)
|
||||
console.log()
|
||||
return GamePhase.Finished
|
||||
} else {
|
||||
return GamePhase.Active
|
||||
|
||||
Reference in New Issue
Block a user