Skip to content

Commit

Permalink
extend gs.info object with gamedig response fields
Browse files Browse the repository at this point in the history
 * adds password, ping, queryPort, version and raw
  • Loading branch information
a-sync committed Sep 9, 2024
1 parent b9356b0 commit 1890097
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/game-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ export interface Info {
name: string;
game: string;
map: string;
password: boolean;
playersNum: number;
playersMax: number;
players: GsPlayer[];
ping: number;
queryPort: number;
version: string;
raw?: {
[key: string]: any;
};
}

export class GameServer {
Expand Down Expand Up @@ -101,7 +108,7 @@ export class GameServer {
} as QueryOptions);

const raw = res.raw as { game?: string; folder?: string; presence_count?: number; };
const game = raw.game || raw.folder || this.config.type;
const game = raw?.game || raw?.folder || this.config.type;

const players: GsPlayer[] = res.players.map((p: Player) => {
return new GsPlayer(p);
Expand All @@ -112,9 +119,14 @@ export class GameServer {
name: res.name,
game: game,
map: res.map || '',
playersNum: res.numplayers || raw.presence_count || res.players.length,
password: res.password,
playersNum: res.numplayers || raw?.presence_count || res.players.length,
playersMax: res.maxplayers,
players
players,
ping: res.ping,
queryPort: res.queryPort,
version: res.version,
raw
};
} catch (e: any) {
console.error(['gs.gamedig', this.config.host, this.config.port].join(':'), e.message || e);
Expand Down

0 comments on commit 1890097

Please sign in to comment.