gamedig: add support for token query field

This commit is contained in:
Smith
2023-03-20 16:45:35 +01:00
parent fabcc10b11
commit fb5b995d51
3 changed files with 27 additions and 3 deletions

View File

@@ -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",

View File

@@ -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;

View File

@@ -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<GameServerConfig[]>(DATA_PATH + 'default.config.json');