From 976395445a02921d4ccb13e3214d05c1ed0b6ba9 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/config.ts | 1 - server/src/teamMenu.ts | 51 +++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 29 deletions(-) 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..270dae46 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,24 +70,26 @@ function randomString(len: number) { export class TeamMenu { rooms = new Map(); - constructor(public server: ApiServer) { } + constructor(public server: ApiServer) {} - init(app: Hono, upgradeWebSocket: UpgradeWebSocket) { + init(app: Hono, upgradeWebSocket: UpgradeWebSocket) { const teamMenu = this; const httpRateLimit = new HTTPRateLimit(1, 2000); const wsRateLimit = new WebSocketRateLimit(5, 1000, 10); - console.log(upgradeWebSocket.toString()) - app.get( "/team_v2", - upgradeWebSocket((c) => { + (upgradeWebSocket as UpgradeWebSocket)((c) => { const info = getConnInfo(c); 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;