Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ port | Web port to use
host | IP or Hostname to listen on
type | Which kind of server to use, can be 'linux', 'windows' or 'wine'
additionalConfigurationOptions | Additional configuration options appended to server.cfg file
modsPath | Path where game mods are stored. Leave empty to use game directory
parameters | Extra startup parameters added to servers and headless clients
serverMods | Mods that always and only will be used by the game servers
auth | If both username and password is set, HTTP Basic Auth will be used
Expand Down
6 changes: 3 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ app.use(serveStatic(path.join(__dirname, 'public')))

var logs = new Logs(config)

var manager = new Manager(config, logs)
manager.load()

var missions = new Missions(config)
var mods = new Mods(config)
mods.updateMods()

var manager = new Manager(config, logs, mods)
manager.load()

var settings = new Settings(config)

app.use('/api/logs', require('./routes/logs')(logs))
Expand Down
1 change: 1 addition & 0 deletions config.js.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
game: 'arma3', // arma3, arma2oa, arma2, arma1, cwa, ofpresistance, ofp
path: 'path-to-arma3-directory',
modsPath: '', // optional: path to mod directories, relative to game directory
port: 3000,
host: '0.0.0.0', // Can be either an IP or a Hostname
type: 'linux', // Can be either linux, windows or wine
Expand Down
5 changes: 3 additions & 2 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ var Server = require('./server')

var filePath = 'servers.json'

