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) . ")"); }
public function dispatchEvent(Event $event) { Logger::debug("Dispatching event " . get_class($event)); if (@$this->listeners[get_class($event)]) { foreach ($this->listeners[get_class($event)] as $plugin) { try { $plugin->onEvent($event); } catch (\Exception $ex) { Logger::error("Error while executing " . get_class($event) . " on " . get_class($plugin)); } } } }
public function send($cmd) { if ($this->server != null) { if ($this->status) { try { return $this->server->rconExec($cmd); } catch (\Exception $e) { Logger::error("Error while doing {$cmd} " . $e->getMessage()); return false; } } } return false; }
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); } }
public function __call($name, $arguments) { \eTools\Utils\Logger::error("Call undefined method {$name} " . print_r($arguments, true)); }
public function setCurrentSide($current_side, $save = false) { if ($current_side == "ct" || $current_side == "t") { $this->current_side = $current_side; if ($save) { mysql_query("UPDATE `maps` SET current_side='" . $current_side . "' WHERE id='" . $this->map_id . "'") or Logger::error("Error while updating current side " . mysql_error()); } } }
public function adminSkipMap() { $backupMap = $this->currentMap; $this->currentMap = null; if ($backupMap->getMapsFor() == "team1") { $mapFor = "team2"; } elseif ($backupMap->getMapsFor() == "team2") { $mapFor = "default"; } foreach ($this->maps as $map) { if ($map->getMapsFor() == $mapFor) { if ($map->getStatus() == Map::STATUS_NOT_STARTED) { $this->currentMap = $map; break; } } } foreach ($this->maps as $map) { if ($map->getStatus() == Map::STATUS_NOT_STARTED) { if ($map->getMapsFor() == $mapFor) { $this->currentMap = $map; break; } } } if ($this->currentMap != null) { $this->currentMap->setStatus(Map::STATUS_STARTING, true); $this->setStatus(self::STATUS_STARTING, true); \mysql_query("UPDATE `matchs` SET `current_map` = '" . $this->currentMap->getMapId() . "' WHERE `id` = '" . $this->match_id . "'"); Logger::debug("Setting need knife round on map"); $this->currentMap->setNeedKnifeRound(true); $this->nbOT = 0; $this->score["team_a"] = 0; $this->score["team_b"] = 0; $this->addLog("Engaging next map " . $this->currentMap->getMapName()); $this->addMatchLog("Engaging next map " . $this->currentMap->getMapName()); $time = microtime(true); $this->timeEngageMap = $time; $this->addLog("Skipping Map"); TaskManager::getInstance()->addTask(new Task($this, self::TASK_ENGAGE_MAP, $time)); } else { $this->setStatus(self::STATUS_END_MATCH, true); Logger::error("Not map found"); $this->addLog("Match is closed"); } return true; }
public function snapshot($round) { @\mysql_query("DELETE FROM players_snapshot WHERE player_id = '" . $this->mysql_id . "' AND round_id='" . $round . "'"); \mysql_query("INSERT INTO players_snapshot \r\n (`player_id`,`nb_kill`,`death`,`assist`,`point`,`hs`,`defuse`,`bombe`,`tk`,`nb1`,`nb2`,`nb3`,`nb4`,`nb5`,`nb1kill`,`nb2kill`,`nb3kill`,`nb4kill`,`nb5kill`,`firstkill`,`round_id`,`created_at`,`updated_at`)\r\n VALUES\r\n ({$this->mysql_id}, {$this->kill}, {$this->death}, {$this->assist}, {$this->point}, {$this->hs}, {$this->defuse}, {$this->bombe}, {$this->tk}, {$this->v1}, {$this->v2}, {$this->v3}, {$this->v4}, {$this->v5}, {$this->k1}, {$this->k2}, {$this->k3}, {$this->k4}, {$this->k5}, {$this->firstKill}, {$round}, NOW(), NOW())") or Logger::error("Error while snapshoting"); }
public function engageMatch($id) { $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 AND m.id = " . $id) 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"]); } } } } }
public function stopAll() { foreach ($this->plugins as $plugin) { try { Logger::debug("Starting plugin " . get_class($plugin)); $plugin->stop(); } catch (\Exception $ex) { Logger::error("Error while starting " . get_class($plugin)); } } }