private function newMatch($match_id, $ip, $rcon, $authkey)
 {
     if (@$this->busyServers[$ip]) {
         if (time() > $this->busyServers[$ip]) {
             unset($this->busyServers[$ip]);
         }
     }
     if (!@$this->busyServers[$ip]) {
         if (!@$this->matchs[$ip]) {
             $this->authkeys[$ip] = $authkey;
             $this->matchs[$ip] = array("id" => $match_id, "i" => $this->chooseInstance());
             $socket = \eBot\Application\ApplicationServer::getInstance()->getSocket();
             $socket->sendTo("addMatch {$match_id}", \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Config\Config::getInstance()->getBot_port() + $this->matchs[$ip]['i']);
             Logger::log("Delegating match {$match_id} to instance #" . $this->matchs[$ip]['i']);
         } else {
             throw new \Exception("MATCH_ALREADY_PLAY_ON_THIS_SERVER");
         }
     } else {
         throw new \Exception("SERVER_BUSY");
     }
 }
Exemple #2
0
 private function initDatabase()
 {
     $conn = @\mysql_connect(Config::getInstance()->getMysql_ip(), Config::getInstance()->getMysql_user(), Config::getInstance()->getMysql_pass());
     if (!$conn) {
         Logger::error("Can't login into database " . Config::getInstance()->getMysql_user() . "@" . Config::getInstance()->getMysql_ip());
         die(1);
     }
     if (!\mysql_select_db(Config::getInstance()->getMysql_base(), $conn)) {
         Logger::error("Can't select database " . Config::getInstance()->getMysql_base());
         die(1);
     }
 }
Exemple #3
0
    if (PHP_OS == "Linux") {
        proc_terminate($webSocketProcess, 9);
    }
    $error = error_get_last();
    if (!empty($error)) {
        $info = "[SHUTDOWN] date: " . date("d.m.y H:m", time()) . " file: " . $error['file'] . " | ln: " . $error['line'] . " | msg: " . $error['message'] . PHP_EOL;
        file_put_contents(APP_ROOT . 'logs' . DIRECTORY_SEPARATOR . 'error.log', $info, FILE_APPEND);
    }
}
echo "| Registerung Shutdown function !" . PHP_EOL;
register_shutdown_function('handleShutdown');
// Starting ebot Websocket Server
if (PHP_OS == "Linux") {
    echo "| Starting eBot Websocket-Server !" . PHP_EOL;
    $descriptorspec = array(0 => array("pipe", "r"), 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('node ' . APP_ROOT . 'websocket_server.js ' . \eBot\Config\Config::getInstance()->getBot_ip() . ' ' . \eBot\Config\Config::getInstance()->getBot_port(), $descriptorspec, $pipes);
    if (is_resource($webSocketProcess)) {
        fclose($pipes[0]);
        usleep(400000);
        $status = proc_get_status($webSocketProcess);
        if (!$status['running']) {
            echo '| WebSocket server crashed' . PHP_EOL;
            echo '-----------------------------------------------------' . PHP_EOL;
            die;
        }
        echo "| WebSocket has been started" . PHP_EOL;
    }
} else {
    echo "| You are under windows, please run websocket_server.bat before starting ebot" . PHP_EOL;
    sleep(5);
}
Exemple #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;
 }
Exemple #5
0
    {
        $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
        if ($socket) {
            if (socket_bind($socket, $this->botIp, $this->botPort)) {
            } else {
                echo "can't bind " . $this->botIp . ":" . $this->botPort . "\n";
                return;
            }
        } else {
            echo "can't bind " . $this->botIp . ":" . $this->botPort . "\n";
            return;
        }
        while (true) {
            $data = "";
            $int = @socket_recvfrom($socket, $line, 1500, 0, $from, $port);
            if ($int) {
                $ip = $from . ":" . $port;
                $data = $line;
            } else {
                usleep(1000);
            }
            if ($data) {
                $this->shared_array[] = $ip . "---" . $data;
            }
        }
    }
}
$config = \eBot\Config\Config::getInstance();
$loggerData = new LoggerArray();
$thread = new LogReceiver($loggerData, $config->getBot_ip(), $config->getBot_port());
\eBot\Application\Application::getInstance()->run();
Exemple #6
0
 public function delayServer($ip, $delay = null)
 {
     if (!@$this->busyServers[$ip]) {
         if ($delay == null) {
             $delay = \eBot\Config\Config::getInstance()->getDelay_busy_server();
         }
         $this->busyServers[$ip] = time() + $delay;
         Logger::log("Delay {$ip} for {$delay} seconds");
     }
 }
 private function newMatch($match_id, $ip, $rcon, $authkey)
 {
     if (@$this->busyServers[$ip]) {
         if (time() > $this->busyServers[$ip]) {
             unset($this->busyServers[$ip]);
         }
     }
     if (!@$this->busyServers[$ip]) {
         if (!@$this->matchs[$ip]) {
             $this->matchs[$ip] = new Match($match_id, $ip, $rcon);
             $this->authkeys[$ip] = $authkey;
         } else {
             $socket = \eBot\Application\ApplicationClient::getInstance()->getSocket();
             $socket->sendTo("removeMatch " . $match_id, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Application\ApplicationClient::getInstance()->getPortMain());
             throw new \Exception("MATCH_ALREADY_PLAY_ON_THIS_SERVER");
         }
     } else {
         $socket = \eBot\Application\ApplicationClient::getInstance()->getSocket();
         $socket->sendTo("removeMatch " . $match_id, \eBot\Config\Config::getInstance()->getBot_ip(), \eBot\Application\ApplicationClient::getInstance()->getPortMain());
         throw new \Exception("SERVER_BUSY");
     }
 }