Esempio n. 1
0
 public static function createFromConfigFile()
 {
     Logger::debug("Loading " . APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "messages.ini");
     if (file_exists(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "messages.ini")) {
         $data = parse_ini_file(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "messages.ini", true);
         foreach ($data as $k => $game) {
             MessageManager::getInstance($k);
             foreach ($game["message"] as $message) {
                 if (class_exists($message)) {
                     MessageManager::getInstance($k)->addMessage(new $message());
                 }
             }
             Logger::log(MessageManager::getInstance($k)->count() . " messages loaded for {$k} ");
         }
     }
 }
Esempio n. 2
0
 public function run()
 {
     global $loggerData;
     // Loading Logger instance
     Logger::getInstance();
     Logger::log($this->getName());
     // Initializing database
     $this->initDatabase();
     // Loading eBot configuration
     Logger::log("Loading config");
     Config::getInstance()->scanAdvertising();
     Config::getInstance()->printConfig();
     // Registring components
     Logger::log("Registering MatchManager");
     MatchManager::getInstance();
     Logger::log("Registering Messages");
     MessageManager::createFromConfigFile();
     Logger::log("Registering PluginsManager");
     PluginsManager::getInstance();
     // Starting application
     Logger::log("Starting eBot Application");
     /* try {
        $this->socket = new Socket(Config::getInstance()->getBot_ip(), Config::getInstance()->getBot_port());
        } catch (Exception $ex) {
        Logger::error("Unable to bind socket");
        die();
        } */
     try {
         $this->websocket['match'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/match");
         $this->websocket['match']->open();
         $this->websocket['rcon'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/rcon");
         $this->websocket['rcon']->open();
         $this->websocket['logger'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/logger");
         $this->websocket['logger']->open();
         $this->websocket['livemap'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/livemap");
         $this->websocket['livemap']->open();
         $this->websocket['aliveCheck'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/alive");
         $this->websocket['aliveCheck']->open();
     } catch (Exception $ex) {
         Logger::error("Unable to create Websocket.");
         die;
     }
     PluginsManager::getInstance()->startAll();
     $time = time();
     while (true) {
         $data = "";
         $ip = "";
         $nbMessage = count($loggerData);
         if ($nbMessage > 0) {
             if ($nbMessage > 5) {
                 Logger::log($nbMessage . " in queue!");
             }
             $d = explode("---", $loggerData->shift());
             $ip = array_shift($d);
             $data = implode("---", $d);
             $nbMessage--;
         } else {
             usleep(500);
         }
         //$data = $this->socket->recvfrom($ip);
         if ($data) {
             if (!preg_match("/L+\\s+\\d+\\/\\d+\\/\\d+/", $data)) {
                 if ($data == '__true__') {
                     $this->clientsConnected = true;
                 } elseif ($data == '__false__') {
                     $this->clientsConnected = false;
                 } elseif ($data == '__aliveCheck__') {
                     $this->websocket['aliveCheck']->sendData('__isAlive__');
                 } else {
                     $data = json_decode($data, true);
                     $authkey = \eBot\Manager\MatchManager::getInstance()->getAuthkey($data[1]);
                     $text = \eTools\Utils\Encryption::decrypt($data[0], $authkey, 256);
                     if ($text) {
                         if (preg_match("!^(?<id>\\d+) stopNoRs (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminStopNoRs();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => 'stop', 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) stop (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminStop();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => 'stop', 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) executeCommand (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+) (?<command>.*)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminExecuteCommand($preg["command"]);
                                 if ($reply) {
                                     $send = json_encode(array('id' => $preg["id"], 'content' => $reply));
                                     $this->websocket['rcon']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) passknife (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminPassKnife();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forceknife (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminForceKnife();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forceknifeend (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminForceKnifeEnd();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forcestart (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminForceStart();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) stopback (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminStopBack();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) pauseunpause (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminPauseUnpause();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) fixsides (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminFixSides();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) streamerready (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminStreamerReady();
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) goBackRounds (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+) (?<round>\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminGoBackRounds($preg['round']);
                                 if ($reply) {
                                     $send = json_encode(array('message' => 'button', 'content' => $match->getStatus(), 'id' => $preg["id"]));
                                     $this->websocket['match']->sendData($send);
                                 }
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) skipmap (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManager::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $reply = $match->adminSkipMap();
                                 /* if ($reply) {
                                    $send = json_encode(array('message' => 'button', 'content' => 'stop', 'id' => $preg["id"]));
                                    $this->websocket['match']->sendData($send);
                                    } */
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } else {
                             Logger::error($text . " not managed");
                         }
                     }
                 }
             } else {
                 $line = substr($data, 7);
                 if (\eBot\Manager\MatchManager::getInstance()->getMatch($ip)) {
                     file_put_contents(APP_ROOT . "/logs/{$ip}", $line, FILE_APPEND);
                     $line = trim(substr($line, 23));
                     \eBot\Manager\MatchManager::getInstance()->getMatch($ip)->processMessage($line);
                     $line = substr($data, 7, strlen($data) - 8);
                     file_put_contents(Logger::getInstance()->getLogPathAdmin() . "/logs_" . \eBot\Manager\MatchManager::getInstance()->getMatch($ip)->getMatchId() . ".log", $line, FILE_APPEND);
                     if ($this->clientsConnected) {
                         $send = json_encode(array('id' => \eBot\Manager\MatchManager::getInstance()->getMatch($ip)->getMatchId(), 'content' => $line));
                         $this->websocket['logger']->sendData($send);
                     }
                 }
             }
         }
         if ($time + 5 < time()) {
             $time = time();
             $this->websocket['match']->send(json_encode(array("message" => "ping")));
             $this->websocket['logger']->send(json_encode(array("message" => "ping")));
             $this->websocket['rcon']->send(json_encode(array("message" => "ping")));
             $this->websocket['livemap']->send(json_encode(array("message" => "ping")));
             $this->websocket['aliveCheck']->send(json_encode(array("message" => "ping")));
         }
         if ($nbMessage < 100) {
             \eBot\Manager\MatchManager::getInstance()->sendPub();
             \eTools\Task\TaskManager::getInstance()->runTask();
         }
     }
 }
Esempio n. 3
0
 public function run()
 {
     // Loading Logger instance
     Logger::getInstance();
     Logger::getInstance()->setName("#0");
     Logger::log($this->getName());
     // Loading eBot configuration
     Logger::log("Loading config");
     Config::getInstance()->printConfig();
     // Initializing database
     $this->initDatabase();
     // Registring components
     Logger::log("Registering MatchManagerServer");
     MatchManagerServer::getInstance();
     Logger::log("Registering Messages");
     MessageManager::createFromConfigFile();
     Logger::log("Registering PluginsManager");
     PluginsManager::getInstance();
     Logger::log("Spawning instance");
     $config = parse_ini_file(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "config.server.ini");
     $instance = 1;
     if (is_numeric($config['NUMBER'])) {
         $instance = $config['NUMBER'];
     }
     for ($i = 1; $i <= $instance; $i++) {
         $descriptorspec = array(0 => STDIN, 1 => STDOUT, 2 => STDOUT);
         $process = proc_open(PHP_BINDIR . '/php ' . EBOT_DIRECTORY . '/bootstrap_client.php ' . $i, $descriptorspec, $pipes);
         $status = proc_get_status($process);
         $this->instance[] = $process;
         Logger::log("Spawned instance " . $status['pid']);
     }
     // Starting application
     Logger::log("Starting eBot Application");
     try {
         $this->socket = new Socket(Config::getInstance()->getBot_ip(), Config::getInstance()->getBot_port());
     } catch (Exception $ex) {
         Logger::error("Unable to bind socket");
         die;
     }
     try {
         $this->websocket['match'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/match");
         $this->websocket['match']->open();
         $this->websocket['rcon'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/rcon");
         $this->websocket['rcon']->open();
         $this->websocket['logger'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/logger");
         $this->websocket['logger']->open();
         $this->websocket['livemap'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/livemap");
         $this->websocket['livemap']->open();
         $this->websocket['aliveCheck'] = new \WebSocket("ws://" . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . "/alive");
         $this->websocket['aliveCheck']->open();
     } catch (Exception $ex) {
         Logger::error("Unable to create Websocket.");
         die;
     }
     PluginsManager::getInstance()->startAll();
     $time = time();
     while (true) {
         $data = $this->socket->recvfrom($ip);
         if ($data) {
             if (!preg_match("/L+\\s+\\d+\\/\\d+\\/\\d+/", $data)) {
                 if ($data == '__true__') {
                     $this->clientsConnected = true;
                     for ($i = 1; $i <= count($this->instance); $i++) {
                         $this->socket->sendto($data, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $i);
                     }
                 } elseif ($data == '__false__') {
                     $this->clientsConnected = false;
                     for ($i = 1; $i <= count($this->instance); $i++) {
                         $this->socket->sendto($data, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $i);
                     }
                 } elseif ($data == '__aliveCheck__') {
                     $this->websocket['aliveCheck']->sendData('__isAlive__');
                     for ($i = 1; $i <= count($this->instance); $i++) {
                         $this->socket->sendto($data, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $i);
                     }
                 } elseif (preg_match("!^removeMatch (?<id>\\d+)\$!", $data, $preg)) {
                     Logger::log("Removing " . $preg['id']);
                     MatchManagerServer::getInstance()->removeMatch($preg['id']);
                 } else {
                     $origData = $data;
                     $data = json_decode($data, true);
                     $authkey = \eBot\Manager\MatchManagerServer::getInstance()->getAuthkey($data[1]);
                     $text = \eTools\Utils\Encryption::decrypt($data[0], $authkey, 256);
                     if ($text) {
                         if (preg_match("!^(?<id>\\d+) stopNoRs (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) stop (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) executeCommand (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+) (?<command>.*)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) passknife (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forceknife (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forceknifeend (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) forcestart (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) stopback (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) pauseunpause (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) fixsides (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) streamerready (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } elseif (preg_match("!^(?<id>\\d+) goBackRounds (?<ip>\\d+\\.\\d+\\.\\d+\\.\\d+\\:\\d+) (?<round>\\d+)\$!", $text, $preg)) {
                             $match = \eBot\Manager\MatchManagerServer::getInstance()->getMatch($preg["ip"]);
                             if ($match) {
                                 $this->socket->sendto($origData, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $match['i']);
                             } else {
                                 Logger::error($preg["ip"] . " is not managed !");
                             }
                         } else {
                             Logger::error($text . " not managed");
                         }
                     }
                 }
             }
         }
         if ($time + 5 < time()) {
             $time = time();
             $this->websocket['match']->send(json_encode(array("message" => "ping")));
             $this->websocket['logger']->send(json_encode(array("message" => "ping")));
             $this->websocket['rcon']->send(json_encode(array("message" => "ping")));
             $this->websocket['livemap']->send(json_encode(array("message" => "ping")));
             $this->websocket['aliveCheck']->send(json_encode(array("message" => "ping")));
         }
         \eTools\Task\TaskManager::getInstance()->runTask();
     }
 }
Esempio n. 4
0
 public function __construct($match_id, $server_ip, $rcon)
 {
     Logger::debug("Registring MessageManager");
     $this->messageManager = \eBot\Manager\MessageManager::getInstance("CSGO");
     Logger::debug("Creating match #" . $match_id . " on {$server_ip}");
     $this->match_id = $match_id;
     $this->server_ip = $server_ip;
     $query = \mysql_query("SELECT * FROM `matchs` WHERE id = '" . $match_id . "'");
     if (!$query) {
         throw new MatchException();
     }
     $this->matchData = \mysql_fetch_assoc($query);
     // SETTING TEAMNAME AND FLAG
     $teama_details = $this->getTeamDetails($this->matchData["team_a"], "a");
     $this->teamAName = $teama_details['name'];
     $this->teamAFlag = $teama_details['flag'];
     $teamb_details = $this->getTeamDetails($this->matchData["team_b"], "b");
     $this->teamBName = $teamb_details['name'];
     $this->teamBFlag = $teamb_details['flag'];
     $this->season_id = $this->matchData["season_id"];
     $this->addMatchLog("----------- Creating log file -----------", false, false);
     $this->addMatchLog("- Match Parameter", false, false);
     $this->addMatchLog("- Match ID: " . $this->match_id, false, false);
     $this->addMatchLog("- Teams: " . $this->teamAName . " - " . $this->teamBName, false, false);
     $this->addMatchLog("- MaxRound: " . $this->matchData["max_round"], false, false);
     $this->addMatchLog("- Overtime: " . $this->matchData["config_ot"] ? "yes (money: " . $this->matchData['overtime_startmoney'] . ", round: " . $this->matchData['overtime_max_round'] . ")" : "no", false, false);
     // Get Websocket
     $this->websocket['match'] = \eBot\Application\Application::getInstance()->getWebSocket('match');
     $this->websocket['livemap'] = \eBot\Application\Application::getInstance()->getWebSocket('livemap');
     $this->websocket['logger'] = \eBot\Application\Application::getInstance()->getWebSocket('logger');
     $ip = explode(":", $this->server_ip);
     try {
         $this->rcon = new Rcon($ip[0], $ip[1], $rcon);
         $this->rconPassword = $rcon;
         Logger::log("RCON init ok");
         $this->rcon->send("log on; mp_logdetail 0; logaddress_del " . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port() . ";logaddress_add " . \eBot\Config\Config::getInstance()->getBot_ip() . ":" . \eBot\Config\Config::getInstance()->getBot_port());
         $this->addMatchLog("- RCON connection OK", true, false);
     } catch (\Exception $ex) {
         $this->needDel = true;
         if (!is_numeric(\eBot\Manager\MatchManager::getInstance()->getRetry($this->match_id))) {
             if ($this->status == 1) {
                 \mysql_query("UPDATE `matchs` SET `enable` = 0, `auto_start` = 0, `status` = 0 WHERE `id` = '" . $this->match_id . "'");
             } else {
                 \mysql_query("UPDATE `matchs` SET `enable` = 0, `auto_start` = 0 WHERE `id` = '" . $this->match_id . "'");
             }
         } else {
             if (\eBot\Manager\MatchManager::getInstance()->getRetry($this->match_id) > 3) {
                 if ($this->status == 1) {
                     \mysql_query("UPDATE `matchs` SET `enable` = 0, `auto_start` = 0, `status` = 0 WHERE `id` = '" . $this->match_id . "'");
                 } else {
                     \mysql_query("UPDATE `matchs` SET `enable` = 0, `auto_start` = 0 WHERE `id` = '" . $this->match_id . "'");
                 }
             } else {
                 $this->addLog("Next retry (" . \eBot\Manager\MatchManager::getInstance()->getRetry($this->match_id) . "/3)");
                 \eBot\Manager\MatchManager::getInstance()->setRetry($this->match_id, \eBot\Manager\MatchManager::getInstance()->getRetry($this->match_id) + 1);
                 \eBot\Manager\MatchManager::getInstance()->delayServer($this->server_ip, 5);
             }
         }
         $this->websocket['match']->sendData(json_encode(array('message' => 'button', 'content' => 'stop', 'id' => $this->match_id)));
         Logger::error("Rcon failed - " . $ex->getMessage());
         Logger::error("Match destructed.");
         $this->addMatchLog("RCON Failed - " . $ex->getMessage(), false, false);
         throw new MatchException();
     }
     TaskManager::getInstance()->addTask(new Task($this, self::TEST_RCON, microtime(true) + 10));
     // CSay Detection
     try {
         $text = $this->rcon->send("csay_version");
         if (preg_match('!"csay_version" = "(.*)"!', $text, $match)) {
             $this->addLog("CSay version " . $match[1]);
             $this->pluginCsay = true;
             $this->pluginPrintPlayers = true;
             $this->pluginSwitch = true;
             $this->addMatchLog("- CSay version " . $match[1], false, false);
         }
     } catch (\Exception $ex) {
         Logger::error("Error while getting plugins information");
     }
     // ESL Plugin Detection
     try {
         $text = $this->rcon->send("esl_version");
         if (preg_match('!"esl_version" = "(.*)"!', $text, $match)) {
             $this->addLog("ESL Plugin version " . $match[1]);
             $this->pluginESL = true;
             $this->addMatchLog("- ESL Plugin version " . $match[1], false, false);
         }
     } catch (\Exception $ex) {
         Logger::error("Error while getting plugins information");
     }
     $this->config_full_score = $this->matchData["config_full_score"];
     $this->config_kniferound = $this->matchData["config_knife_round"];
     $this->config_switch_auto = $this->matchData["config_switch_auto"];
     $this->config_ot = $this->matchData["config_ot"];
     if ($this->config_ot) {
         $this->ot_startmoney = $this->matchData["overtime_startmoney"];
         $this->ot_maxround = $this->matchData["overtime_max_round"];
     }
     $this->config_streamer = $this->matchData["config_streamer"];
     $this->maxRound = $this->matchData["max_round"];
     $this->oldMaxround = $this->maxRound;
     $this->rules = $this->matchData["rules"];
     $this->status = $this->matchData["status"];
     $this->isPaused = $this->matchData['is_paused'] == 1;
     Logger::debug("Match config loaded - Printing configuration");
     $this->addLog("Match configuration" . " :: Full Score: " . ($this->config_full_score ? "yes" : "no") . " :: Switch Auto: " . ($this->config_switch_auto ? "yes" : "no") . " :: Over Time: " . ($this->config_ot ? "yes" : "no") . " :: KnifeRound: " . ($this->config_kniferound ? "yes" : "no"));
     $this->addMatchLog("- Match configuration" . " :: Full Score: " . ($this->config_full_score ? "yes" : "no") . " :: Switch Auto: " . ($this->config_switch_auto ? "yes" : "no") . " :: Over Time: " . ($this->config_ot ? "yes" : "no") . " :: KnifeRound: " . ($this->config_kniferound ? "yes" : "no"), false, true);
     $this->addLog("MaxRound: " . $this->maxRound . " :: Rules: " . $this->rules);
     // Map Start
     Logger::debug("Loading maps");
     $query = \mysql_query("SELECT * FROM `maps` WHERE match_id = '" . $match_id . "'");
     if (!$query) {
         throw new MatchException();
     }
     while ($data = \mysql_fetch_assoc($query)) {
         $this->maps[$data["id"]] = new Map($data);
         $this->maps[$data["id"]]->setNbMaxRound($this->maxRound);
     }
     // Fixing for maxround in OT
     if ($this->getStatus() >= self::STATUS_WU_OT_1_SIDE) {
         $this->maxRound = $this->ot_maxround;
     }
     if ($this->matchData["current_map"] == null) {
         Logger::debug("No map is currently playing, picking one (based on default)");
         foreach ($this->maps as &$map) {
             if ($map->getStatus() == Map::STATUS_NOT_STARTED && $map->getMapsFor() == "default") {
                 $this->currentMap = $map;
                 $this->matchData["current_map"] = $map->getMapId();
                 Logger::debug("Map #" . $map->getMapId() . " selected");
                 mysql_query("UPDATE `matchs` SET current_map='" . $map->getMapId() . "' WHERE id='" . $this->match_id . "'");
                 break;
             }
         }
     } else {
         if ($this->maps[$this->matchData["current_map"]]) {
             $this->currentMap = $this->maps[$this->matchData["current_map"]];
         } else {
             $this->addLog("Can't find the map #" . $this->matchData["current_map"], Logger::ERROR);
             throw new MatchException();
         }
     }
     if ($this->currentMap == null) {
         $this->addLog("No map found, exiting matchs", Logger::ERROR);
         mysql_query("UPDATE `matchs` SET enable='0', status='" . self::STATUS_END_MATCH . "' WHERE id='" . $this->match_id . "'");
         throw new MatchException();
     }
     $this->addLog("Maps selected: #" . $this->currentMap->getMapId() . " - " . $this->currentMap->getMapName() . " - " . $this->currentMap->getStatusText());
     if ($this->currentMap->getMapName() != "tba") {
         $this->mapIsEngaged = true;
         $this->addLog("Setting map engaged");
     } else {
         $this->mapIsEngaged = false;
         $this->addLog("Setting veto mode");
     }
     if ($this->getStatus() == self::STATUS_STARTING) {
         if ($this->currentMap->getStatus() == Map::STATUS_NOT_STARTED || $this->currentMap->getStatus() == Map::STATUS_STARTING) {
             if ($this->config_kniferound) {
                 Logger::debug("Setting need knife round on map");
                 $this->currentMap->setNeedKnifeRound(true);
             }
         }
         if ($this->currentMap->getMapName() != "tba") {
             Logger::debug("Schedule task for first map");
             TaskManager::getInstance()->addTask(new Task($this, self::TASK_ENGAGE_MAP, microtime(true) + 1));
         } else {
             if ($this->config_kniferound) {
                 $this->setStatus(self::STATUS_WU_KNIFE, true);
                 $this->currentMap->setStatus(Map::STATUS_WU_KNIFE, true);
             } else {
                 $this->setStatus(self::STATUS_WU_1_SIDE, true);
                 $this->currentMap->setStatus(Map::STATUS_WU_1_SIDE, true);
             }
         }
     } else {
         if ($this->currentMap->getStatus() == Map::STATUS_NOT_STARTED || $this->currentMap->getStatus() == Map::STATUS_STARTING) {
             if ($this->currentMap->getMapName() != "tba") {
                 Logger::debug("Current map is not started/starting, engaging map");
                 TaskManager::getInstance()->addTask(new Task($this, self::TASK_ENGAGE_MAP, microtime(true) + 1));
             } else {
                 if ($this->config_kniferound) {
                     $this->setStatus(self::STATUS_WU_KNIFE, true);
                     $this->currentMap->setStatus(Map::STATUS_WU_KNIFE, true);
                 } else {
                     $this->setStatus(self::STATUS_WU_1_SIDE, true);
                     $this->currentMap->setStatus(Map::STATUS_WU_1_SIDE, true);
                 }
             }
         } else {
             Logger::debug("Restore score");
         }
     }
     TaskManager::getInstance()->addTask(new Task($this, self::CHANGE_HOSTNAME, microtime(true) + 5));
     // Setting side for maps
     if ($this->currentMap->getCurrentSide() == "ct") {
         $this->side['team_a'] = "ct";
         $this->side['team_b'] = "t";
     } else {
         $this->side['team_a'] = "t";
         $this->side['team_b'] = "ct";
     }
     $this->websocket['match']->sendData(json_encode(array('message' => 'teams', 'teamA' => $this->side['team_a'], 'teamB' => $this->side['team_b'], 'id' => $this->match_id)));
     // Calculating scores
     $this->currentMap->calculScores();
     $this->score["team_a"] = $this->currentMap->getScore1();
     $this->score["team_b"] = $this->currentMap->getScore2();
     @mysql_query("UPDATE `matchs` SET score_a = '" . $this->score["team_a"] . "', score_b ='" . $this->score["team_b"] . "' WHERE id='" . $this->match_id . "'");
     // Setting nb OverTime
     $this->nbOT = $this->currentMap->getNbOt();
     // This case happens only when the bot shutdown and restart at this status
     if ($this->currentMap->getStatus() == Map::STATUS_END_KNIFE) {
         $this->addLog("Setting round to knife round, because was waiting end knife");
         $this->currentMap->setStatus(Map::STATUS_WU_KNIFE, true);
         $this->setStatus(Map::STATUS_WU_KNIFE, true);
     }
     // Getting all players
     $this->recupStatus();
     // Setting server password
     if ($this->matchData["config_password"] != "") {
         $this->rcon->send("sv_password \"" . $this->matchData["config_password"] . "\"");
     }
     $this->addMatchLog("----------- End match loading -----------", false, false);
     if ($this->getStatus() <= self::STATUS_WU_1_SIDE) {
         $this->sendTeamNames();
     }
     if ($this->matchData["ingame_enable"] != null && !$this->matchData["ingame_enable"]) {
         $this->addLog("Setting match not enabled");
         $this->enable = false;
     }
     if ($this->getStatus() > self::STATUS_WU_1_SIDE) {
         $this->streamerReady = true;
     }
     // Setting nbMaxRound for sided score
     if ($this->getStatus() > self::STATUS_WU_OT_1_SIDE && $this->config_ot) {
         $this->currentMap->setNbMaxRound($this->ot_maxround);
     }
     // Sending roundbackup format file
     $this->rcon->send("mp_backup_round_file \"ebot_" . $this->match_id . "\"");
     TaskManager::getInstance()->addTask(new Task($this, self::CHANGE_HOSTNAME, microtime(true) + 60));
 }