Ejemplo n.º 1
0
 private function check()
 {
     Logger::debug("Checking for new match (current matchs: " . count($this->matchs) . ")");
     $sql = mysql_query("SELECT m.team_a_name as team_a_name, m.team_b_name as team_b_name, m.id as match_id, m.config_authkey as config_authkey, t_a.name as team_a, t_b.name as team_b, s.id as server_id, s.ip as server_ip, s.rcon as server_rcon FROM `matchs` m LEFT JOIN `servers` s ON s.id = m.server_id LEFT JOIN `teams` t_a ON t_a.id = m.team_a LEFT JOIN `teams` t_b ON t_b.id = m.team_b WHERE m.`status` >= " . Match::STATUS_STARTING . " AND m.`status` < " . Match::STATUS_END_MATCH . " AND m.`enable` = 1") or die(mysql_error());
     while ($req = mysql_fetch_assoc($sql)) {
         if (!@$this->matchs[$req['server_ip']]) {
             try {
                 $teamA = $this->getTeamDetails($req['team_a'], 'a', $req);
                 $teamB = $this->getTeamDetails($req['team_a'], 'b', $req);
                 Logger::log("New match detected - " . $teamA['name'] . " vs " . $teamB['name'] . " on " . $req['server_ip']);
                 $this->newMatch($req["match_id"], $req['server_ip'], $req['server_rcon'], $req['config_authkey']);
             } catch (MatchException $ex) {
                 Logger::error("Error while creating the match");
                 mysql_query("UPDATE `matchs` SET enable=0 WHERE id = '" . $req['match_id'] . "'") or die(mysql_error());
             } catch (\Exception $ex) {
                 if ($ex->getMessage() == "SERVER_BUSY") {
                     Logger::error($req["server_ip"] . " is busy for " . (time() - $this->busyServers[$req['server_ip']]));
                 } elseif ($ex->getMessage() == "MATCH_ALREADY_PLAY_ON_THIS_SERVER") {
                     Logger::error("A match is already playing on " . $req["server_ip"]);
                 }
             }
         }
     }
     TaskManager::getInstance()->addTask(new Task($this, self::CHECK_NEW_MATCH, microtime(true) + 3), true);
     Logger::debug("End checking (current matchs: " . count($this->matchs) . ")");
 }
Ejemplo 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();
         }
     }
 }
Ejemplo 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();
     }
 }
