arma-server-web-admin/routes/servers.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

module.exports = function (manager, mods) {
var resolveMods = function(server, cb) {
mods.resolveMods(server.mods, function(err, resolvedMods) {
if (!err) {
server.mods = resolvedMods;
manager.save();
}
cb();
});
};
return {
index: function (req, res){
res.send(manager.getServers());
},
2014-04-06 22:58:17 +00:00
create: function (req, res) {
var server = manager.addServer(req.body);
if (server.mods.length > 0) {
resolveMods(server, function() {
res.send(server);
});
} else {
res.send(server);
}
},
2014-04-04 08:37:43 +00:00
show: function (req, res){
var server = manager.getServer(req.params.server);
res.send(server);
},
2014-04-04 08:37:43 +00:00
update: function(req, res){
var server = manager.getServer(req.params.server);
server.update(req.body);
manager.save();
2014-04-06 21:09:52 +00:00
if (server.mods.length > 0) {
resolveMods(server, function() {
res.send(server);
});
} else {
res.send(server);
}
},
2014-04-08 20:59:59 +00:00
destroy: function(req, res){
var server = manager.removeServer(req.params.server);
2014-06-04 22:17:18 +00:00
res.send(server);
},
2014-04-06 21:09:52 +00:00
start: function (req, res){
var server = manager.getServer(req.params.server);
server.start();
res.send({status:"ok", pid: server.pid});
},
2014-04-06 22:58:17 +00:00
stop: function (req, res){
var server = manager.getServer(req.params.server);
server.stop(function () {
if (!server.pid) {
res.send({status: true, pid: server.pid});
} else {
res.send({status: false, pid: server.pid});
}
});
},
};
2014-04-06 21:09:52 +00:00
};