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');
|
2015-01-21 03:00:09 +00:00
|
|
|
var Mods = require('./lib/mods');
|
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
|
|
|
|
|
|
|
app.use(express.logger('dev'));
|
|
|
|
app.use(express.cookieParser());
|
|
|
|
app.use(express.bodyParser());
|
|
|
|
app.use(express.methodOverride());
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
|
2015-01-21 02:18:45 +00:00
|
|
|
var manager = new Manager(config);
|
|
|
|
manager.load();
|
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-02-01 04:01:50 +00:00
|
|
|
var serversRoutes = require('./routes/servers')(manager, mods);
|
|
|
|
var modsRoutes = require('./routes/mods')(mods);
|
2014-04-06 21:09:52 +00:00
|
|
|
|
2014-09-28 08:50:03 +00:00
|
|
|
app.resource('api/logs', require('./routes/logs'));
|
2014-04-04 08:37:43 +00:00
|
|
|
app.resource('api/missions', require('./routes/missions'));
|
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-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);
|