Exemple #1
0
 public function __construct(Server $server)
 {
     $this->time = time();
     $this->server = $server;
     $this->path = $this->server->getDataPath() . "CrashDump_" . date("D_M_j-H.i.s-T_Y", $this->time) . ".log";
     $this->fp = @fopen($this->path, "wb");
     if (!is_resource($this->fp)) {
         throw new \RuntimeException("Could not create Crash Dump");
     }
     $this->data["time"] = $this->time;
     $this->addLine($this->server->getName() . " Crash Dump " . date("D M j H:i:s T Y", $this->time));
     $this->addLine();
     $this->baseCrash();
     $this->generalData();
     $this->pluginsData();
     $this->extraData();
     //$this->encodeData();
 }
Exemple #2
0
 public function CommandHello($id, $command)
 {
     $rcon = ServerList::getServerRCon(Server::getName());
     $player = Server::getPlayer($id);
     if (isset($command[0])) {
         $target = Server::getPlayer(Server::searchPlayer($command[0]));
         if ($target === FALSE) {
             $target = 'nobody';
         }
         if (is_array($target)) {
             $target = $target[0];
         }
         $rcon->say('Hello ' . $player->name . ', it seems you like ' . $target->name . ' !');
     } else {
         $rcon->say('Hay ' . $player->name . ' !');
     }
 }
 private static function createServer(Server $server)
 {
     //Grab connection object
     $mysqli = Utility::getSQLConnection();
     $sql = "INSERT INTO servers(";
     $sql .= "address, port, version, name, private_key, key_hash, max_clients, public, password_protected, ";
     $sql .= "allow_guests, user_count, user_list, motd, game_mode, last_heartbeat_date";
     $sql .= ") VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW())";
     $stmt = $mysqli->prepare($sql);
     if ($mysqli->errno) {
         trigger_error($mysqli->error, E_USER_ERROR);
     }
     //Bind parameters
     $stmt->bind_param("sissssisssisss", $server->getAddress(), $server->getPort(), $server->getVersion(), $server->getName(), $server->getPrivateKey(), $server->getPublicKey(), $server->getMaxClients(), $server->getPublic(), $server->getPasswordProtected(), $server->getAllowGuests(), $server->getUserCount(), $server->getUserList(), $server->getMotd(), $server->getGameMode());
     //Execute statement
     $stmt->execute();
     if ($mysqli->errno) {
         trigger_error($mysqli->error, E_USER_ERROR);
     }
     $stmt->close();
     unset($stmt);
     return "Server added successfully.\nserver=" . $server->getPublicKey();
 }
Exemple #4
0
 function edit(&$request)
 {
     $html = '';
     if ($request->exist('server')) {
         $server = new Server($request->get('server'));
     } else {
         if ($request->exist('id')) {
             $server =& $this->server_factory->getServerById($request->get('id'));
         }
     }
     if (!$server) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('admin_servers', 'error_notfound'));
         $GLOBALS['Response']->redirect('/admin/servers/');
     } else {
         $this->title = $GLOBALS['Language']->getText('admin_servers', 'all_edit', array($server->getName()));
         $html .= $this->_form($server, '/admin/servers/update/' . $server->getId());
         $html .= $this->_fetchServices($server);
     }
     return $html;
 }
Exemple #5
0
 /** Grants the given player rights.
  * This function grants the player his rights when he's authed. No auth verification is performed with this function.
  * 
  * \param $player The player to grant rights to.
  * \param $authname The name on which the player is authed.
  * \param $auth The auth parameters (IP, aliases, GUIDs).
  * 
  * \return Nothing.
  */
 private function grantAuthedRights($player, $authname, $auth)
 {
     //Auth the player
     $player->auth = $authname;
     $player->level = $auth['level'];
     //Save player data modification
     $modif = TRUE;
     if (!in_array($player->name, $auth['aliases'])) {
         $this->rights[$authname]['aliases'][] = $player->name;
     } elseif ($player->ip != $auth['IP']) {
         $this->rights[$authname]['IP'] = $player->ip;
     } elseif (!isset($auth['GUID'][Server::getName()]) || $auth['GUID'][Server::getName()] != $player->guid) {
         $this->rights[$authname]['GUID'][Server::getName()] = $player->guid;
     } else {
         $modif = FALSE;
     }
     //If a modification occured, we save the authlist
     if ($modif) {
         $this->saveRights($this->config['RightsFile']);
     }
     if ($this->config['Verbose']) {
         RCon::tell($player->id, 'You\'re now authed as $0', $authname);
     }
     $this->_plugins->callEventSimple('rights', 'authenticate', $player->id, $authname);
 }
