All players must join game before spawn (#380)

## Description:
The server stores all players that have joined, and once the game starts
it sends a list of players to all clients. Players cannot join after the
game has started. Server now generated the PlayerID instead of the
client.

The is necessary for team mode, we need to know how who is playing the
game before it starts so we can properly assign teams based on clans.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This commit is contained in:
evanpelle
2025-03-30 17:04:29 -07:00
committed by GitHub
parent d6e596f7d8
commit ab3f4fbac1
24 changed files with 212 additions and 189 deletions
+19 -39
View File
@@ -56,34 +56,24 @@ export class Executor {
}
createExec(intent: Intent): Execution {
let player: Player;
if (intent.type != "spawn") {
if (!this.mg.hasPlayer(intent.playerID)) {
console.warn(
`player ${intent.playerID} not found on intent ${intent.type}`,
);
return new NoOpExecution();
}
player = this.mg.player(intent.playerID);
if (player.clientID() != intent.clientID) {
console.warn(
`intent ${intent.type} has incorrect clientID ${intent.clientID} for player ${player.name()} with clientID ${player.clientID()}`,
);
return new NoOpExecution();
}
const player = this.mg.playerByClientID(intent.clientID);
if (!player) {
console.warn(`player with clientID ${intent.clientID} not found`);
return new NoOpExecution();
}
const playerID = player.id();
switch (intent.type) {
case "attack": {
return new AttackExecution(
intent.troops,
intent.playerID,
playerID,
intent.targetID,
null,
);
}
case "cancel_attack":
return new RetreatExecution(intent.playerID, intent.attackID);
return new RetreatExecution(playerID, intent.attackID);
case "move_warship":
return new MoveWarshipExecution(intent.unitId, intent.tile);
case "spawn":
@@ -94,50 +84,42 @@ export class Executor {
intent.clientID == this.clientID
? sanitize(intent.name)
: fixProfaneUsername(sanitize(intent.name)),
intent.playerType,
PlayerType.Human,
intent.clientID,
intent.playerID,
playerID,
),
this.mg.ref(intent.x, intent.y),
);
case "boat":
return new TransportShipExecution(
intent.playerID,
playerID,
intent.targetID,
this.mg.ref(intent.x, intent.y),
intent.troops,
);
case "allianceRequest":
return new AllianceRequestExecution(intent.playerID, intent.recipient);
return new AllianceRequestExecution(playerID, intent.recipient);
case "allianceRequestReply":
return new AllianceRequestReplyExecution(
intent.requestor,
intent.playerID,
playerID,
intent.accept,
);
case "breakAlliance":
return new BreakAllianceExecution(intent.playerID, intent.recipient);
return new BreakAllianceExecution(playerID, intent.recipient);
case "targetPlayer":
return new TargetPlayerExecution(intent.playerID, intent.target);
return new TargetPlayerExecution(playerID, intent.target);
case "emoji":
return new EmojiExecution(
intent.playerID,
intent.recipient,
intent.emoji,
);
return new EmojiExecution(playerID, intent.recipient, intent.emoji);
case "donate":
return new DonateExecution(
intent.playerID,
intent.recipient,
intent.troops,
);
return new DonateExecution(playerID, intent.recipient, intent.troops);
case "troop_ratio":
return new SetTargetTroopRatioExecution(intent.playerID, intent.ratio);
return new SetTargetTroopRatioExecution(playerID, intent.ratio);
case "embargo":
return new EmbargoExecution(player, intent.targetID, intent.action);
case "build_unit":
return new ConstructionExecution(
intent.playerID,
playerID,
this.mg.ref(intent.x, intent.y),
intent.unit,
);
@@ -147,9 +129,7 @@ export class Executor {
}
spawnBots(numBots: number): Execution[] {
return new BotSpawner(this.mg, this.gameID)
.spawnBots(numBots)
.map((i) => this.createExec(i));
return new BotSpawner(this.mg, this.gameID).spawnBots(numBots);
}
fakeHumanExecutions(): Execution[] {