var Manager = function (config, logs) {
var Manager = function (config, logs, mods) {
this.config = config
this.logs = logs
this.mods = mods
this.serversArr = []
this.serversHash = {}
}
Expand Down Expand Up @@ -41,7 +42,7 @@ Manager.prototype.removeServer = function (id) {
}

Manager.prototype._addServer = function (data) {
var server = new Server(this.config, this.logs, data)
var server = new Server(this.config, this.logs, this.mods, data)
this.serversArr.push(server)
this.serversArr.sort(function (a, b) {
return a.title.localeCompare(b.title)
Expand Down
27 changes: 24 additions & 3 deletions lib/mods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ var Mods = function (config) {
this.mods = []
}

Mods.prototype = new events.EventEmitter()
Mods.prototype = Object.create(events.EventEmitter.prototype)

Mods.prototype.delete = function (mod, cb) {
var self = this
fs.rmrf(path.join(this.config.path, mod), function (err) {
fs.rmrf(self.getAbsoluteModPath(mod), function (err) {
cb(err)

if (!err) {
Expand All @@ -23,7 +23,7 @@ Mods.prototype.delete = function (mod, cb) {

Mods.prototype.updateMods = function () {
var self = this
glob('**/{@*,gm,vn}/addons', { cwd: self.config.path }, function (err, files) {
glob('**/{@*,gm,vn}/addons', { cwd: self.getAbsoluteModsPath() }, function (err, files) {
if (err) {
console.log(err)
} else {
Expand All @@ -40,4 +40,25 @@ Mods.prototype.updateMods = function () {
})
}

Mods.prototype.getAbsoluteModsPath = function () {
if (this.config.modsPath) {
if (path.isAbsolute(this.config.modsPath)) {
return this.config.modsPath
}
return path.join(this.config.path, this.config.modsPath)
}
return this.config.path
}

Mods.prototype.getApplicableModPath = function (mod) {
if (!this.config.modsPath) {
return mod
}
return path.join(this.config.modsPath, mod)
}

Mods.prototype.getAbsoluteModPath = function (mod) {
return path.join(this.getAbsoluteModsPath(), mod)
}

module.exports = Mods
13 changes: 9 additions & 4 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ var createServerTitle = function (title) {
return title
}

var Server = function (config, logs, options) {
var Server = function (config, logs, mods, options) {
this.config = config
this.logs = logs
this.modsManager = mods
this.update(options)
}

Expand Down Expand Up @@ -134,6 +135,7 @@ Server.prototype.start = function () {
return this
}

var self = this
var parameters = this.getParameters()
var server = new ArmaServer.Server({
additionalConfigurationOptions: this.getAdditionalConfigurationOptions(),
Expand All @@ -149,7 +151,9 @@ Server.prototype.start = function () {
hostname: createServerTitle(this.title),
localClient: this.number_of_headless_clients > 0 ? ['127.0.0.1'] : null,
missions: this.missions,
mods: this.mods,
mods: this.mods.map(function (mod) {
return self.modsManager.getApplicableModPath(mod)
}),
motd: (this.motd && this.motd.split('\n')) || null,
parameters: parameters,
password: this.password,
Expand All @@ -164,7 +168,6 @@ Server.prototype.start = function () {
})
server.writeServerConfig()
var instance = server.start()
var self = this

var logStream = null
if (this.config.type === 'linux') {
Expand Down Expand Up @@ -225,7 +228,9 @@ Server.prototype.startHeadlessClients = function () {
filePatching: self.file_patching,
game: config.game,
host: '127.0.0.1',
mods: self.mods,
mods: self.mods.map(function (mod) {
return self.modsManager.getApplicableModPath(mod)
}),
parameters: parameters,
password: self.password,
path: self.config.path,
Expand Down
82 changes: 82 additions & 0 deletions test/lib/mods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
var path = require('path')
var os = require('os')
require('should')

function isWindows () {
return os.type() === 'Windows_NT'
}

var Mods = require('../../lib/mods.js')

describe('Mods', function () {
var rootPrefix = '/'
if (isWindows()) {
rootPrefix = 'C:'
}
var absoluteArmaPath = path.join(rootPrefix, 'foo', 'arma')
var absoluteModsPath = path.join(rootPrefix, 'foo', 'mods')
var relativeModsPath = path.join('..', 'mods')

describe('getAbsoluteModsPath() / getAbsoluteModPath(mod)', function () {
describe('when no modsPath is given', function () {
it('returns path', function () {
var mods = new Mods({ path: absoluteArmaPath })
mods.getAbsoluteModsPath().should.eql(absoluteArmaPath)
mods.getAbsoluteModPath('x').should.eql(path.join(absoluteArmaPath, 'x'))
})
})
describe('when modsPath is', function () {
it('relative, it returns absolute path', function () {
var mods = new Mods({ path: absoluteArmaPath, modsPath: relativeModsPath })
mods.getAbsoluteModsPath().should.eql(absoluteModsPath)
mods.getAbsoluteModPath('x').should.eql(path.join(absoluteModsPath, 'x'))
})
it('absolute, it returns absolute path', function () {
var mods = new Mods({ path: absoluteArmaPath, modsPath: absoluteModsPath })
mods.getAbsoluteModsPath().should.eql(absoluteModsPath)
mods.getAbsoluteModPath('x').should.eql(path.join(absoluteModsPath, 'x'))
})
})
})
describe('getApplicableModPath()', function () {
it('returns mod name if no modsPath is given', function () {
var mods = new Mods({ path: absoluteArmaPath })
mods.getApplicableModPath('x').should.eql('x')
})
it('returns relative path if relative modsPath is given', function () {
var mods = new Mods({ path: absoluteArmaPath, modsPath: relativeModsPath })
mods.getApplicableModPath('x').should.eql(path.join(relativeModsPath, 'x'))
})
it('returns absolute path if modsPath is absolute', function () {
var mods = new Mods({ path: absoluteArmaPath, modsPath: absoluteModsPath })
mods.getApplicableModPath('x').should.eql(path.join(absoluteModsPath, 'x'))
})
})

describe('updateMods()', function () {
it('finds mods in arma dir', function (done) {
var mods = new Mods({ path: path.join(__dirname, '..', 'resources', 'armaPath') })
mods.on('mods', function (modList) {
modList.should.eql([{ name: '@armaMod' }])
done()
})
mods.updateMods()
})
it('finds mods in modsPath dir', function (done) {
var mods = new Mods({ path: path.join(__dirname, '..', 'resources', 'armaPath'), modsPath: path.join(__dirname, '..', 'resources', 'modPath') })
mods.on('mods', function (modList) {
modList.should.eql([{ name: '@modPathMod' }])
done()
})
mods.updateMods()
})
it('finds mods in relative modsPath dir', function (done) {
var mods = new Mods({ path: path.join(__dirname, '..', 'resources', 'armaPath'), modsPath: path.join('..', 'modPath') })
mods.on('mods', function (modList) {
modList.should.eql([{ name: '@modPathMod' }])
done()
})
mods.updateMods()
})
})
})
4 changes: 2 additions & 2 deletions test/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ var Server = require('../../lib/server.js')
describe('Server', function () {
describe('generateId()', function () {
it('should include title', function () {
var server = new Server(null, null, { title: 'title.with.lot.of.dots' })
var server = new Server(null, null, null, { title: 'title.with.lot.of.dots' })
server.generateId().should.eql('title-with-lot-of-dots')
})
})

describe('toJSON()', function () {
it('should include title', function () {
var server = new Server(null, null, { title: 'test' })
var server = new Server(null, null, null, { title: 'test' })
server.toJSON().should.have.property('title', 'test')
})
})
Expand Down
Empty file.
Empty file.