Exemple #6
0
 /** Parses a ban command to get ban infos.
  * This function takes an array of parameters like the ones given to the !ban command and parses them to get needed infos for the ban,
  * according to the specifications of the command PluginBans::CommandBan()
  * 
  * \param $command the command parameters to parse.
  * 
  * \return An array containing the ban infos.
  */
 private function _parseBanCommand($command)
 {
     $baninfo = array('players' => array(), 'from' => array(), 'for' => array(), 'permanent' => FALSE);
     $category = 'players';
     //Parsing command
     foreach ($command as $param) {
         if ($param == 'from' || $param == 'for') {
             $category = $param;
         } elseif ($param == 'forever') {
             $baninfo['permanent'] = TRUE;
         } else {
             $baninfo[$category][] = $param;
         }
     }
     //Setting default realm if not present
     if (empty($baninfo['from']) && isset($this->config['DefaultRealm']) && $this->config['DefaultRealm'] == 'server') {
         $baninfo['from'][] = self::GLOBALBAN;
     } elseif (empty($baninfo['from'])) {
         $baninfo['from'][] = Server::getName();
     }
     //Setting default duration if not present
     $duration = $this->_parseBanDuration(join(' ', $baninfo['for']));
     if ($duration == -1 && $this->_defaultBanDuration !== NULL) {
         $duration = $this->_defaultBanDuration;
     } elseif ($duration == -1) {
         $duration = $this->_durations['day'];
     }
     if (!$baninfo['permanent']) {
         $return = array('banned' => $baninfo['players'], 'servers' => $baninfo['from'], 'duration' => $duration);
     } else {
         $return = array('banned' => $baninfo['players'], 'servers' => $baninfo['from'], 'duration' => 'forever');
     }
     return $return;
 }
Exemple #7
0
 public function IrcPlayers($pseudo, $channel, $cmd, $message)
 {
     $serverlist = ServerList::getList();
     $actual = Server::getName();
     if (isset($cmd[1]) && in_array($cmd[1], $serverlist)) {
         Server::setServer($this->_main->servers[$cmd[1]]);
         $this->_printPlayers($cmd[1]);
     } else {
         foreach ($serverlist as $server) {
             Server::setServer($this->_main->servers[$server]);
             $this->_printPlayers();
         }
     }
     Server::setServer($this->_main->servers[$actual]);
 }
