From 553f78122520fb556b795369492595030db42929 Mon Sep 17 00:00:00 2001 From: leia uwu Date: Mon, 28 Oct 2024 23:22:34 -0300 Subject: [PATCH] chore: lint and fix build --- server/src/api/apiServer.ts | 4 ++-- server/src/config.ts | 1 - server/src/teamMenu.ts | 47 +++++++++++++++++-------------------- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/server/src/api/apiServer.ts b/server/src/api/apiServer.ts index e220a1d8..fc248749 100644 --- a/server/src/api/apiServer.ts +++ b/server/src/api/apiServer.ts @@ -3,7 +3,7 @@ import type { UpgradeWebSocket } from "hono/ws"; import { GIT_VERSION } from "../utils/gitRevision"; import { Config, type ConfigType } from "./../config"; import type { FindGameBody, FindGameResponse } from "./../gameServer"; -import { TeamMenu } from "./../teamMenu"; +import { TeamMenu, type TeamSocketData } from "./../teamMenu"; import { Logger } from "./../utils/logger"; export class Region { @@ -65,7 +65,7 @@ export class ApiServer { } } - init(app: Hono, upgradeWebSocket: UpgradeWebSocket) { + init(app: Hono, upgradeWebSocket: UpgradeWebSocket) { this.teamMenu.init(app, upgradeWebSocket); app.get("/api/site_info", (c) => { diff --git a/server/src/config.ts b/server/src/config.ts index 5cd68565..4c911d50 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -70,7 +70,6 @@ export const Config = { gameConfig: {}, } satisfies ConfigType as ConfigType; - if (!isProduction) { util.mergeDeep(Config, { regions: { diff --git a/server/src/teamMenu.ts b/server/src/teamMenu.ts index a5581f41..d62750ed 100644 --- a/server/src/teamMenu.ts +++ b/server/src/teamMenu.ts @@ -27,7 +27,7 @@ export interface TeamSocketData { } interface RoomPlayer extends TeamMenuPlayer { - socket: WSContext + socket: WSContext; } export interface Room { @@ -70,7 +70,7 @@ function randomString(len: number) { export class TeamMenu { rooms = new Map(); - constructor(public server: ApiServer) { } + constructor(public server: ApiServer) {} init(app: Hono, upgradeWebSocket: UpgradeWebSocket) { const teamMenu = this; @@ -78,8 +78,6 @@ export class TeamMenu { const httpRateLimit = new HTTPRateLimit(1, 2000); const wsRateLimit = new WebSocketRateLimit(5, 1000, 10); - console.log(upgradeWebSocket.toString()) - app.get( "/team_v2", upgradeWebSocket((c) => { @@ -87,7 +85,11 @@ export class TeamMenu { const ip = info.remote.address; let closeOnOpen = false; - if (!ip || httpRateLimit.isRateLimited(ip) || wsRateLimit.isIpRateLimited(ip)) { + if ( + !ip || + httpRateLimit.isRateLimited(ip) || + wsRateLimit.isIpRateLimited(ip) + ) { closeOnOpen = true; } @@ -96,7 +98,7 @@ export class TeamMenu { onOpen(_evt, ws: WSContext) { const userData = { ip, - rateLimit: {} + rateLimit: {}, } as TeamSocketData; ws.raw = userData; if (closeOnOpen) { @@ -120,8 +122,8 @@ export class TeamMenu { } wsRateLimit.ipDisconnected(userData.ip); }, - } - }) + }; + }), ); } @@ -178,7 +180,10 @@ export class TeamMenu { /** * @param socket player to send the response to */ - sendResponse(response: ServerToClientTeamMsg, socket: WSContext): void { + sendResponse( + response: ServerToClientTeamMsg, + socket: WSContext, + ): void { socket.send(JSON.stringify(response)); } @@ -307,7 +312,7 @@ export class TeamMenu { isLeader: true, inGame: false, playerId: 0, - socket: ws + socket: ws, }; if (!Config.modes[1].enabled && !Config.modes[2].enabled) { @@ -356,7 +361,7 @@ export class TeamMenu { isLeader: false, inGame: false, playerId: room.players.length, - socket: ws + socket: ws, } as RoomPlayer; room.players.push(player); @@ -368,9 +373,7 @@ export class TeamMenu { case "changeName": { const newName = this.cleanUserName(parsedMessage.data.name); const room = this.rooms.get(localPlayerData.roomUrl)!; - const player = room.players.find( - (p) => p.socket === ws, - )!; + const player = room.players.find((p) => p.socket === ws)!; player.name = newName; this.sendRoomState(room); @@ -379,9 +382,7 @@ export class TeamMenu { case "setRoomProps": { const newRoomData = parsedMessage.data; const room = this.rooms.get(localPlayerData.roomUrl)!; - const player = room.players.find( - (p) => p.socket === ws, - )!; + const player = room.players.find((p) => p.socket === ws)!; if (!player.isLeader) { return; } @@ -399,9 +400,7 @@ export class TeamMenu { } case "kick": { const room = this.rooms.get(localPlayerData.roomUrl)!; - const player = room.players.find( - (p) => p.socket === ws, - )!; + const player = room.players.find((p) => p.socket === ws)!; if (!player.isLeader) { return; } @@ -431,9 +430,7 @@ export class TeamMenu { case "playGame": { // this message can only ever be sent by the leader const room = this.rooms.get(localPlayerData.roomUrl)!; - const player = room.players.find( - (p) => p.socket === ws, - )!; + const player = room.players.find((p) => p.socket === ws)!; if (!player.isLeader) { return; @@ -478,9 +475,7 @@ export class TeamMenu { case "gameComplete": { // doesn't necessarily mean game is over, sent when player leaves game and returns to team menu const room = this.rooms.get(localPlayerData.roomUrl)!; - const player = room.players.find( - (p) => p.socket === ws, - )!; + const player = room.players.find((p) => p.socket === ws)!; player.inGame = false; room.roomData.findingGame = false;