コード例 #1
0
ファイル: Match.php プロジェクト: heshengjie/eBot-CSGO
 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));
 }
コード例 #2
0
ファイル: bootstrap.php プロジェクト: heshengjie/eBot-CSGO
            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);
}
/*

not done yet

// Checking outgoing connection and IP configuration
if (!($status = file_get_contents("http://www.esport-tools.net/ebot/ping"))) {
    echo '-----------------------------------------------------' . PHP_EOL;
    echo '| Cannot connect to the internet.' . PHP_EOL;
} elseif (\eBot\Config\Config::getInstance()->getBot_ip() != $status) {
    echo '-----------------------------------------------------' . PHP_EOL;
    echo '| Your config\'s IP address differs from your real IP.' . PHP_EOL;
    echo '| Be sure to not use a loopback like "localhost" or "127.0.0.1".' . PHP_EOL;
    echo '| The gameservers sends the serverlog to the eBot IP address.' . PHP_EOL;
    echo '-----------------------------------------------------' . PHP_EOL;
    die();
}
*/
echo '-----------------------------------------------------' . PHP_EOL;
error_reporting(E_ERROR);
\eBot\Application\Application::getInstance()->run();
コード例 #3
0
 public function getWebSocket($room)
 {
     return Application::getInstance()->websocket[$room];
 }