Exemple #8
0
 public function IrcStats($pseudo, $channel, $cmd, $message)
 {
     $server = LeelaBotIrc::nameOfServer($cmd[2], FALSE);
     $actual = Server::getName();
     if (isset($cmd[1])) {
         if ($server !== false) {
             Server::setServer($this->_main->servers[$server]);
             $target = Server::searchPlayer(trim($cmd[1]));
             if (!$target) {
                 LeelaBotIrc::sendMessage("Unknown player");
             } elseif (is_array($target)) {
                 $players = array();
                 foreach ($target as $p) {
                     $players[] = Server::getPlayer($p)->name;
                 }
                 LeelaBotIrc::sendMessage("Multiple players found : " . join(', ', $players));
             } else {
                 $buffer = array();
                 $_stats = Server::get('stats');
                 $_awards = Server::get('awards');
                 $player = Server::getPlayer($target);
                 if ($_stats[$player->id]['deaths'] != 0) {
                     $ratio = $_stats[$player->id]['kills'] / $_stats[$player->id]['deaths'];
                 } else {
                     $ratio = $_stats[$player->id]['kills'];
                 }
                 if (in_array('hits', $this->config['ShowStats'])) {
                     //Gestion des hits en fonction de la configuration du plugin de stats
                     $hits = "Hits : " . $_stats[$player->id]['hits'] . " - ";
                 }
                 if (Server::getServer()->serverInfo['g_gametype'] == 7) {
                     //Gestion des caps uniquement en CTF
                     $caps = " - Caps : " . $_stats[$player->id]['caps'];
                 }
                 LeelaBotIrc::sendMessage("Stats de " . $player->name . " : " . $hits . "Kills : " . $_stats[$player->id]['kills'] . " - Deaths : " . $_stats[$player->id]['deaths'] . " - Ratio : " . $ratio . $caps . " - Streaks : " . $_stats[$player->id]['streaks']);
             }
             Server::setServer($this->_main->servers[$actual]);
         }
     } else {
         LeelaBotIrc::sendMessage("Player name missing");
     }
 }
Exemple #9
0
 public function SrvEventSay($id, $contents)
 {
     if ($contents[0] != '!') {
         $nick = LeelaBotIrc::rmColor(Server::getPlayer($id)->name);
         $message = LeelaBotIrc::rmColor($contents);
         $server = Server::getName();
         if (is_array($this->config['AutoSpeak'])) {
             foreach ($this->config['Channels'] as $channel) {
                 if (isset($this->config['AutoSpeak'][$server][$channel]) && in_array($this->config['AutoSpeak'][$server][$channel], array(1, 2))) {
                     LeelaBotIrc::privmsg($channel, "[" . $server . "] <" . $nick . "> : " . $message);
                 }
             }
         } elseif (is_numeric($this->config['AutoSpeak'])) {
             if (in_array($this->config['AutoSpeak'], array(1, 2))) {
                 foreach ($this->config['Channels'] as $channel) {
                     LeelaBotIrc::privmsg($channel, "[" . $server . "] <" . $nick . "> : " . $message);
                 }
             }
         }
     }
 }
Exemple #10
0
 /** Executes all the routines for all plugins.
  * This function executes all the routines for all plugins, whether checking if their interval timed out, or not (so all routines are executed), depending
  * on the value of the \b $force param.
  * 
  * \param $force Forces the routines to be executed or not. By default it does not executes them.
  * 
  * \return TRUE if routines executed correctly, FALSE otherwise.
  */
 public function callAllRoutines($force = FALSE)
 {
     $serverPlugins = Server::getPlugins();
     $serverName = Server::getName();
     foreach ($this->_routines as $className => &$class) {
         foreach ($class as $name => &$routine) {
             if ($force || !isset($routine[2][$serverName]) || time() >= $routine[2][$serverName] + $routine[1]) {
                 if (in_array($this->_pluginClasses[$className], $serverPlugins) || $routine[3]) {
                     $routine[0]->{$name}();
                     $routine[2][$serverName] = time();
                 }
             }
         }
     }
 }
Exemple #11
0
 /** Logs the data into specific logs.
  * This function logs the specified data into the right logfile, adding the date and a line return.
  * 
  * \param $log The log to write to.
  * \param $text The text to write in the log.
  * \param $server The server on which the data will be logged. Defaults to the current server.
  * 
  * \return TRUE if the text has been correctly logged, FALSE otherwise.
  */
 public function log($log, $text, $server = NULL)
 {
     if ($server === NULL) {
         $server = Server::getName();
     }
     if (!isset($this->_logFiles[$server])) {
         return FALSE;
     }
     if (!isset($this->_logFiles[$server][$log])) {
         return FALSE;
     }
     $ret = fputs($this->_logFiles[$server][$log], date(Locales::getDateTimeFormat()) . ' - ' . $text . "\n");
     return $ret !== FALSE;
 }