First commit for PR
This commit is contained in:
parent
a2168da999
commit
e6faf6f8bd
@ -224,8 +224,8 @@ const refreshServerStatus = async function(fade = false){
|
|||||||
let pVal = 'OFFLINE'
|
let pVal = 'OFFLINE'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const serverURL = new URL('my://' + serv.getAddress())
|
const serverAddress = serv.getAddress()
|
||||||
const servStat = await ServerStatus.getStatus(serverURL.hostname, serverURL.port)
|
const servStat = await ServerStatus.getStatus(serverAddress)
|
||||||
if (servStat.online) {
|
if (servStat.online) {
|
||||||
pLabel = 'PLAYERS'
|
pLabel = 'PLAYERS'
|
||||||
pVal = servStat.onlinePlayers + '/' + servStat.maxPlayers
|
pVal = servStat.onlinePlayers + '/' + servStat.maxPlayers
|
||||||
@ -233,7 +233,6 @@ const refreshServerStatus = async function(fade = false){
|
|||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
loggerLanding.warn('Unable to refresh server status, assuming offline.')
|
loggerLanding.warn('Unable to refresh server status, assuming offline.')
|
||||||
loggerLanding.debug(err)
|
|
||||||
}
|
}
|
||||||
if (fade) {
|
if (fade) {
|
||||||
$('#server_status_wrapper').fadeOut(250, () => {
|
$('#server_status_wrapper').fadeOut(250, () => {
|
||||||
|
@ -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.
|
* 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
|
* @returns {Promise.<Object>} A promise which resolves to an object containing
|
||||||
* status information.
|
* status information.
|
||||||
*/
|
*/
|
||||||
exports.getStatus = function(address, port = 25565){
|
exports.getStatus = async function (address, port = 25565) {
|
||||||
|
|
||||||
if (port == null || port == '') {
|
if (port == null || port == '') {
|
||||||
port = 25565
|
port = 25565
|
||||||
@ -16,8 +18,36 @@ exports.getStatus = function(address, port = 25565){
|
|||||||
if (typeof port === 'string') {
|
if (typeof port === 'string') {
|
||||||
port = parseInt(port)
|
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, () => {
|
const socket = net.connect(port, address, () => {
|
||||||
let buff = Buffer.from([0xFE, 0x01])
|
let buff = Buffer.from([0xFE, 0x01])
|
||||||
socket.write(buff)
|
socket.write(buff)
|
||||||
@ -33,6 +63,7 @@ exports.getStatus = function(address, port = 25565){
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Commented out for documentation
|
||||||
socket.on('data', (data) => {
|
socket.on('data', (data) => {
|
||||||
if (data != null && data != '') {
|
if (data != null && data != '') {
|
||||||
let server_info = data.toString().split('\x00\x00\x00')
|
let server_info = data.toString().split('\x00\x00\x00')
|
||||||
@ -60,6 +91,6 @@ exports.getStatus = function(address, port = 25565){
|
|||||||
// ENOTFOUND = Unable to resolve.
|
// ENOTFOUND = Unable to resolve.
|
||||||
// ECONNREFUSED = Unable to connect to port.
|
// ECONNREFUSED = Unable to connect to port.
|
||||||
})
|
})
|
||||||
})
|
})*/
|
||||||
|
|
||||||
}
|
}
|
28
package-lock.json
generated
28
package-lock.json
generated
@ -2522,12 +2522,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node-fetch": {
|
"node-fetch": {
|
||||||
"version": "2.6.5",
|
"version": "2.6.2",
|
||||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.5.tgz",
|
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.2.tgz",
|
||||||
"integrity": "sha512-mmlIVHJEu5rnIxgEgez6b9GgWXbkZj5YZ7fx+2r94a2E+Uirsp6HsPTPlomfdHtpt/B0cdKviwkoaM6pyvUOpQ==",
|
"integrity": "sha512-aLoxToI6RfZ+0NOjmWAgn9+LEd30YCkJKFSyWacNZdEKTit/ZMcKjGkTRo8uWEsnIb/hfKecNPEbln02PdWbcA=="
|
||||||
"requires": {
|
|
||||||
"whatwg-url": "^5.0.0"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"node-stream-zip": {
|
"node-stream-zip": {
|
||||||
"version": "1.15.0",
|
"version": "1.15.0",
|
||||||
@ -3117,11 +3114,6 @@
|
|||||||
"punycode": "^2.1.1"
|
"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": {
|
"truncate-utf8-bytes": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
|
||||||
@ -3333,20 +3325,6 @@
|
|||||||
"extsprintf": "^1.2.0"
|
"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": {
|
"which": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"github-syntax-dark": "^0.5.0",
|
"github-syntax-dark": "^0.5.0",
|
||||||
"jquery": "^3.6.0",
|
"jquery": "^3.6.0",
|
||||||
|
"node-fetch": "^2.6.2",
|
||||||
"node-stream-zip": "^1.15.0",
|
"node-stream-zip": "^1.15.0",
|
||||||
"request": "^2.88.2",
|
"request": "^2.88.2",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
|
Loading…
Reference in New Issue
Block a user