First commit for PR

This commit is contained in:
drori200 2021-10-30 09:03:58 +03:00
parent a2168da999
commit e6faf6f8bd
4 changed files with 193 additions and 184 deletions

View File

@ -224,8 +224,8 @@ const refreshServerStatus = async function(fade = false){
let pVal = 'OFFLINE'
try {
const serverURL = new URL('my://' + serv.getAddress())
const servStat = await ServerStatus.getStatus(serverURL.hostname, serverURL.port)
const serverAddress = serv.getAddress()
const servStat = await ServerStatus.getStatus(serverAddress)
if (servStat.online) {
pLabel = 'PLAYERS'
pVal = servStat.onlinePlayers + '/' + servStat.maxPlayers
@ -233,7 +233,6 @@ const refreshServerStatus = async function(fade = false){
} catch (err) {
loggerLanding.warn('Unable to refresh server status, assuming offline.')
loggerLanding.debug(err)
}
if (fade) {
$('#server_status_wrapper').fadeOut(250, () => {

View File

@ -1,4 +1,6 @@
const net = require('net')
//const net = require('net)
const fetch = require('node-fetch')
const loggerLanding = LoggerUtil('%c[Landing]', 'color: #000668; font-weight: bold')
/**
* Retrieves the status of a minecraft server.
@ -8,7 +10,7 @@ const net = require('net')
* @returns {Promise.<Object>} A promise which resolves to an object containing
* status information.
*/
exports.getStatus = function(address, port = 25565){
exports.getStatus = async function (address, port = 25565) {
if (port == null || port == '') {
port = 25565
@ -16,8 +18,36 @@ exports.getStatus = function(address, port = 25565){
if (typeof port === 'string') {
port = parseInt(port)
}
let online,
version,
motd,
onlinePlayers,
maxPlayers;
let data;
return new Promise((resolve, reject) => {
try {
var response = await fetch(`https://api.mcsrvstat.us/2/${address}`);
data = await response.json();
online = data.online;
version = data.version
motd = data.motd.clean
onlinePlayers = data.players.online;
maxPlayers = data.players.max
} catch (err) {
loggerLanding.warn('Unable to refresh server status, assuming offline.')
loggerLanding.debug(err)
}
return {
online,
version,
motd,
onlinePlayers,
maxPlayers
};
/*return await new Promise((resolve, reject) => {
Commented out for documentation
const socket = net.connect(port, address, () => {
let buff = Buffer.from([0xFE, 0x01])
socket.write(buff)
@ -33,6 +63,7 @@ exports.getStatus = function(address, port = 25565){
})
})
Commented out for documentation
socket.on('data', (data) => {
if (data != null && data != '') {
let server_info = data.toString().split('\x00\x00\x00')
@ -60,6 +91,6 @@ exports.getStatus = function(address, port = 25565){
// ENOTFOUND = Unable to resolve.
// ECONNREFUSED = Unable to connect to port.
})
})
})*/
}

28
package-lock.json generated
View File

@ -2522,12 +2522,9 @@
"dev": true
},
"node-fetch": {
"version": "2.6.5",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
"requires": {
"whatwg-url": "^5.0.0"
}
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
},
"node-stream-zip": {
"version": "1.15.0",
@ -3117,11 +3114,6 @@
"punycode": "^2.1.1"
}
},
"tr46": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
"integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o="
},
"truncate-utf8-bytes": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
@ -3333,20 +3325,6 @@
"extsprintf": "^1.2.0"
}
},
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
"integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE="
},
"whatwg-url": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
"integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=",
"requires": {
"tr46": "~0.0.3",
"webidl-conversions": "^3.0.0"
}
},
"which": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",

View File

@ -33,6 +33,7 @@
"fs-extra": "^10.0.0",
"github-syntax-dark": "^0.5.0",
"jquery": "^3.6.0",
"node-fetch": "^2.6.2",
"node-stream-zip": "^1.15.0",
"request": "^2.88.2",
"semver": "^7.3.5",