server.js (2577B)
1 /** 2 * Webserver and Websocket-server 3 * 4 * @module nBot 5 * @submodule server 6 * @requires app, express, http, io, rcon, addserver, util, pluginManager 7 */ 8 var app = require('express')(); 9 var express = require('express') 10 var http = require('http').Server(app); 11 var io = require('socket.io')(http); 12 var rcon = require("../backend/rcon.js") 13 var addserver = require("../backend/addServer.js") 14 var pluginManager = require("../backend/pluginManager.js") 15 var util = require('util'); 16 var path = require('path'); 17 /** 18 * @class server 19 * @static 20 */ 21 var server = module.exports = {}; 22 /** 23 * @method start 24 */ 25 server.start = function () { 26 app.get('/', function(req, res){ 27 res.sendFile(path.join(__dirname, '/theme/index.html')); 28 }); 29 app.get('/pluginManager', function(req, res){ 30 res.sendFile(path.join(__dirname, '/theme/admin/pluginManager.html')); 31 }); 32 app.get('/admin', function(req, res){ 33 res.sendFile(path.join(__dirname, '/theme/admin/index.html')); 34 }); 35 app.use('/css', express.static(path.join(__dirname, '/theme/css'))); 36 app.use('/js', express.static(path.join(__dirname, '/theme/js'))); 37 app.use('/fonts', express.static(path.join(__dirname, '/theme/fonts'))); 38 http.listen((process.env.PORT || 8080), "0.0.0.0", function(){ 39 console.log('listening on *:8080'); 40 }); 41 }, 42 /** 43 * @method iojs 44 */ 45 server.iojs = function () { 46 io.on('connection', function (socket) { 47 //senden an socket dass er verbunden ist 48 //socket.emit('userOnline', {message: 'verbunden'}); 49 50 //Informationen vom User holen 51 socket.on('command', function (command) { 52 console.log(command.command); 53 if (command.command === "restartgame") { 54 rcon.restart_game() 55 }else { 56 if (command.command === "live_on") { 57 rcon.live_on() 58 }else { 59 if (command.command === "status") { 60 rcon.status().then(result => console.log('Got status', result)) 61 //socket.emit('status_alert', {response: result}) 62 }else { 63 if (command.command === "script_download") { 64 addserver.start(socket, command) 65 }else { 66 if (command.command === "refreshSourcemod") { 67 pluginManager.getSourcemodVersions(socket, command) 68 }else { 69 console.log("unknown command"); 70 } 71 } 72 } 73 } 74 } 75 socket.emit('alert', {response: "command executed", command: command.command}); 76 }); 77 }); 78 }