Skip to content

Commit

Permalink
Fix some issues with decoding games
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumplation committed Dec 3, 2024
1 parent 86a644b commit e087777
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions referee/referee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { KinesisClient, PutRecordsCommand } from "@aws-sdk/client-kinesis";
import { Packet } from "utils/HydraMultiplayer/base.js";
import { fromHex, toHex } from "utils/helpers.js";



const NETWORK_ID = Number(process.env.NETWORK_ID);
const HYDRA_NODE = "http://localhost:4001/";
const RECORD_STATS = true;
Expand Down
8 changes: 4 additions & 4 deletions src/utils/HydraMultiplayer/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ function decodeGame(raw: Uint8Array): TGame {
cheaterRaw,
} = game;

const referee_key_hash = referee_payment[0];
const referee_key_hash = referee_payment.payment_key_hash;
const playerCount = playerCountRaw as bigint;
const botCount = botCountRaw as bigint;
return {
referee_key_hash: referee_key_hash,
playerCount,
botCount,
players: player_payments,
players: player_payments.map(p => p.payment_key_hash),
state: stateTag,
winner: winnerRaw[0],
cheater: cheaterRaw[0],
winner: winnerRaw,
cheater: cheaterRaw,
};
}
10 changes: 6 additions & 4 deletions src/utils/HydraMultiplayer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@ export type TPacketArray = Static<typeof PacketArraySchema>;
export const PacketArray = PacketArraySchema as unknown as TPacketArray;

export const GameSchema = Data.Object({
referee_payment: Data.Array(Data.Bytes()),
referee_payment: Data.Object({
payment_key_hash: Data.Bytes()
}),
playerCountRaw: Data.Integer(),
botCountRaw: Data.Integer(),
player_payments: Data.Array(Data.Bytes()),
player_payments: Data.Array(Data.Object({ payment_key_hash: Data.Bytes() })),
stateTag: Data.Enum([
Data.Literal("Lobby"),
Data.Literal("Running"),
Data.Literal("Cheated"),
Data.Literal("Finished"),
Data.Literal("Aborted"),
]),
winnerRaw: Data.Tuple(Data.Bytes()),
cheaterRaw: Data.Tuple(Data.Bytes()),
winnerRaw: Data.Nullable(Data.Object({ payment_key_hash: Data.Bytes() })),
cheaterRaw: Data.Nullable(Data.Object({ payment_key_hash: Data.Bytes() })),
});

export type TGame = Static<typeof GameSchema>;
Expand Down

0 comments on commit e087777

Please sign in to comment.