diff --git a/bootstrap.php b/bootstrap.php index f72b7538..ead9e655 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -151,7 +151,7 @@ public function run() { 1 => array("file", APP_ROOT . "logs" . DIRECTORY_SEPARATOR . "websocket.log", "a"), 2 => array("file", APP_ROOT . "logs" . DIRECTORY_SEPARATOR . "websocket.error", "a") ); - $webSocketProcess = proc_open($config->getNodeStartupMethod().' ' . APP_ROOT . 'websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port(), $descriptorspec, $pipes); + $webSocketProcess = proc_open($config->getNodeStartupMethod() . ' ' . APP_ROOT . 'websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port() . ' ' . (\eBot\Config\Config::getInstance()->isSSLEnabled() ? 'TRUE': 'FALSE') . ' ' . \eBot\Config\Config::getInstance()->getSSLCertificatePath() . ' ' . \eBot\Config\Config::getInstance()->getSSLKeyPath(), $descriptorspec, $pipes); if (is_resource($webSocketProcess)) { fclose($pipes[0]); usleep(400000); diff --git a/config/config.ini.smp b/config/config.ini.smp index 38404f74..b2ab2741 100644 --- a/config/config.ini.smp +++ b/config/config.ini.smp @@ -14,6 +14,9 @@ MYSQL_BASE = "ebotv3" [Config] BOT_IP = "127.0.0.1" BOT_PORT = 12360 +SSL_ENABLED = false +SSL_CERTIFICATE_PATH = "ssl/cert.pem" +SSL_KEY_PATH = "ssl/key.pem" EXTERNAL_LOG_IP = "" ; use this in case your server isn't binded with the external IP (behind a NAT) MANAGE_PLAYER = 1 DELAY_BUSY_SERVER = 120 @@ -26,7 +29,7 @@ LO3_METHOD = "restart" ; restart or csay or esl KO3_METHOD = "restart" ; restart or csay or esl DEMO_DOWNLOAD = true ; true or false :: whether gotv demos will be downloaded from the gameserver after matchend or not REMIND_RECORD = false ; true will print the 3x "Remember to record your own POV demos if needed!" messages, false will not -DAMAGE_REPORT = true; true will print damage reports at end of round to players, false will not +DAMAGE_REPORT = true ; true will print damage reports at end of round to players, false will not USE_DELAY_END_RECORD = false ; use the tv_delay to record postpone the tv_stoprecord & upload [MAPS] diff --git a/src/eBot/Config/Config.php b/src/eBot/Config/Config.php index 15bf9532..d706dd19 100644 --- a/src/eBot/Config/Config.php +++ b/src/eBot/Config/Config.php @@ -18,7 +18,6 @@ */ class Config extends Singleton { - private $mysql_ip; private $mysql_port; private $mysql_user; @@ -26,6 +25,9 @@ class Config extends Singleton private $mysql_base; private $bot_ip; private $bot_port; + private $sslEnabled; + private $sslCertPath; + private $sslKeyPath; private $messages = array(); private $record_name = "ebot"; private $delay_busy_server = 90; @@ -60,6 +62,9 @@ public function __construct() $this->bot_ip = $config["BOT_IP"]; $this->bot_port = $config["BOT_PORT"]; + $this->sslEnabled = $config["SSL_ENABLED"]; + $this->sslCertPath = $config["SSL_CERTIFICATE_PATH"]; + $this->sslKeyPath = $config["SSL_KEY_PATH"]; $this->delay_busy_server = $config["DELAY_BUSY_SERVER"]; @@ -232,6 +237,39 @@ public function setBot_port($bot_port) $this->bot_port = $bot_port; } + public function isSSLEnabled() + { + return $this->sslEnabled; + } + + public function setSSLEnabled($sslEnabled) + { + $this->sslEnabled = $sslEnabled; + return $this; + } + + public function getSSLCertificatePath() + { + return $this->sslCertPath; + } + + public function setSSLCertificatePath($sslCertificatePath) + { + $this->sslCertPath = $sslCertificatePath; + return $this; + } + + public function getSSLKeyPath() + { + return $this->sslKeyPath; + } + + public function setSSLKeyPath($sslKeyPath) + { + $this->sslKeyPath = $sslKeyPath; + return $this; + } + public function getMessages() { return $this->messages; diff --git a/src/eBot/Match/Match.php b/src/eBot/Match/Match.php index 591581ad..fb797014 100644 --- a/src/eBot/Match/Match.php +++ b/src/eBot/Match/Match.php @@ -592,9 +592,8 @@ public function taskExecute($name) { } elseif ($name == self::STOP_RECORD) { $this->needDelTask = false; $this->addLog("Stopping record and pushing demo..."); -// $this->rcon->send("tv_stoprecord"); if (\eBot\Config\Config::getInstance()->getDemoDownload()) { - $this->rcon->send('tv_stoprecord; ' . 'csay_tv_demo_push "' . $this->currentRecordName . '.dem" "http://' . \eBot\Config\Config::getInstance()->getLogAddressIp() . ':' . \eBot\Config\Config::getInstance()->getBot_port() . '/upload"'); + $this->rcon->send('tv_stoprecord; ' . 'csay_tv_demo_push "' . $this->currentRecordName . '.dem" "' . (\eBot\Config\Config::getInstance()->isSSLEnabled() ? 'https' : 'http') . '://' . \eBot\Config\Config::getInstance()->getLogAddressIp() . ':' . \eBot\Config\Config::getInstance()->getBot_port() . '/upload"'); } else { $this->rcon->send("tv_stoprecord"); } diff --git a/websocket_server.js b/websocket_server.js index 7f311e47..7822937c 100644 --- a/websocket_server.js +++ b/websocket_server.js @@ -1,4 +1,5 @@ var http = require('http'); +var https = require('https'); var formidable = require('formidable'); var archiver = require('archiver'); var fs = require('fs'); @@ -7,6 +8,7 @@ var clientUDP = dgram.createSocket("udp4"); var udp_ip = process.argv[2]; var udp_port = process.argv[3]; +var sslEnabled = process.argv[4] === 'TRUE'; var DEMO_PATH = __dirname + "/demos/"; @@ -14,7 +16,7 @@ String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; }; -var server = http.createServer(function(request, response) { +function requestHandler (request, response) { switch (request.url) { case '/upload': @@ -87,7 +89,16 @@ var server = http.createServer(function(request, response) { response.end(); break; } -}); +} +var server; +if (sslEnabled) { + server = https.createServer({ + key: fs.readFileSync(process.argv[6] || 'ssl/key.pem'), + cert: fs.readFileSync(process.argv[5] ||'ssl/cert.pem') + },requestHandler); +} else { + server = http.createServer(requestHandler); +} fs.exists(DEMO_PATH, function(exists) { if (!exists) {