Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Commit

Permalink
chore: lint and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Oct 29, 2024
1 parent 5306055 commit 9763954
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 29 deletions.
1 change: 0 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const Config = {
gameConfig: {},
} satisfies ConfigType as ConfigType;


if (!isProduction) {
util.mergeDeep(Config, {
regions: {
Expand Down
51 changes: 23 additions & 28 deletions server/src/teamMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface TeamSocketData {
}

interface RoomPlayer extends TeamMenuPlayer {
socket: WSContext<TeamSocketData>
socket: WSContext<TeamSocketData>;
}

export interface Room {
Expand Down Expand Up @@ -70,24 +70,26 @@ function randomString(len: number) {
export class TeamMenu {
rooms = new Map<string, Room>();

constructor(public server: ApiServer) { }
constructor(public server: ApiServer) {}

init(app: Hono, upgradeWebSocket: UpgradeWebSocket<TeamSocketData>) {
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<TeamSocketData>)((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;
}

Expand All @@ -96,7 +98,7 @@ export class TeamMenu {
onOpen(_evt, ws: WSContext<TeamSocketData>) {
const userData = {
ip,
rateLimit: {}
rateLimit: {},
} as TeamSocketData;
ws.raw = userData;
if (closeOnOpen) {
Expand All @@ -120,8 +122,8 @@ export class TeamMenu {
}
wsRateLimit.ipDisconnected(userData.ip);
},
}
})
};
}),
);
}

Expand Down Expand Up @@ -178,7 +180,10 @@ export class TeamMenu {
/**
* @param socket player to send the response to
*/
sendResponse(response: ServerToClientTeamMsg, socket: WSContext<TeamSocketData>): void {
sendResponse(
response: ServerToClientTeamMsg,
socket: WSContext<TeamSocketData>,
): void {
socket.send(JSON.stringify(response));
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand All @@ -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);
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 9763954

Please sign in to comment.