rewrite minecraft server status widget to directly ping server

pull/1067/head
Sairenity 2 years ago
parent f418ee6327
commit ad66637ff1

@ -20,6 +20,7 @@
"js-yaml": "^4.1.0",
"json-rpc-2.0": "^1.4.1",
"memory-cache": "^0.2.0",
"minecraft-ping-js": "^1.0.2",
"next": "^12.3.1",
"next-i18next": "^12.0.1",
"node-os-utils": "^1.3.7",

@ -22,6 +22,7 @@ specifiers:
js-yaml: ^4.1.0
json-rpc-2.0: ^1.4.1
memory-cache: ^0.2.0
minecraft-ping-js: ^1.0.2
next: ^12.3.1
next-i18next: ^12.0.1
node-os-utils: ^1.3.7
@ -53,6 +54,7 @@ dependencies:
js-yaml: 4.1.0
json-rpc-2.0: 1.4.1
memory-cache: 0.2.0
minecraft-ping-js: 1.0.2
next: 12.3.1_biqbaboplfbrettd7655fr4n2y
next-i18next: 12.0.1_azq6kxkn3od7qdylwkyksrwopy
node-os-utils: 1.3.7
@ -2152,6 +2154,13 @@ packages:
engines: {node: '>=6'}
dev: false
/minecraft-ping-js/1.0.2:
resolution: {integrity: sha512-h9QYG2n+fBKgp520tXBwR354XRzR/w5wXe8CJCmxKm6jbLpAoLODM8Nj5+ssuIVQF8rtxkAnjwv7PH+7ehFzQQ==}
dependencies:
node-int64: 0.4.0
varint: 6.0.0
dev: false
/mini-svg-data-uri/1.4.4:
resolution: {integrity: sha512-r9deDe9p5FJUPZAk3A59wGH7Ii9YrjjWw0jmw/liSbHl2CHiyXj6FcDXDu2K3TjVAXqiJdaw3xxwlZZr9E6nHg==}
hasBin: true
@ -2288,6 +2297,10 @@ packages:
- babel-plugin-macros
dev: false
/node-int64/0.4.0:
resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==}
dev: false
/node-os-utils/1.3.7:
resolution: {integrity: sha512-fvnX9tZbR7WfCG5BAy3yO/nCLyjVWD6MghEq0z5FDfN+ZXpLWNITBdbifxQkQ25ebr16G0N7eRWJisOcMEHG3Q==}
dev: false
@ -3296,6 +3309,10 @@ packages:
hasBin: true
dev: false
/varint/6.0.0:
resolution: {integrity: sha512-cXEIW6cfr15lFv563k4GuVuW/fiwjknytD37jIOLSdSWuOI6WnO/oKwmP2FQTU2l01LP8/M5TSAJpzUaGe3uWg==}
dev: false
/verror/1.10.0:
resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==}
engines: {'0': node >=0.6.0}

@ -0,0 +1,27 @@
import { pingWithPromise } from "minecraft-ping-js";
import createLogger from "utils/logger";
import getServiceWidget from "utils/config/service-helpers";
const proxyName = "minecraftProxyHandler";
const logger = createLogger(proxyName);
export default async function minecraftProxyHandler(req, res) {
const { group, service } = req.query;
const serviceWidget = await getServiceWidget(group, service);
try {
const pingResponse = await pingWithPromise(serviceWidget.domain, serviceWidget.port || 25565);
res.status(200).send({
version: pingResponse.version.name,
online: true,
players: pingResponse.players
});
} catch (e) {
logger.warn(e)
res.status(500).send({
version: undefined,
online: false,
players: undefined
});
}
}

@ -25,22 +25,15 @@ export default function Component({ service }) {
const statusIndicator = serverData.online ?
<span className="text-green-500">{t("minecraft.up")}</span>:
<span className="text-red-500">{t("minecraft.down")}</span>;
const players = serverData.players ? `${serverData.players.online} / ${serverData.players.max}` : "-";
const version = serverData.version || "-";
if(serverData.players){
return (
<Container service={service}>
<Block label="minecraft.status" value={statusIndicator} />
<Block label="minecraft.players" value={`${serverData.players.online} / ${serverData.players.max}`} />
<Block label="minecraft.version" value={serverData.version} />
</Container>
);
}
return (
<Container service={service}>
<Container service={service}>
<Block label="minecraft.status" value={statusIndicator} />
<Block label="minecraft.players" value="-" />
<Block label="minecraft.version" value="-" />
</Container>
<Block label="minecraft.players" value={players} />
<Block label="minecraft.version" value={version} />
</Container>
);
}

@ -1,12 +1,11 @@
import genericProxyHandler from "utils/proxy/handlers/generic";
import minecraftProxyHandler from "utils/proxy/handlers/minecraft";
import { asJson } from "utils/proxy/api-helpers";
const widget = {
api: "{url}/{endpoint}/{domain}",
proxyHandler: genericProxyHandler,
proxyHandler: minecraftProxyHandler,
mappings: {
status: {
endpoint: "2",
endpoint: "_",
map: (data) => {
const jsonData = asJson(data);
return {

Loading…
Cancel
Save