Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/updated gamedig implementation #4949

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
51 changes: 16 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"express-basic-auth": "~1.2.1",
"express-static-gzip": "~2.1.7",
"form-data": "~4.0.0",
"gamedig": "^4.2.0",
"gamedig": "^5.0.1",
"html-escaper": "^3.0.3",
"http-cookie-agent": "~5.0.4",
"http-graceful-shutdown": "~3.1.7",
Expand Down Expand Up @@ -211,4 +211,4 @@
"wait-on": "^7.2.0",
"whatwg-url": "~12.0.1"
}
}
}
4 changes: 2 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const version = require("../../package.json").version;
const apicache = require("../modules/apicache");
const { UptimeKumaServer } = require("../uptime-kuma-server");
const { DockerHost } = require("../docker");
const Gamedig = require("gamedig");
const { GameDig } = require("gamedig");
const jwt = require("jsonwebtoken");
const crypto = require("crypto");
const { UptimeCalculator } = require("../uptime-calculator");
Expand Down Expand Up @@ -696,7 +696,7 @@ class Monitor extends BeanModel {
}
} else if (this.type === "gamedig") {
try {
const state = await Gamedig.query({
const state = await GameDig.query({
type: this.game,
host: this.hostname,
port: this.port,
Expand Down
39 changes: 22 additions & 17 deletions server/socket-handlers/general-socket-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,36 @@ const { log } = require("../../src/util");
const { Settings } = require("../settings");
const { sendInfo } = require("../client");
const { checkLogin } = require("../util-server");
const GameResolver = require("gamedig/lib/GameResolver");
const { games } = require("gamedig");
const { testChrome } = require("../monitor-types/real-browser-monitor-type");
const fs = require("fs");
const path = require("path");

let gameResolver = new GameResolver();
let gameList = null;

/**
* Get a game list via GameDig
* @returns {object[]} list of games supported by GameDig
* @returns {object} list of games supported by GameDig
*/
function getGameList() {
if (gameList == null) {
gameList = gameResolver._readGames().games.sort((a, b) => {
if ( a.pretty < b.pretty ) {
return -1;
}
if ( a.pretty > b.pretty ) {
return 1;
}
return 0;
});
}
return gameList;
let gamelist = [];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

camelCase

gamelist = Object.keys(games).map(key => {
const item = games[key];
return {
keys: [ key ],
pretty: item.name,
options: item.options,
extra: item.extra || {}
};
});
gamelist.sort((a, b) => {
if ( a.pretty < b.pretty ) {
return -1;
}
if ( a.pretty > b.pretty ) {
return 1;
}
return 0;
});
return gamelist;
}

module.exports.generalSocketHandler = (socket, server) => {
Expand Down
Loading