From fb5b995d5116448d22f06ff55899f5b9086df67c Mon Sep 17 00:00:00 2001 From: Smith Date: Mon, 20 Mar 2023 16:45:35 +0100 Subject: [PATCH] gamedig: add support for token query field --- public/main.js | 7 +++++++ src/game-server.ts | 20 ++++++++++++++++++-- src/watcher.ts | 3 ++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/public/main.js b/public/main.js index 4175f51..096b9f5 100644 --- a/public/main.js +++ b/public/main.js @@ -111,6 +111,13 @@ $(async () => { "grid_columns": 6 } }, + "token": { + "title": "Terraria tshock REST user token", + "type": "string", + "options": { + "grid_columns": 12 + } + }, "updateIntervalMinutes": { "title": "Update interval (minutes) [NOT IMPLEMENTED]", "type": "integer", diff --git a/src/game-server.ts b/src/game-server.ts index 15c531d..c3b7490 100644 --- a/src/game-server.ts +++ b/src/game-server.ts @@ -1,5 +1,5 @@ import axios from 'axios'; -import { Player, query, QueryResult } from 'gamedig'; +import { Player, query, QueryResult, Type } from 'gamedig'; import { Low, JSONFile } from '@commonify/lowdb'; import ipRegex from './lib/ipregex'; import getIP from './lib/getip'; @@ -48,6 +48,20 @@ interface qRes extends QueryResult { numplayers: number; } +interface QueryOptions { + type: Type; + host: string; + port?: number; + ipfamily?: number; + maxAttempts?: number; + socketTimeout?: number; + attemptTimeout?: number; + givenPortOnly?: boolean; + debug?: boolean; + requestRules?: boolean; + token?: string; +} + export class GameServer { public ip: string; public info?: Info; @@ -97,7 +111,9 @@ export class GameServer { host: this.config.host, port: this.config.port, type: this.config.type, - }) as qRes; + requestRules: false, + token: this.config.token + } as QueryOptions) as qRes; const raw = res.raw as { game: string; folder: string; }; const game = raw.game || raw.folder || this.config.type; diff --git a/src/watcher.ts b/src/watcher.ts index 231380a..01339be 100644 --- a/src/watcher.ts +++ b/src/watcher.ts @@ -27,8 +27,9 @@ export interface GameServerConfig { updateIntervalMinutes?: number;//5 graphHistoryHours?: number;//12 timezoneOffset?: number;//0 - discord?: DiscordConfig[], + discord?: DiscordConfig[]; telegram?: TelegramConfig[]; + token?: string; } const adapter = new JSONFile(DATA_PATH + 'default.config.json');