Ejemplo n.º 4
0
 public function adminGoBackRounds($round)
 {
     $this->enable = false;
     $sql = mysql_query("SELECT * FROM  round_summary WHERE match_id = '" . $this->match_id . "' AND map_id = '" . $this->currentMap->getMapId() . "' AND round_id = {$round}");
     $req = mysql_fetch_array($sql);
     $backup = $req['backup_file_name'];
     $this->addLog("Admin backup round {$round}");
     $this->addLog("Backup file " . $backup);
     $this->stop["ct"] = false;
     $this->stop["t"] = false;
     if ($this->isPaused) {
         if (\eBot\Config\Config::getInstance()->getPauseMethod() == "nextRound") {
             $this->rcon->send("mp_unpause_match");
         } else {
             $this->rcon->send("pause");
         }
         $this->isPaused = false;
         $this->addLog("Disabling pause");
         \mysql_query("UPDATE `matchs` SET `is_paused` = '0' WHERE `id` = '" . $this->match_id . "'");
         $this->websocket['match']->sendData(json_encode(array('message' => 'status', 'content' => 'is_unpaused', 'id' => $this->match_id)));
     }
     $this->rcon->send("mp_unpause_match");
     $this->score["team_a"] = $req['score_a'];
     $this->score["team_b"] = $req['score_b'];
     @mysql_query("UPDATE `matchs` SET score_a = '" . $this->score["team_a"] . "', score_b ='" . $this->score["team_b"] . "' WHERE id='" . $this->match_id . "'");
     // To check with overtime
     if ($this->score["team_a"] + $this->score["team_b"] < $this->matchData["max_round"]) {
         $score = $this->currentMap->getCurrentScore();
         if ($score != null) {
             $score->setScore1Side1($this->score['team_a']);
             $score->setScore2Side1($this->score['team_b']);
             $score->setScore1Side2(0);
             $score->setScore2Side2(0);
             $score->saveScore();
         }
         $this->currentMap->calculScores();
     } else {
         $score = $this->currentMap->getCurrentScore();
         if ($score != null) {
             $score->setScore1Side2($this->score['team_a'] - $score->getScore1Side1());
             $score->setScore2Side2($this->score['team_b'] - $score->getScore2Side1());
             $score->saveScore();
         }
         $this->currentMap->calculScores();
     }
     // Sending roundbackup format file
     $this->rcon->send("mp_backup_round_file \"ebot_" . $this->match_id . "\"");
     // Prevent the halftime pausetimer
     $this->rcon->send("mp_halftime_pausetimer 0");
     // Sending restore
     $this->rcon->send("mp_backup_restore_load_file " . $backup);
     // Prevent a bug for double stop
     $this->rcon->send("mp_backup_round_file_last " . $backup);
     foreach ($this->players as &$player) {
         $player->restoreSnapshot($this->getNbRound() - 1);
     }
     // Determine status
     $status = false;
     $total = $this->score["team_a"] + $this->score["team_b"];
     if ($total < $this->matchData["max_round"]) {
         $status = self::STATUS_FIRST_SIDE;
         $statusMap = Map::STATUS_FIRST_SIDE;
     } elseif ($total < $this->matchData["max_round"] * 2) {
         $status = self::STATUS_SECOND_SIDE;
         $statusMap = Map::STATUS_SECOND_SIDE;
     } else {
         if ($this->config_ot) {
             $total -= $this->matchData["max_round"] * 2;
             $total_rest = $total % $this->ot_maxround * 2;
             if ($total_rest < $this->ot_maxround) {
                 $status = self::STATUS_OT_FIRST_SIDE;
                 $statusMap = Map::STATUS_OT_FIRST_SIDE;
             } else {
                 $status = self::STATUS_OT_SECOND_SIDE;
                 $statusMap = Map::STATUS_OT_SECOND_SIDE;
             }
         }
     }
     if ($status && $this->getStatus() != $status) {
         $this->addLog("Setting match to another status: " . $status);
         switch ($this->getStatus()) {
             case self::STATUS_SECOND_SIDE:
                 if ($status == self::STATUS_FIRST_SIDE) {
                     $this->addLog("Swapping teams !");
                     $this->swapSides();
                 }
                 break;
             case self::STATUS_OT_FIRST_SIDE:
                 if ($status == self::STATUS_FIRST_SIDE) {
                     $this->addLog("Swapping teams !");
                     $this->swapSides();
                 }
                 break;
             case self::STATUS_OT_SECOND_SIDE:
                 if ($status == self::STATUS_OT_FIRST_SIDE) {
                     $this->addLog("Swapping teams !");
                     $this->swapSides();
                 }
                 if ($status == self::STATUS_SECOND_SIDE) {
                     $this->addLog("Swapping teams !");
                     $this->swapSides();
                 }
                 break;
         }
         $this->setStatus($status, true);
         $this->currentMap->setStatus($statusMap, true);
     }
     $this->say("Round restored, going live !");
     \mysql_query("UPDATE `matchs` SET ingame_enable = 1 WHERE id='" . $this->match_id . "'") or $this->addLog("Can't update ingame_enable", Logger::ERROR);
     TaskManager::getInstance()->addTask(new Task($this, self::SET_LIVE, microtime(true) + 2));
     return true;
 }
Ejemplo n.º 5
0
 public function taskExecute($name)
 {
     if ($name == "check") {
         mysql_query("SELECT 1;");
         TaskManager::getInstance()->addTask(new Task($this, self::CHECK_SQL, microtime(true) + 5), true);
     }
 }