2014-06-04 22:19:54 +00:00
|
|
|
var express = require('express');
|
|
|
|
var Resource = require('express-resource');
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2014-04-04 08:37:43 +00:00
|
|
|
var config = require('./config');
|
2015-01-21 02:18:45 +00:00
|
|
|
var Manager = require('./lib/manager');
|
2016-10-29 14:34:54 +00:00
|
|
|
var Missions = require('./lib/missions');
|
2015-01-21 03:00:09 +00:00
|
|
|
var Mods = require('./lib/mods');
|
2015-10-31 14:27:16 +00:00
|
|
|
var Logs = require('./lib/logs');
|
2014-02-09 03:19:48 +00:00
|
|
|
|
|
|
|
var app = express();
|
2014-06-04 22:19:54 +00:00
|
|
|
var server = require('http').Server(app);
|
|
|
|
var io = require('socket.io')(server);
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2015-05-30 00:29:48 +00:00
|
|
|
if (config.auth && config.auth.username && config.auth.password) {
|
|
|
|
app.use(express.basicAuth(config.auth.username, config.auth.password));
|
|
|
|
}
|
|
|
|
|
2014-02-09 03:19:48 +00:00
|
|
|
app.use(express.logger('dev'));
|
|
|
|
app.use(express.cookieParser());
|
|
|
|
app.use(express.bodyParser());
|
|
|
|
app.use(express.methodOverride());
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
|
2015-10-31 14:27:16 +00:00
|
|
|
var logs = new Logs(config);
|
|
|
|
|
|
|
|
var manager = new Manager(config, logs);
|
2015-01-21 02:18:45 +00:00
|
|
|
manager.load();
|
2015-10-31 14:27:16 +00:00
|
|
|
|
2016-10-29 14:34:54 +00:00
|
|
|
var missions = new Missions(config);
|
2015-01-21 03:00:09 +00:00
|
|
|
var mods = new Mods(config);
|
2015-02-14 18:42:18 +00:00
|
|
|
mods.updateMods();
|
2015-01-21 03:00:09 +00:00
|
|
|
|
2015-10-31 14:27:16 +00:00
|
|
|
var logsRoutes = require('./routes/logs')(logs);
|
2015-02-01 04:01:50 +00:00
|
|
|
var serversRoutes = require('./routes/servers')(manager, mods);
|
2016-10-29 14:34:54 +00:00
|
|
|
var missionsRoutes = require('./routes/missions')(missions);
|
2015-02-01 04:01:50 +00:00
|
|
|
var modsRoutes = require('./routes/mods')(mods);
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2015-10-31 14:27:16 +00:00
|
|
|
app.resource('api/logs', logsRoutes);
|
2016-10-29 14:34:54 +00:00
|
|
|
app.resource('api/missions', missionsRoutes);
|
2015-02-01 04:01:50 +00:00
|
|
|
app.resource('api/mods', modsRoutes);
|
|
|
|
var serversResource = app.resource('api/servers', serversRoutes);
|
2014-04-04 08:37:43 +00:00
|
|
|
app.resource('api/settings', require('./routes/settings'));
|
2014-02-13 22:47:51 +00:00
|
|
|
|
2015-08-15 15:12:50 +00:00
|
|
|
app.post('/api/missions/workshop', require('./routes/workshop').mission);
|
2015-05-29 23:30:53 +00:00
|
|
|
app.post('/api/mods/refresh', modsRoutes.refresh);
|
2015-02-01 04:01:50 +00:00
|
|
|
app.post('/api/mods/search', modsRoutes.search);
|
|
|
|
app.get('/api/servers/:server/start', serversRoutes.start);
|
|
|
|
app.get('/api/servers/:server/stop', serversRoutes.stop);
|
2014-02-09 03:19:48 +00:00
|
|
|
|
2014-04-04 08:37:43 +00:00
|
|
|
app.get('/', function (req, res){
|
2014-02-09 03:19:48 +00:00
|
|
|
res.sendfile(__dirname + '/public/index.html');
|
|
|
|
});
|
|
|
|
|
2014-06-04 22:19:54 +00:00
|
|
|
io.on('connection', function (socket) {
|
2015-02-01 04:27:12 +00:00
|
|
|
socket.emit('mods', mods.mods);
|
2014-06-04 22:19:54 +00:00
|
|
|
socket.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
2015-02-01 04:27:12 +00:00
|
|
|
mods.on('mods', function(mods) {
|
|
|
|
io.emit('mods', mods);
|
|
|
|
});
|
|
|
|
|
2014-06-04 22:19:54 +00:00
|
|
|
manager.on('servers', function() {
|
|
|
|
io.emit('servers', manager.getServers());
|
|
|
|
});
|
|
|
|
|
2015-05-29 15:23:19 +00:00
|
|
|
server.listen(config.port,config.host);
|