Revert "Added a server-only intent creation"

This reverts commit 3502c81187.
This commit is contained in:
aqw42
2025-06-05 18:26:10 +02:00
parent 3502c81187
commit 2e29024f84
4 changed files with 17 additions and 39 deletions
+4 -9
View File
@@ -21,7 +21,7 @@ export class LocalServer {
private turns: Turn[] = [];
private intents: { intent: Intent; isServerSide: boolean }[] = [];
private intents: Intent[] = [];
private startedAt: number;
private paused = false;
@@ -96,11 +96,11 @@ export class LocalServer {
if (clientMsg.intent.type === "troop_ratio") {
// Store troop change events because otherwise they are
// not registered when game is paused.
this.intents.push({ intent: clientMsg.intent, isServerSide: false });
this.intents.push(clientMsg.intent);
}
return;
}
this.intents.push({ intent: clientMsg.intent, isServerSide: false });
this.intents.push(clientMsg.intent);
}
if (clientMsg.type === "hash") {
if (!this.lobbyConfig.gameRecord) {
@@ -154,12 +154,7 @@ export class LocalServer {
this.endGame();
return;
}
this.intents = this.replayTurns[this.turns.length].intents.map((i) => {
return {
intent: i.intent,
isServerSide: false,
};
});
this.intents = this.replayTurns[this.turns.length].intents;
}
const pastTurn: Turn = {
turnNumber: this.turns.length,
+1 -6
View File
@@ -323,12 +323,7 @@ const IntentSchema = z.union([
export const TurnSchema = z.object({
turnNumber: z.number(),
intents: z.array(
z.object({
intent: IntentSchema,
isServerSide: z.boolean(),
}),
),
intents: z.array(IntentSchema),
// The hash of the game state at the end of the turn.
hash: z.number().nullable().optional(),
});
+3 -7
View File
@@ -39,10 +39,10 @@ export class Executor {
}
createExecs(turn: Turn): Execution[] {
return turn.intents.map((i) => this.createExec(i.intent, i.isServerSide));
return turn.intents.map((i) => this.createExec(i));
}
createExec(intent: Intent, isServerSide: boolean): Execution {
createExec(intent: Intent): Execution {
const player = this.mg.playerByClientID(intent.clientID);
if (!player) {
console.warn(`player with clientID ${intent.clientID} not found`);
@@ -122,11 +122,7 @@ export class Executor {
intent.variables ?? {},
);
case "mark_disconnected":
if (isServerSide) {
return new MarkDisconnectedExecution(player, intent.isDisconnected);
} else {
return new NoOpExecution();
}
return new MarkDisconnectedExecution(player, intent.isDisconnected);
default:
throw new Error(`intent type ${intent} not found`);
}
+9 -17
View File
@@ -38,7 +38,7 @@ export class GameServer {
private disconnectedTimeout = 1 * 30 * 1000; // 30 seconds
private turns: Turn[] = [];
private intents: { intent: Intent; isServerSide: boolean }[] = [];
private intents: Intent[] = [];
public activeClients: Client[] = [];
// Used for record record keeping
private allClients: Map<ClientID, Client> = new Map();
@@ -325,8 +325,8 @@ export class GameServer {
});
}
private addIntent(intent: Intent, isServerSide: boolean = false) {
this.intents.push({ intent, isServerSide });
private addIntent(intent: Intent) {
this.intents.push(intent);
}
private sendStartGameMsg(ws: WebSocket, lastTurn: number) {
@@ -353,12 +353,7 @@ export class GameServer {
private endTurn() {
const pastTurn: Turn = {
turnNumber: this.turns.length,
intents: this.intents.map((i) => {
return {
intent: i.intent,
isServerSide: i.isServerSide,
};
}),
intents: this.intents,
};
this.turns.push(pastTurn);
this.intents = [];
@@ -568,14 +563,11 @@ export class GameServer {
private markClientDisconnected(client: Client, isDisconnected: boolean) {
client.isDisconnected = isDisconnected;
this.addIntent(
{
type: "mark_disconnected",
clientID: client.clientID,
isDisconnected: isDisconnected,
},
true,
);
this.addIntent({
type: "mark_disconnected",
clientID: client.clientID,
isDisconnected: isDisconnected,
});
}
private archiveGame() {