Use new built in public IP detection

This commit is contained in:
Björn Dahlgren 2023-07-21 17:25:26 +02:00
parent 9ec8e83090
commit b3574552e2
2 changed files with 25 additions and 30 deletions

View File

@ -3,7 +3,6 @@ var events = require('events')
var fs = require('fs.extra')
var Gamedig = require('gamedig')
var path = require('path')
var publicIp = require('public-ip')
var slugify = require('slugify')
var queryInterval = 5000
@ -89,7 +88,7 @@ Server.prototype.makeServerConfig = function () {
return {
bindAddress: '',
bindPort: this.port,
publicAddress: this.ip,
publicAddress: '',
publicPort: this.port,
a2s: {
address: '127.0.0.1',
@ -172,39 +171,36 @@ Server.prototype.start = function () {
}
var self = this
publicIp.v4().then(function (ip) {
self.ip = ip
var config = self.makeServerConfig()
self.saveServerConfig(config, function (err) {
if (err) {
console.log(err)
return
}
var config = self.makeServerConfig()
self.saveServerConfig(config, function (err) {
if (err) {
console.log(err)
return
}
var instance = childProcess.spawn(self.serverBinary(), self.serverArguments(), { cwd: self.config.path })
var instance = childProcess.spawn(self.serverBinary(), self.serverArguments(), { cwd: self.config.path })
instance.on('error', function (err) {
console.error('Failed to start server', self.title, err)
})
instance.on('error', function (err) {
console.error('Failed to start server', self.title, err)
})
instance.on('close', function (code) {
clearInterval(self.queryStatusInterval)
self.state = null
self.pid = null
self.instance = null
self.emit('state')
})
self.pid = instance.pid
self.instance = instance
self.headlessClientInstances = []
self.queryStatusInterval = setInterval(function () {
self.queryStatus()
}, queryInterval)
instance.on('close', function (code) {
clearInterval(self.queryStatusInterval)
self.state = null
self.pid = null
self.instance = null
self.emit('state')
})
self.pid = instance.pid
self.instance = instance
self.headlessClientInstances = []
self.queryStatusInterval = setInterval(function () {
self.queryStatus()
}, queryInterval)
self.emit('state')
})
return this

View File

@ -39,7 +39,6 @@
"lodash": "^4.17.10",
"morgan": "^1.8.1",
"multer": "^1.3.0",
"public-ip": "^4.0.4",
"raw-loader": "^0.5.1",
"serve-static": "^1.12.1",
"slugify": "^1.1.0",