Skip to content

Commit

Permalink
fix(rpc): staking events
Browse files Browse the repository at this point in the history
  • Loading branch information
jagnani73 committed Sep 2, 2024
1 parent 54b7950 commit 0fc74fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const RockPaperScissorsRoutes = async (
tier_id,
player_id,
}: RockPaperScissors.JoinEvent["payload"]) => {
console.log(1);
try {
const roomKey: string = `${season_id}::${game_id}::${tier_id}`;
const logId: string = `[${season_id}][${game_id}][${tier_id}][${player_id}]`;
Expand Down Expand Up @@ -137,15 +138,19 @@ export const RockPaperScissorsRoutes = async (
playerJoinedEvent.payload,
);

const { player1, player2, round } =
const gameState =
parseStringifiedValues<RockPaperScissors.ServerGameState>(
await RedisClient.hgetall(room_id),
);

if (player1 && player2) {
if (gameState.player1 && gameState.player2) {
const stakingEvent: RockPaperScissors.StakingEvent = {
type: "staking",
payload: null,
payload: {
player1: gameState.player1,
player2: gameState.player2,
round: gameState.round as 0,
},
};
io.to(room_id).emit(
stakingEvent.type,
Expand Down
6 changes: 5 additions & 1 deletion packages/common/rock-paper-scissors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export type PlayerJoinedEvent = {

export type StakingEvent = {
type: "staking";
payload: null;
payload: {
round: 0;
player1: PlayerServerState;
player2: PlayerServerState;
};
};

export type GameStartEvent = {
Expand Down

0 comments on commit 0fc74fa

Please sign in to comment.