Skip to content

Commit

Permalink
Fix parallel staking logic in connect 4
Browse files Browse the repository at this point in the history
  • Loading branch information
SneakySensei committed Sep 6, 2024
1 parent 7e640a2 commit 1c8ae0d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions packages/backend/microservices/connect-four/connect-four.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,35 @@ export const ConnectFourRoutes = async (socket: Socket, io: Namespace) => {

if (gameState.player1.player_id === player_id) {
gameState.player1.staked = true;
await RedisClient.hset(
room_id,
stringifyObjectValues<
Pick<ConnectFour.ServerGameState, "player1">
>({ player1: gameState.player1 }),
);
} else if (gameState.player2.player_id === player_id) {
gameState.player2.staked = true;
await RedisClient.hset(
room_id,
stringifyObjectValues<
Pick<ConnectFour.ServerGameState, "player2">
>({ player2: gameState.player2 }),
);
} else {
throw Error(
`Player ${player_id} does not exist in room ${room_id}`,
);
}

await RedisClient.hset(
room_id,
stringifyObjectValues<ConnectFour.ServerGameState>(
gameState,
),
);
const updatedGameState =
parseStringifiedValues<ConnectFour.ServerGameState>(
await RedisClient.hgetall(room_id),
);

if (gameState.player1.staked && gameState.player2.staked) {
if (
updatedGameState.player1.staked &&
updatedGameState.player2.staked
) {
await addMoneyToSeasonPool(season_id, tier_id);

const gameStartEvent: ConnectFour.GameStartEvent = {
Expand Down

0 comments on commit 1c8ae0d

Please sign in to comment.