mirror of
https://github.com/a-sync/game-server-watcher.git
synced 2026-07-22 05:41:43 -04:00
working games list
This commit is contained in:
@@ -17,13 +17,14 @@
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"title": "Gamedig type",
|
||||
"description": "Look for the <i>GameDig Type ID</i> in the <a href=\"https://github.com/gamedig/node-gamedig/blob/master/GAMES_LIST.md\">games list</a>.",
|
||||
"title": "GameDig type",
|
||||
"description": "For more info check the <a href=\"https://github.com/gamedig/node-gamedig/blob/master/GAMES_LIST.md\">GameDig games list</a>.",
|
||||
"type": "string",
|
||||
"minLength": 1,
|
||||
"options": {
|
||||
"grid_columns": 3
|
||||
}
|
||||
},
|
||||
"$ref": "gamedig-games"
|
||||
},
|
||||
"host": {
|
||||
"title": "Host name or IP",
|
||||
|
||||
@@ -16,18 +16,18 @@
|
||||
<link href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/animate.css@4/animate.min.css" rel="stylesheet">
|
||||
<!--
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4/dist/css/select2.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/simplemde@1/dist/simplemde.min.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/select2@4/dist/css/select2.min.css" rel="stylesheet">
|
||||
-->
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.slim.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1/dist/umd/popper.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<!--
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4/dist/js/select2.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/flatpickr@4/dist/flatpickr.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/simplemde@1/dist/simplemde.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/select2@4/dist/js/select2.min.js"></script>
|
||||
-->
|
||||
<script src="https://cdn.jsdelivr.net/npm/node-forge@1/dist/forge.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/dompurify@3/dist/purify.min.js"></script>
|
||||
|
||||
@@ -36,7 +36,7 @@ $(async () => {
|
||||
"compact": 0,
|
||||
"show_errors": "always",
|
||||
"required_by_default": 0,
|
||||
"no_additional_properties": 1,
|
||||
"no_additional_properties": true,
|
||||
"display_required_only": 1,
|
||||
"show_opt_in": 0,
|
||||
"remove_empty_properties": 0,
|
||||
|
||||
@@ -4,8 +4,8 @@ import crypto from 'node:crypto';
|
||||
import { createServer } from 'node:http';
|
||||
import { URL } from 'node:url';
|
||||
import { getInstance } from 'gamedig';
|
||||
//import gamedigPjson from '../node_modules/node-gamedig/package.json' assert {type: 'json'};
|
||||
const gamedigPjson = fs.readFileSync('../node_modules/node-gamedig/package.json', 'utf-8');
|
||||
//import gamedigPjson from '../node_modules/gamedig/package.json' assert {type: 'json'};
|
||||
const gamedigPjson = fs.readFileSync(path.resolve(__dirname, '../node_modules/gamedig/package.json'), 'utf-8');
|
||||
const gamedigVersion = JSON.parse(gamedigPjson).version || 0;
|
||||
|
||||
import 'dotenv/config';
|
||||
@@ -20,18 +20,30 @@ const DBG = Boolean(Number(process.env.DBG));
|
||||
|
||||
let loop: NodeJS.Timeout | undefined;
|
||||
|
||||
interface ApiResponse {
|
||||
interface ApiResponse extends FeaturesResponse, ConfigResponse {
|
||||
message?: string;
|
||||
error?: string;
|
||||
config?: GameServerConfig[];
|
||||
}
|
||||
|
||||
interface FeaturesResponse{
|
||||
features?: {
|
||||
gamedig: string;
|
||||
steam: boolean;
|
||||
discord: boolean;
|
||||
telegram: boolean;
|
||||
slack: boolean;
|
||||
};
|
||||
version?: string;
|
||||
games?: any[];//debug
|
||||
}
|
||||
|
||||
interface ConfigResponse{
|
||||
config?: GameServerConfig[];
|
||||
}
|
||||
|
||||
interface SelectOptionsResponse {
|
||||
options: {
|
||||
enum_titles: string[];
|
||||
};
|
||||
enum: string[];
|
||||
}
|
||||
|
||||
const EXT_MIME: Record<string, string> = {
|
||||
@@ -61,6 +73,23 @@ createServer(async (req, res) => {
|
||||
} else if (p === 'ping') {
|
||||
if (DBG) console.log('ping');
|
||||
res.end('pong');
|
||||
} else if (p === 'gamedig-games') {
|
||||
//re.version = gamedigPjson.version;
|
||||
const gd = getInstance();
|
||||
// @ts-ignore
|
||||
const games: Map<string,{pretty: string}> = gd.queryRunner.gameResolver.gamesByKey || new Map();
|
||||
let status = 200;
|
||||
let re: SelectOptionsResponse = {
|
||||
enum: Array.from(games.keys()),
|
||||
options: {
|
||||
enum_titles: Array.from(games.values()).map(g=>g.pretty)
|
||||
}
|
||||
};
|
||||
res.writeHead(status, {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'max-age=0'
|
||||
});
|
||||
res.end(JSON.stringify(re, null, DBG ? 2 : 0));
|
||||
} else if (SECRET !== '' && req.headers['x-btoken']) {
|
||||
let status = 200;
|
||||
let re: ApiResponse = {};
|
||||
@@ -70,6 +99,7 @@ createServer(async (req, res) => {
|
||||
try {
|
||||
if (reqPath[0] === 'features') {
|
||||
re.features = {
|
||||
gamedig: String(gamedigVersion),
|
||||
steam: Boolean(process.env.STEAM_WEB_API_KEY),
|
||||
discord: Boolean(process.env.DISCORD_BOT_TOKEN),
|
||||
telegram: Boolean(process.env.TELEGRAM_BOT_TOKEN),
|
||||
@@ -101,13 +131,6 @@ createServer(async (req, res) => {
|
||||
} else if (reqPath[0] === 'flush' && ['servers', 'discord', 'telegram', 'slack'].includes(reqPath[1])) {
|
||||
await restart(reqPath[1]);
|
||||
re.message = '🗑️ ' + reqPath[1].slice(0, 1).toUpperCase() + reqPath[1].slice(1) + ' data flushed.';
|
||||
} else if (reqPath[0] === 'gamedig-games') {
|
||||
//re.version = gamedigPjson.version;
|
||||
const gd = getInstance();
|
||||
// @ts-ignore
|
||||
const games = gd.queryRunner.gameResolver.games || [];
|
||||
re.version = gamedigVersion;
|
||||
re.games = games;
|
||||
} else {
|
||||
status = 400;
|
||||
re.error = 'Invalid Request';
|
||||
|
||||
Reference in New Issue
Block a user