/** * * @param Task $task * @param boolean $uniq */ public function addTask(&$task, $uniq = false) { if (get_class($task) == "eTools\\Task\\Task") { Logger::debug("Try adding task for " . get_class($task->getObjet())); $ok = true; if ($uniq) { $paramTask = $task->getParam(); foreach ($this->tasklist as $v) { if ($v->getObjet() == $task->getObjet()) { if ($v->getStatus() == Task::NOT_RUNNING) { if ($v->getFunctionName() == $task->getFunctionName()) { $param = $v->getParam(); if (count($param) == count($paramTask)) { $ok = false; foreach ($param as $k => $v) { if ($paramTask[$k] != $param[$k]) { $ok = true; break; } } } } } } } } if ($ok) { Logger::debug("Added task " . get_class($task->getObjet())); array_push($this->tasklist, $task); } } }
public function __construct($scoreData) { Logger::debug("Creating score " . $scoreData["id"]); $this->setTypeScore($scoreData["type_score"]); $this->setScore1Side1($scoreData["score1_side1"]); $this->setScore1Side2($scoreData["score1_side2"]); $this->setScore2Side1($scoreData["score2_side1"]); $this->setScore2Side2($scoreData["score2_side2"]); $this->setId($scoreData["id"]); }
public function __construct($url) { $this->url = str_replace("ws://", "http://", $url); preg_match("!^http://(.*):(\\d+)/(.*)\$!", $this->url, $match); $this->ip = $match[1]; $this->port = $match[2] + 1; $this->scope = $match[3]; \eTools\Utils\Logger::log("Setting WebSocket fix to " . $this->ip . ":" . $this->port); if (self::$sock == null) { self::$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); } }
public function __construct(&$obj, $functionName, $time) { Logger::debug("Creating task for " . get_class($obj) . "::taskExecute({$functionName}) at {$time}"); $this->obj = $obj; $this->functionName = $functionName; $this->time = $time; $this->status = self::NOT_RUNNING; if (func_num_args() > 3) { for ($i = 3; $i < func_num_args(); $i++) { $this->param[] = func_get_arg($i); } } }
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; }
public function __construct($bot_ip, $bot_port) { Logger::debug("Creating {$bot_ip}:{$bot_port}"); $this->socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); if ($this->socket) { if (socket_bind($this->socket, $bot_ip, $bot_port)) { if (!socket_set_nonblock($this->socket)) { throw new SocketException("Can't set non-block mode !"); } } else { throw new SocketException("Can't bind the socket"); } } else { throw new SocketException("Can't create the socket"); } }
public function setStatus($newStatus, $save = false) { $this->status = $newStatus; if ($save) { Logger::debug("Updating status to " . $this->getStatusText() . " in database"); mysql_query("UPDATE `maps` SET status='" . $newStatus . "' WHERE id='" . $this->map_id . "'"); } }
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"); } }
public function printConfig() { Logger::log("MySQL: " . $this->mysql_ip . ":" . $this->mysql_port . " " . $this->mysql_user . ":" . \str_repeat("*", \strlen($this->mysql_pass)) . "@" . $this->mysql_base); Logger::log("Socket: " . $this->bot_ip . ":" . $this->bot_port); Logger::log("Advertising by Season:"); for ($i = 0; $i < count($this->advertising['message']); $i++) { Logger::log("-> " . $this->advertising['season_name'][$i] . ": " . $this->advertising['message'][$i]); } Logger::log("Maps:"); foreach ($this->maps as $map) { Logger::log("-> " . $map); } }
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)); } } }
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 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"); } }
public function restoreSnapshot($round) { $sql = \mysql_query("SELECT * FROM players_snapshot WHERE player_id ='" . $this->mysql_id . "' AND round_id='" . $round . "' ") or dir(mysql_error()); $req = \mysql_fetch_array($sql); if ($req) { Logger::log("Restoring player " . $this->steamid . " from match " . $this->match_id . " for round " . $round); $this->kill = $req['nb_kill']; $this->assist = $req['assist']; $this->death = $req['death']; $this->point = $req['point']; $this->hs = $req['hs']; $this->defuse = $req['defuse']; $this->bombe = $req['bombe']; $this->tk = $req['tk']; $this->v1 = $req['nb1']; $this->v2 = $req['nb2']; $this->v3 = $req['nb3']; $this->v4 = $req['nb4']; $this->v5 = $req['nb5']; $this->k1 = $req['nb1kill']; $this->k2 = $req['nb2kill']; $this->k3 = $req['nb3kill']; $this->k4 = $req['nb4kill']; $this->k5 = $req['nb5kill']; $this->firstKill = $req['firstkill']; } else { Logger::log("Snapshot not found for " . $this->steamid . " from match " . $this->match_id . " for round " . $round); } }
public function addMessage(Message $message) { Logger::log("Adding message " . get_class($message) . " to " . $this->name); $this->messages[] = $message; }
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"]); } } } } }
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 onEnd() { Logger::log("Ending " . get_class($this)); }