Skip to content

Commit

Permalink
Use new built in public IP detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dahlgren committed Jul 21, 2023
1 parent 9ec8e83 commit b357455
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 30 deletions.
54 changes: 25 additions & 29 deletions lib/reforger/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 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)
})
var config = self.makeServerConfig()
self.saveServerConfig(config, function (err) {
if (err) {
console.log(err)
return
}

instance.on('close', function (code) {
clearInterval(self.queryStatusInterval)
self.state = null
self.pid = null
self.instance = null
var instance = childProcess.spawn(self.serverBinary(), self.serverArguments(), { cwd: self.config.path })

self.emit('state')
})
instance.on('error', function (err) {
console.error('Failed to start server', self.title, err)
})

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
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b357455

Please sign in to comment.