public function startAll() { foreach ($this->plugins as $plugin) { try { Logger::debug("Starting plugin " . get_class($plugin)); $plugin->onStart(); Logger::debug("Attaching event"); $events = $plugin->getEventList(); if (is_array($events)) { foreach ($events as $event) { if (is_string($event)) { EventDispatcher::getInstance()->addListener($plugin, $event); } } } else { Logger::error("Event list is not an array"); } } catch (\Exception $ex) { Logger::error("Error while starting " . get_class($plugin)); } } if (count($this->plugins) > 0) { Logger::log("Plugins started"); } }
public function addListener(Plugin $plugin, $name) { if (!isset($this->listeners[$name])) { Logger::error("Event name {$name} doesn't exists"); return; } Logger::log("Add listener for " . get_class($plugin) . " to {$name}"); $this->listeners[$name][] = $plugin; }
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($mapData) { Logger::debug("Creating maps " . $mapData["id"]); $this->setMapId($mapData["id"]); $this->setMapName($mapData["map_name"]); $this->setScore1($mapData["score_1"]); $this->setScore2($mapData["score_2"]); $this->setCurrentSide($mapData["current_side"]); $this->setStatus($mapData["status"]); $this->setMapsFor($mapData["maps_for"]); $this->setNbOt($mapData["nb_ot"]); $this->setTvRecordFile($mapData['tv_record_file']); Logger::log("Maps loaded " . $this->getMapName() . " (score: " . $this->getScore1() . " - " . $this->getScore2() . ") - Current left side: " . $this->getCurrentSide() . " - Current status: " . $this->getStatusText()); $query = mysql_query("SELECT * FROM maps_score WHERE map_id = '" . $this->map_id . "' ORDER BY created_at DESC"); while ($r = mysql_fetch_array($query)) { $this->scores[] = new Score($r); } if (count($this->scores) == 0) { mysql_query("INSERT INTO maps_score (`map_id`,`type_score`,`score1_side1`,`score1_side2`,`score2_side1`,`score2_side2`, `created_at`,`updated_at`) VALUES ('" . $mapData["id"] . "', 'normal',0,0,0,0, NOW(), NOW())"); $r = mysql_fetch_array(mysql_query("SELECT * FROM maps_score WHERE id='" . \mysql_insert_id() . "'")); $this->scores[] = new Score($r); } }
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(); } } }
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(); } }
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); } }
private function addLog($text, $type = Logger::LOG) { $text = $this->server_ip . " :: " . $text; switch ($type) { case Logger::DEBUG: Logger::debug($text); break; case Logger::LOG: Logger::log($text); break; case Logger::ERROR: Logger::error($text); break; } }
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"]); } } } } }
public function onEnd() { Logger::log("Ending " . get_class($this)); }