Skip to content

Commit

Permalink
fix: matchmaking + gas (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
hsanger committed Jan 29, 2025
1 parent 0fb710a commit d5a2a42
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 45 deletions.
6 changes: 0 additions & 6 deletions server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const Config = {

maxPlayersPerGame: 80,
maxGames: 5,
gameJoinTime: 60,

gas: { mode: GasMode.Normal },

Expand Down Expand Up @@ -159,11 +158,6 @@ export interface ConfigType {
*/
readonly maxGames: number

/**
* The number of seconds after which players are prevented from joining a game.
*/
readonly gameJoinTime: number

/**
* There are 3 gas modes: GasMode.Normal, GasMode.Debug, and GasMode.Disabled.
* GasMode.Normal: Default gas behavior. overrideDuration is ignored.
Expand Down
46 changes: 23 additions & 23 deletions server/src/data/gasStages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,86 +23,86 @@ export const GasStages: GasStage[] = [
state: GasState.Waiting,
duration: 90,
oldRadius: 0.762,
newRadius: 0.45,
newRadius: 0.42,
dps: 0,
summonAirdrop: true
},
{
state: GasState.Advancing,
duration: 30,
oldRadius: 0.762,
newRadius: 0.45,
newRadius: 0.42,
dps: 1
},
{
state: GasState.Waiting,
duration: 60,
oldRadius: 0.45,
newRadius: 0.3,
dps: 1
oldRadius: 0.42,
newRadius: 0.238,
dps: 1,
preventJoin: true
},
{
state: GasState.Advancing,
duration: 20,
oldRadius: 0.45,
newRadius: 0.3,
dps: 2,
preventJoin: true
oldRadius: 0.42,
newRadius: 0.238,
dps: 2
},
{
state: GasState.Waiting,
duration: 45,
oldRadius: 0.3,
newRadius: 0.18,
oldRadius: 0.238,
newRadius: 0.095,
dps: 2,
summonAirdrop: true
},
{
state: GasState.Advancing,
duration: 10,
oldRadius: 0.3,
newRadius: 0.18,
oldRadius: 0.238,
newRadius: 0.095,
dps: 3
},
{
state: GasState.Waiting,
duration: 30,
oldRadius: 0.18,
newRadius: 0.1,
oldRadius: 0.095,
newRadius: 0.048,
dps: 3.5
},
{
state: GasState.Advancing,
duration: 5,
oldRadius: 0.18,
newRadius: 0.1,
oldRadius: 0.095,
newRadius: 0.048,
dps: 4
},
{
state: GasState.Waiting,
duration: 20,
oldRadius: 0.1,
newRadius: 0.05,
oldRadius: 0.048,
newRadius: 0.024,
dps: 5
},
{
state: GasState.Advancing,
duration: 5,
oldRadius: 0.1,
newRadius: 0.05,
oldRadius: 0.048,
newRadius: 0.024,
dps: 6.5
},
{
state: GasState.Waiting,
duration: 10,
oldRadius: 0.05,
oldRadius: 0.024,
newRadius: 0,
dps: 7.5
},
{
state: GasState.Advancing,
duration: 5,
oldRadius: 0.05,
oldRadius: 0.024,
newRadius: 0,
dps: 9
},
Expand Down
11 changes: 4 additions & 7 deletions server/src/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export class Game implements GameData {
}

if (this.aliveCount >= Config.maxPlayersPerGame) {
this.createNewGame();
this.preventJoin();
}

// Record performance and start the next tick
Expand Down Expand Up @@ -483,11 +483,10 @@ export class Game implements GameData {
parentPort?.postMessage({ type: WorkerMessages.UpdateGameData, data } satisfies WorkerMessage);
}

createNewGame(): void {
if (!this.allowJoin) return; // means a new game has already been created by this game
preventJoin(): void {
if (!this.allowJoin) return;

parentPort?.postMessage({ type: WorkerMessages.CreateNewGame });
this.log("Attempting to create new game");
this.log("Preventing new players from joining");
this.setGameData({ allowJoin: false });
}

Expand Down Expand Up @@ -753,8 +752,6 @@ export class Game implements GameData {
this._started = true;
this.setGameData({ startedTime: this.now });
this.gas.advanceGasStage();

this.addTimeout(this.createNewGame.bind(this), Config.gameJoinTime * 1000);
}, 3000);
}

Expand Down
9 changes: 1 addition & 8 deletions server/src/gameManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export enum WorkerMessages {
UpdateGameData,
UpdateMaxTeamSize,
UpdateMap,
CreateNewGame,
Reset
}

Expand All @@ -44,9 +43,7 @@ export type WorkerMessage =
readonly map: MapWithParams
}
| {
readonly type:
| WorkerMessages.CreateNewGame
| WorkerMessages.Reset
readonly type: WorkerMessages.Reset
};

export interface GameData {
Expand Down Expand Up @@ -101,10 +98,6 @@ export class GameContainer {
}
break;
}
case WorkerMessages.CreateNewGame: {
void newGame();
break;
}
case WorkerMessages.IPAllowed: {
const promises = this._ipPromiseMap.get(message.ip);
if (!promises) break;
Expand Down
2 changes: 1 addition & 1 deletion server/src/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export class Gas {
}

if (currentStage.preventJoin) {
this.game.setGameData({ allowJoin: false });
this.game.preventJoin();
}
}

Expand Down

0 comments on commit d5a2a42

Please sign in to comment.