diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index 0036b6302..8248a1603 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -11,11 +11,7 @@ import { ServerStartGameMessageSchema, Turn, } from "../core/Schemas"; -import { - createGameRecord, - decompressGameRecord, - generateID, -} from "../core/Util"; +import { createGameRecord, decompressGameRecord } from "../core/Util"; import { LobbyConfig } from "./ClientGameRunner"; import { getPersistentIDFromCookie } from "./Main"; @@ -56,14 +52,6 @@ export class LocalServer { gameID: this.lobbyConfig.gameStartInfo.gameID, gameStartInfo: this.lobbyConfig.gameStartInfo, turns: this.turns, - players: [ - { - flag: this.lobbyConfig.flag, - playerID: generateID(), - clientID: this.lobbyConfig.clientID, - username: this.lobbyConfig.playerName, - }, - ], }), ); } diff --git a/src/client/SinglePlayerModal.ts b/src/client/SinglePlayerModal.ts index fbc23d0bd..25bf2e525 100644 --- a/src/client/SinglePlayerModal.ts +++ b/src/client/SinglePlayerModal.ts @@ -10,6 +10,7 @@ import "./components/baseComponents/Modal"; import "./components/Difficulties"; import { DifficultyDescription } from "./components/Difficulties"; import "./components/Maps"; +import { FlagInput } from "./FlagInput"; import { JoinLobbyEvent } from "./Main"; import { UsernameInput } from "./UsernameInput"; @@ -334,6 +335,10 @@ export class SinglePlayerModal extends LitElement { consolex.warn("Username input element not found"); } + const flagInput = document.querySelector("flag-input") as FlagInput; + if (!flagInput) { + consolex.warn("Flag input element not found"); + } this.dispatchEvent( new CustomEvent("join-lobby", { detail: { @@ -346,6 +351,10 @@ export class SinglePlayerModal extends LitElement { playerID: generateID(), clientID, username: usernameInput.getCurrentUsername(), + flag: + flagInput.getCurrentFlag() == "xx" + ? "" + : flagInput.getCurrentFlag(), }, ], config: { diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 1b50fbdad..d3c570a9b 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -337,6 +337,7 @@ export class Transport { lastTurn: numTurns, persistentID: this.lobbyConfig.persistentID, username: this.lobbyConfig.playerName, + flag: this.lobbyConfig.flag, }), ), ); diff --git a/src/client/graphics/layers/OptionsMenu.ts b/src/client/graphics/layers/OptionsMenu.ts index b52876518..165c99afd 100644 --- a/src/client/graphics/layers/OptionsMenu.ts +++ b/src/client/graphics/layers/OptionsMenu.ts @@ -205,7 +205,7 @@ export class OptionsMenu extends LitElement implements Layer { ? "Opens menu" : "Attack"), })} - ${button({ + `; diff --git a/src/client/graphics/layers/TerrainLayer.ts b/src/client/graphics/layers/TerrainLayer.ts index d84c1ef9d..bac8487c8 100644 --- a/src/client/graphics/layers/TerrainLayer.ts +++ b/src/client/graphics/layers/TerrainLayer.ts @@ -58,7 +58,6 @@ export class TerrainLayer implements Layer { } renderLayer(context: CanvasRenderingContext2D) { - console.log(this.transformHandler.scale); if (this.transformHandler.scale < 1) { context.imageSmoothingEnabled = true; context.imageSmoothingQuality = "low"; diff --git a/src/client/graphics/layers/TerritoryLayer.ts b/src/client/graphics/layers/TerritoryLayer.ts index d3c96c843..88ec807c3 100644 --- a/src/client/graphics/layers/TerritoryLayer.ts +++ b/src/client/graphics/layers/TerritoryLayer.ts @@ -55,7 +55,7 @@ export class TerritoryLayer implements Layer { paintPlayerBorder(player: PlayerView) { player.borderTiles().then((playerBorderTiles) => { playerBorderTiles.borderTiles.forEach((tile: TileRef) => { - this.paintTerritory(tile); // Immediately paint the tile instead of enqueueing + this.paintTerritory(tile, true); // Immediately paint the tile instead of enqueueing }); }); } diff --git a/src/core/Schemas.ts b/src/core/Schemas.ts index 0dc8d9ae7..fc5d6fbf9 100644 --- a/src/core/Schemas.ts +++ b/src/core/Schemas.ts @@ -125,12 +125,9 @@ const GameConfigSchema = z.object({ const SafeString = z .string() - // Remove common dangerous characters and patterns - // The weird \u stuff is to allow emojis .regex( - /^[a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|üÜ]+$/, + /^([a-zA-Z0-9\s.,!?@#$%&*()-_+=\[\]{}|;:"'\/\u00a9|\u00ae|[\u2000-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff]|üÜ])*$/, ) - // Reasonable max length to prevent DOS .max(1000); const EmojiSchema = z.string().refine( @@ -396,6 +393,7 @@ export const ClientJoinMessageSchema = ClientBaseMessageSchema.extend({ type: z.literal("join"), lastTurn: z.number(), // The last turn the client saw. username: SafeString, + flag: SafeString.nullable().optional(), }); export const ClientMessageSchema = z.union([ diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index 33da4cbc2..28626f7f0 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -268,7 +268,7 @@ export class DefaultConfig implements Config { case UnitType.AtomBomb: return { cost: (p: Player) => - p.type() == PlayerType.Human && this.infiniteGold() ? 0 : 500_000, + p.type() == PlayerType.Human && this.infiniteGold() ? 0 : 750_000, territoryBound: false, }; case UnitType.HydrogenBomb: diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 259ccccad..853467814 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -1,4 +1,4 @@ -import { GameType, UnitInfo, UnitType } from "../game/Game"; +import { UnitInfo, UnitType } from "../game/Game"; import { UserSettings } from "../game/UserSettings"; import { GameConfig } from "../Schemas"; import { GameEnv, ServerConfig } from "./Config"; @@ -40,10 +40,10 @@ export class DevConfig extends DefaultConfig { super(sc, gc, us); } - numSpawnPhaseTurns(): number { - return this.gameConfig().gameType == GameType.Singleplayer ? 70 : 100; - // return 100 - } + // numSpawnPhaseTurns(): number { + // return this.gameConfig().gameType == GameType.Singleplayer ? 70 : 100; + // // return 100 + // } unitInfo(type: UnitType): UnitInfo { const info = super.unitInfo(type); diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index c59e735cf..b63a0949d 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -550,6 +550,8 @@ export class GameView implements GameMap { } focusedPlayer(): PlayerView | null { + // TODO: renable when performance issues are fixed. + return this.myPlayer(); if (userSettings.focusLocked()) return this.myPlayer(); return this._focusedPlayer; } diff --git a/src/core/game/UnitImpl.ts b/src/core/game/UnitImpl.ts index 4c24170e9..ac5b80fc6 100644 --- a/src/core/game/UnitImpl.ts +++ b/src/core/game/UnitImpl.ts @@ -86,6 +86,8 @@ export class UnitImpl implements Unit { } this._lastTile = this._tile; this._tile = tile; + this.mg.removeUnit(this); + this.mg.addUnit(this); this.mg.addUpdate(this.toUpdate()); } setTroops(troops: number): void { diff --git a/src/core/game/UserSettings.ts b/src/core/game/UserSettings.ts index 536b908da..3c22c8ac5 100644 --- a/src/core/game/UserSettings.ts +++ b/src/core/game/UserSettings.ts @@ -25,7 +25,9 @@ export class UserSettings { } focusLocked() { - return this.get("settings.focusLocked", false); + return false; + // TODO: renable when performance issues are fixed. + this.get("settings.focusLocked", true); } toggleLeftClickOpenMenu() { diff --git a/src/server/Client.ts b/src/server/Client.ts index 13c3939d3..27bbd8d75 100644 --- a/src/server/Client.ts +++ b/src/server/Client.ts @@ -16,5 +16,6 @@ export class Client { public readonly ip: string, public readonly username: string, public readonly ws: WebSocket, + public readonly flag: string | null, ) {} } diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 54cf9a329..9210f7660 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -267,6 +267,7 @@ export class GameServer { playerID: c.playerID, username: c.username, clientID: c.clientID, + flag: c.flag, })), }); diff --git a/src/server/Master.ts b/src/server/Master.ts index a371bfb9c..3e8aecf2a 100644 --- a/src/server/Master.ts +++ b/src/server/Master.ts @@ -238,7 +238,7 @@ async function schedulePublicGame(playlist: MapPlaylist) { instantBuild: false, disableNPCs: false, disableNukes: false, - gameMode: Math.random() < 0.7 ? GameMode.FFA : GameMode.Team, + gameMode: Math.random() < 0.5 ? GameMode.FFA : GameMode.Team, bots: 400, } as GameConfig; diff --git a/src/server/Worker.ts b/src/server/Worker.ts index 32ece2100..0a2d0db83 100644 --- a/src/server/Worker.ts +++ b/src/server/Worker.ts @@ -303,6 +303,7 @@ export function startWorker() { ip, clientMsg.username, ws, + clientMsg.flag, ); const wasFound = gm.addClient(