mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
var spawn = require('child_process').spawn;
|
|
|
|
var config = require('./config');
|
|
|
|
function Server(id, title, port, mods) {
|
|
this.id = id;
|
|
this.title = title;
|
|
this.port = port;
|
|
this.mods = mods;
|
|
}
|
|
|
|
Server.prototype.armaServerPath = function() {
|
|
return config.path + '/arma3server';
|
|
}
|
|
|
|
Server.prototype.makeModsParameter = function() {
|
|
return '-mod=' + this.mods.join(';');
|
|
}
|
|
|
|
Server.prototype.makePortParameter = function() {
|
|
return '-port=' + this.port;
|
|
}
|
|
|
|
Server.prototype.start = function() {
|
|
var mods = this.makeModsParameter();
|
|
var port = this.makePortParameter();
|
|
|
|
var server = spawn(this.armaServerPath(), [mods, port, '-config=server.cfg', '-noSound', '-world=empty']);
|
|
|
|
server.stdout.on('data', function (data) {
|
|
console.log('stdout: ' + data);
|
|
});
|
|
|
|
server.stderr.on('data', function (data) {
|
|
console.log('stderr: ' + data);
|
|
});
|
|
|
|
server.on('close', function (code) {
|
|
console.log('child process exited with code ' + code);
|
|
});
|
|
}
|
|
|
|
function Manager() {
|
|
this.servers = [];
|
|
};
|
|
|
|
Manager.prototype.addServer = (function (id, title) {
|
|
mods = [];
|
|
port = 2302;
|
|
var server = new Server(id, title, port, mods)
|
|
this.servers.push(server);
|
|
return server;
|
|
});
|
|
|
|
module.exports = Manager; |