From 18900975284816198572442d7fe795786525017f Mon Sep 17 00:00:00 2001 From: a-sync Date: Mon, 9 Sep 2024 20:09:43 +0200 Subject: [PATCH] extend gs.info object with gamedig response fields * adds password, ping, queryPort, version and raw --- src/game-server.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/game-server.ts b/src/game-server.ts index 3de20ce..e083ed3 100644 --- a/src/game-server.ts +++ b/src/game-server.ts @@ -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 { @@ -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); @@ -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);