use mcping-js, prevent ping loops while the last is still running
This commit is contained in:
parent
f9ce280a2b
commit
10bd23cfa4
23
lib/ping.js
23
lib/ping.js
@ -1,4 +1,4 @@
|
||||
const minecraftJavaPing = require('mc-ping-updated')
|
||||
const minecraftJavaPing = require('mcping-js')
|
||||
const minecraftBedrockPing = require('mcpe-ping-fixed')
|
||||
|
||||
const logger = require('./logger')
|
||||
@ -10,7 +10,9 @@ function ping (serverRegistration, timeout, callback, version) {
|
||||
switch (serverRegistration.data.type) {
|
||||
case 'PC':
|
||||
serverRegistration.unfurlSrv((host, port) => {
|
||||
minecraftJavaPing(host, port || 25565, (err, res) => {
|
||||
const server = new minecraftJavaPing.MinecraftServer(host, port || 25565)
|
||||
|
||||
server.ping(timeout, version, (err, res) => {
|
||||
if (err) {
|
||||
callback(err)
|
||||
} else {
|
||||
@ -28,7 +30,7 @@ function ping (serverRegistration, timeout, callback, version) {
|
||||
|
||||
callback(null, payload)
|
||||
}
|
||||
}, timeout, version)
|
||||
})
|
||||
})
|
||||
break
|
||||
|
||||
@ -71,6 +73,7 @@ function capPlayerCount (host, playerCount) {
|
||||
class PingController {
|
||||
constructor (app) {
|
||||
this._app = app
|
||||
this._isRunningTasks = false
|
||||
}
|
||||
|
||||
schedule () {
|
||||
@ -113,8 +116,15 @@ class PingController {
|
||||
}
|
||||
|
||||
startPingTasks = (callback) => {
|
||||
if (this._isRunningTasks) {
|
||||
logger.log('warn', 'Started re-pinging servers before the last loop has finished! You may need to increase "rates.pingAll" in config.json')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this._isRunningTasks = true
|
||||
|
||||
const results = []
|
||||
let remainingTasks = this._app.serverRegistrations.length
|
||||
|
||||
for (const serverRegistration of this._app.serverRegistrations) {
|
||||
const version = serverRegistration.getNextProtocolVersion()
|
||||
@ -130,7 +140,10 @@ class PingController {
|
||||
version
|
||||
}
|
||||
|
||||
if (--remainingTasks === 0) {
|
||||
if (Object.keys(results).length === this._app.serverRegistrations.length) {
|
||||
// Loop has completed, release the locking flag
|
||||
this._isRunningTasks = false
|
||||
|
||||
callback(results)
|
||||
}
|
||||
}, version.protocolId)
|
||||
|
@ -223,11 +223,7 @@ class ServerRegistration {
|
||||
|
||||
// Generate an updated hash
|
||||
// This is used by #getFaviconUrl
|
||||
if (!this._faviconHasher) {
|
||||
this._faviconHasher = crypto.createHash('md5')
|
||||
}
|
||||
|
||||
this.faviconHash = this._faviconHasher.update(favicon).digest('hex').toString()
|
||||
this.faviconHash = crypto.createHash('md5').update(favicon).digest('hex').toString()
|
||||
|
||||
return true
|
||||
}
|
||||
|
10
package-lock.json
generated
10
package-lock.json
generated
@ -5495,11 +5495,6 @@
|
||||
"object-visit": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"mc-ping-updated": {
|
||||
"version": "0.1.1",
|
||||
"resolved": "https://registry.npmjs.org/mc-ping-updated/-/mc-ping-updated-0.1.1.tgz",
|
||||
"integrity": "sha512-wYX4B41Jog+RvLFgYPytNvbw+b9mjjsKKqMLJ57a7aH3VgJCNzk6qeWFCTz7FLCWTEk8F81RBqh8kMPCjUVdNw=="
|
||||
},
|
||||
"mcpe-ping-fixed": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/mcpe-ping-fixed/-/mcpe-ping-fixed-0.0.3.tgz",
|
||||
@ -5509,6 +5504,11 @@
|
||||
"portfinder": "^0.4.0"
|
||||
}
|
||||
},
|
||||
"mcping-js": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/mcping-js/-/mcping-js-1.2.1.tgz",
|
||||
"integrity": "sha512-s0MRsyDnaxhG0lt1JqJl6tBewZkRj0fzeq/oU/aPSF74PrFW/ZWyzNOgh+NO5hY84U2XnRnscAZ0A0MIIEvC4A=="
|
||||
},
|
||||
"md5.js": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
|
||||
|
@ -5,8 +5,8 @@
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"finalhandler": "^1.1.2",
|
||||
"mc-ping-updated": "0.1.1",
|
||||
"mcpe-ping-fixed": "0.0.3",
|
||||
"mcping-js": "^1.2.1",
|
||||
"request": "2.88.2",
|
||||
"serve-static": "^1.14.1",
|
||||
"sqlite3": "4.1.1",
|
||||
|
Loading…
Reference in New Issue
Block a user