mirror of
https://github.com/Dahlgren/arma-server-web-admin.git
synced 2024-08-30 17:22:10 +00:00
Basic handling of servers
This commit is contained in:
parent
9b0c31e83e
commit
4fac04257d
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@ node_modules
|
|||||||
|
|
||||||
# Project stuff
|
# Project stuff
|
||||||
config.js
|
config.js
|
||||||
servers.js
|
|
||||||
|
19
main.js
19
main.js
@ -1,10 +1,13 @@
|
|||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
fs = require('fs');
|
fs = require('fs'),
|
||||||
|
slug = require('slug');
|
||||||
|
|
||||||
var config = require('./config'),
|
var config = require('./config'),
|
||||||
|
Manager = require('./manager'),
|
||||||
servers = require('./servers');
|
servers = require('./servers');
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
var manager = new Manager();
|
||||||
|
|
||||||
app.use(express.logger('dev'));
|
app.use(express.logger('dev'));
|
||||||
app.use(express.cookieParser());
|
app.use(express.cookieParser());
|
||||||
@ -39,7 +42,19 @@ app.get('/api/mods', function (req, res){
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/servers', function (req, res){
|
app.get('/api/servers', function (req, res){
|
||||||
res.send(servers);
|
res.send(manager.servers);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post('/api/servers', function (req, res){
|
||||||
|
var title = req.body.title;
|
||||||
|
var id = slug(title);
|
||||||
|
manager.addServer(id, title);
|
||||||
|
res.send(manager.servers);
|
||||||
|
});
|
||||||
|
|
||||||
|
app.get('/api/servers/:id/start', function (req, res){
|
||||||
|
manager.runServer();
|
||||||
|
res.send({status:"ok"});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/api/settings', function (req, res){
|
app.get('/api/settings', function (req, res){
|
||||||
|
53
manager.js
Normal file
53
manager.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
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;
|
||||||
|
this.servers.push(new Server(id, title, port, mods));
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Manager;
|
@ -4,6 +4,7 @@
|
|||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "3.x"
|
"express": "3.x",
|
||||||
|
"slug": "~0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
<a href='#servers/<%-name%>'><%-name%></a>
|
<a href='#servers/<%-id%>'><%-title%></a>
|
||||||
|
|
@ -1,4 +0,0 @@
|
|||||||
module.exports = [
|
|
||||||
{name: "first-server"},
|
|
||||||
{name: "second-server"}
|
|
||||||
];
|
|
Loading…
Reference in New Issue
Block a user