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

Commit

Permalink
fix: more players joining games than they should
Browse files Browse the repository at this point in the history
  • Loading branch information
leia-uwu committed Oct 1, 2024
1 parent 8e2511d commit 42c4553
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/src/game/gameProcessManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ChildProcess, fork } from "child_process";
import { randomBytes } from "crypto";
import type { WebSocket } from "uWebSockets.js";
import { type MapDef, MapDefs } from "../../../shared/defs/mapDefs";
import type { TeamMode } from "../../../shared/gameConfig";
import { Config } from "../config";
import type { FindGameBody, GameSocketData } from "../gameServer";
Expand Down Expand Up @@ -108,6 +109,8 @@ class GameProcess implements GameData {

stoppedTime = Date.now();

avaliableSlots = 0;

constructor(manager: GameProcessManager, id: string, config: ServerGameConfig) {
this.manager = manager;
this.process = fork(path, args, {
Expand Down Expand Up @@ -173,6 +176,9 @@ class GameProcess implements GameData {
this.id = id;
this.teamMode = config.teamMode;
this.mapName = config.mapName;

const mapDef = MapDefs[this.mapName as keyof typeof MapDefs] as MapDef;
this.avaliableSlots = mapDef.gameMode.maxPlayers;
}

addJoinToken(token: string, autoFill: boolean, playerCount: number) {
Expand All @@ -182,6 +188,7 @@ class GameProcess implements GameData {
autoFill,
playerCount,
});
this.avaliableSlots--;
}

handleMsg(data: ArrayBuffer, socketId: string) {
Expand Down Expand Up @@ -316,7 +323,11 @@ export class GameProcessManager implements GameManager {

let game = this.processes
.filter((proc) => {
return proc.teamMode === mode.teamMode && proc.mapName === mode.mapName;
return (
proc.avaliableSlots > 0 &&
proc.teamMode === mode.teamMode &&
proc.mapName === mode.mapName
);
})
.sort((a, b) => {
return a.startedTime - b.startedTime;
Expand Down

0 comments on commit 42c4553

Please sign in to comment.