Esempio n. 1
0
 public function SrvEventStartupGame($server)
 {
     if (is_array($this->config[$server]) && count($this->config[$server])) {
         // If messages was active on this server
         if (isset($this->config[$server]['Active'])) {
             $this->config[$server]['Active'] = Leelabot::parseBool($this->config[$server]['Active']);
         } else {
             $this->config[$server]['Active'] = FALSE;
         }
         // Time in secondes
         if (!(isset($this->config[$server]['EverySeconds']) && is_numeric($this->config[$server]['EverySeconds']) && $this->config[$server]['EverySeconds'] >= 0)) {
             $this->config[$server]['EverySeconds'] = 60;
         }
         // File where are stored the messages to send.
         if (empty($this->config[$server]['MessagesFile']) || !is_file($this->_main->getConfigLocation() . '/' . $this->config[$server]['MessagesFile']) && !touch($this->_main->getConfigLocation() . '/' . $this->config[$server]['MessagesFile'])) {
             Leelabot::message("Can't load messages files. Messages will not be send.", array(), E_WARNING);
             $this->config[$server]['MessagesFile'] = NULL;
             $this->config[$server]['Active'] = FALSE;
         } else {
             $this->config[$server]['MessagesFile'] = $this->_main->getConfigLocation() . '/' . $this->config[$server]['MessagesFile'];
         }
         // If everythings is ok, we can load the file.
         $this->_loadFileMessages($server);
         $server = ServerList::getServer($server);
         $server->set('lastmsg', end($server->get('msgs')));
         $server->set('lasttime', 0);
     } else {
         Leelabot::message("Messages config was not found for \"" . $server . "\" server.", array(), E_WARNING);
     }
 }
Esempio n. 2
0
 public static function message($text, $params = array(), $errorType = E_NOTICE)
 {
     Leelabot::message('NginyUS : ' . $text, $params, $errorType);
     if ($errorType == E_ERROR) {
         exit;
     }
 }
Esempio n. 3
0
 public function SrvEventStartupGame($server)
 {
     if (isset($this->config[$server]['AutoTeams'])) {
         $this->config[$server]['AutoTeams'] = Leelabot::parseBool($this->config[$server]['AutoTeams']);
     }
     if (!empty($this->config[$server]['CycleMapFile'])) {
         $this->config[$server]['CycleMapFile'] = NULL;
     }
 }
Esempio n. 4
0
 public function unloadPlugin($data)
 {
     $this->_dispatcher->disableDesign();
     //We disable the design, because of AJAX
     $this->_dispatcher->disableCache();
     //Disabling cache, to be sure to re-execute the request the next time
     //Returning the the bot's root, since we're in the webadmin root
     $cwd = getcwd();
     chdir(Leelabot::$instance->root);
     //Saving the loaded plugins before loading, so we can get the loaded plugins during operation
     $pluginsBefore = Leelabot::$instance->plugins->getLoadedPlugins();
     //Loading the plugin, and processing the result
     if (Leelabot::$instance->plugins->unloadPlugin($data['matches'][1])) {
         $ret = 'success:' . join('/', array_diff($pluginsBefore, Leelabot::$instance->plugins->getLoadedPlugins()));
     } else {
         $ret = 'error:' . Leelabot::lastError();
     }
     chdir($cwd);
     //Returning to the webadmin root.
     return $ret;
 }
Esempio n. 5
0
 public function SrvEventClientConnect($id)
 {
     Leelabot::message('Client connected : $0', array($id));
 }
Esempio n. 6
0
 /** Saves the banlist.
  * This function takes the banlist in memory and put it into the banlist file specified in the configuration, after having it transformed
  * into recursive INI mode.
  * 
  * \return TRUE if the banlist saved correctly, FALSE otherwise.
  */
 public function saveBanlist()
 {
     $dump = Leelabot::generateINIStringRecursive($this->_banlist);
     return file_put_contents($this->_banlistLocation, $dump);
 }
Esempio n. 7
0
 /** Routine : checks updates on the mirror.
  * This method is bound to a routine call, which will check the availability of update for the bot, and download them if necessary.
  * If automatic updates are enabled, it will also install them.
  * 
  * \return Nothing.
  */
 public function checkUpdate()
 {
     if (!preg_match('/: ([0-9]+) \\$/', Leelabot::REVISION, $matches)) {
         return FALSE;
     }
     Leelabot::message('Checking updates...', null, E_DEBUG);
     $currentVersion = $matches[1];
     $last = $this->getLastVersion();
     if ($last->rev <= $currentVersion) {
         return;
     }
     $versions = $this->getVersions();
     usort($versions, array($this, 'compareUpdates'));
     //Getting the last updated version
     $i = 0;
     for (; $versions[$i]->rev <= $currentVersion; $i++) {
     }
     $this->_updates = array_slice($versions, $i);
     Leelabot::$instance->plugins->callEvent('update', 'available');
 }
Esempio n. 8
0
 public function eventExists($listener, $event)
 {
     if (!isset($this->_events[$listener])) {
         Leelabot::message('Error: Undefined Event Listener: $0', $listener, E_DEBUG);
         return FALSE;
     }
     return isset($this->_events[$listener][$event]);
 }
Esempio n. 9
0
 public function RoutineIrcMain()
 {
     $donnees = LeelaBotIrc::get();
     if ($donnees) {
         $commande = explode(' ', $donnees);
         $message = explode(':', $donnees, 3);
         $pseudo = explode('!', $message[1]);
         $pseudo = $pseudo[0];
         LeelaBotIrc::setPseudo($pseudo);
         if (isset($commande[1]) && rtrim($commande[0]) == 'PING') {
             LeelaBotIrc::send('PONG :' . $message[1]);
         }
         // For crazy IRC server
         if (isset($commande[1])) {
             if ($commande[1] == '001') {
                 if (isset($this->config['AutoPerform'])) {
                     foreach ($this->config['AutoPerform'] as $command) {
                         LeelaBotIrc::send($command);
                     }
                 }
                 LeelaBotIrc::join(implode(',', $this->config['Channels']));
                 Leelabot::message('The IRC bot has join $0', array(implode(',', $this->config['Channels'])));
             }
             if ($commande[1] == '433') {
                 $this->config['Nick'] = $this->config['Nick'] . '_';
                 LeelaBotIrc::setConfig($this->config);
                 LeelaBotIrc::send("NICK " . $this->config['Nick']);
                 Leelabot::message('The IRC nickname has changed for $0', array($this->config['Nick']));
             }
             if ($commande[1] == 'PRIVMSG') {
                 $channel = $commande[2];
                 LeelaBotIrc::setChannel($channel);
                 if ($message[2][0] == '!') {
                     $cmd = explode(' ', trim($message[2]));
                     $cmd[0] = substr($cmd[0], 1);
                     $level = LeelaBotIrc::getLevel($pseudo, $this->config['MainChannel']);
                     $return = $this->_plugins->callEvent('irc', $cmd[0], $level, NULL, $pseudo, $channel, $cmd, $message);
                     if ($return === Events::ACCESS_DENIED) {
                         LeelaBotIrc::sendMessage("You don't have enough rights.");
                     }
                 } else {
                     $irc2urt = LeelaBotIrc::standardize(rtrim($message[2]));
                     $pseudo = explode(' ', $message[1]);
                     $pseudo = explode('!', $pseudo[0]);
                     $pseudo = $pseudo[0];
                     $serverlist = ServerList::getList();
                     if (is_array($this->config['AutoSpeak'])) {
                         foreach ($serverlist as $server) {
                             if (isset($this->config['AutoSpeak'][$server][$channel]) && in_array($this->config['AutoSpeak'][$server][$channel], array(1, 3))) {
                                 $rcon = ServerList::getServerRCon($server);
                                 $rcon->say('^4IRC : <$nick> $message', array('nick' => $pseudo, 'message' => $irc2urt));
                             }
                         }
                     } elseif (is_numeric($this->config['AutoSpeak']) && in_array($this->config['AutoSpeak'], array(1, 3))) {
                         foreach ($serverlist as $server) {
                             $rcon = ServerList::getServerRCon($server);
                             $rcon->say('^4IRC : <$nick> $message', array('nick' => $pseudo, 'message' => $irc2urt));
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 10
0
<?php

/**
 * \file tests/config/parseconf.php
 * \author Yohann Lorant <*****@*****.**>
 * \version 0.5
 * \brief Config parser tests.
 *
 * \section LICENSE
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details at
 * http://www.gnu.org/copyleft/gpl.html
 *
 * \section DESCRIPTION
 *
 * This file tests the behavior of the config file parser (for INI-style files, but with a feature added) packed in Leelabot class.
 * This file will NOT be further documented.
 */
include '../../core/leelabot.class.php';
$leelabot = new Leelabot();
echo print_r($leelabot->parseCFGDirRecursive('conf'), TRUE);
Esempio n. 11
0
 public function WSMethodKickAll($server, $mask)
 {
     if (!ServerList::serverEnabled($server)) {
         throw new WebserviceException('Server not found');
     }
     $server = ServerList::getServer($server);
     $target = $server->searchPlayer($mask);
     if ($target === FALSE) {
         throw new WebserviceException('No player found.');
     } elseif (is_array($target)) {
         $players = array();
         $kick = true;
         foreach ($target as $p) {
             $kick = $kick && RCon::kick($p);
         }
         return $target;
     } else {
         return Leelabot::boolString(RCon::kick($target));
     }
 }
Esempio n. 12
0
 /** Init function. Loads configuration.
  * This function is called at the plugin's creation, and loads the config from main config data (in Leelabot::$config).
  * 
  * \return Nothing.
  */
 public function init()
 {
     // Got an warning on teamkill
     if (isset($this->config['TeamKills'])) {
         if (!is_bool($this->config['TeamKills'])) {
             // Only if is the first load of plugin
             $this->config['TeamKills'] = Leelabot::parseBool($this->config['TeamKills']);
         }
     } else {
         $this->config['TeamKills'] = TRUE;
     }
     // Got an warning on teamhit
     if (isset($this->config['TeamHits'])) {
         if (!is_bool($this->config['TeamHits'])) {
             // Only if is the first load of plugin
             $this->config['TeamHits'] = Leelabot::parseBool($this->config['TeamHits']);
         }
     } else {
         $this->config['TeamHits'] = FALSE;
     }
     // Got an warning if player say an bad word
     if (!isset($this->config['BadWordsFile']) || !is_file($this->_main->getConfigLocation() . '/' . $this->config['BadWordsFile']) && !touch($this->_main->getConfigLocation() . '/' . $this->config['BadWordsFile'])) {
         if (isset($this->config['BadWords'])) {
             if (!is_bool($this->config['BadWords'])) {
                 // Only if is the first load of plugin
                 $this->config['BadWords'] = Leelabot::parseBool($this->config['BadWords']);
             }
             $this->_badwords = explode('\\n', file_get_contents($this->_main->getConfigLocation() . '/' . $this->config['BadWordsFile']));
         } else {
             $this->config['BadWords'] = TRUE;
         }
     } else {
         if (isset($this->config['BadWords'])) {
             if (!is_bool($this->config['BadWords'])) {
                 // Only if is the first load of plugin
                 $this->config['BadWords'] = Leelabot::parseBool($this->config['BadWords']);
             }
             if ($this->config['BadWords']) {
                 Leelabot::message("The BadWordsFile configuration isn't set. The bot can't load BadWords warning.", array(), E_WARNING);
             }
         }
         $this->config['BadWords'] = FALSE;
     }
     // Clear warning on InitGame
     if (isset($this->config['ClearOnInit'])) {
         if (!is_bool($this->config['ClearOnInit'])) {
             // Only if is the first load of plugin
             $this->config['ClearOnInit'] = Leelabot::parseBool($this->config['ClearOnInit']);
         }
     } else {
         $this->config['ClearOnInit'] = TRUE;
     }
     // Kick on [WarnsKick] warns (must be a positive number)
     if (!(isset($this->config['WarnsKick']) && is_numeric($this->config['WarnsKick']) && $this->config['WarnsKick'] > 0)) {
         $this->config['WarnsKick'] = 3;
     }
     // Kick player after [SecondsBeforeKick]  (must be a positive number or 0)
     if (!(isset($this->config['SecondsBeforeKick']) && is_numeric($this->config['SecondsBeforeKick']) && $this->config['SecondsBeforeKick'] >= 0)) {
         $this->config['SecondsBeforeKick'] = 60;
     }
     // Level where we can't take warning. (ex: 100 = super op can't take warning)
     if (!(isset($this->config['Level']) && is_numeric($this->config['Level']) && $this->config['Level'] >= 0)) {
         $this->config['Level'] = 100;
     }
     // We delete useless event
     if (!$this->config['TeamKills']) {
         $this->deleteServerEvent('kill');
     }
     if (!$this->config['TeamHits']) {
         $this->deleteServerEvent('hit');
     }
     if (!$this->config['BadWords']) {
         $this->deleteServerEvent('say');
     }
     // We browse all servers for variables initialization
     $servers = ServerList::getList();
     foreach ($servers as $serv) {
         // Take server instance
         $server = ServerList::getServer($serv);
         // Initialize server variables
         $server->set('warns', array());
         $server->set('forgive', array());
         // Initialize players variables
         $_warns = $server->get('warns');
         $players = array_keys($server->getPlayerList());
         foreach ($players as $id) {
             $_warns[$id] = array('num' => 0, 'last' => 0);
         }
         $server->set('warns', $_warns);
     }
 }
Esempio n. 13
0
 /** Adds a custom event listener, with its auto-binding method prefix.
  * This function adds a new event listener to the event system. It allows a plugin to create his own space of events, which it cans trigger after, allowing better
  * and easier interaction between plugins.
  * 
  * \param $name The name the listener will get.
  * \param $autoMethodPrefix The prefix there will be used by other plugins for automatic method binding.
  * 
  * \return TRUE if the listener was correctly created, FALSE otherwise.
  * 
  * \see Events::addEventListener()
  */
 public function addEventListener($name, $autoMethodPrefix)
 {
     parent::addEventListener($name, $autoMethodPrefix);
     Leelabot::message('Using automatic events recognition on all plugins for listener $0...', $name);
     foreach ($this->_plugins as $pluginName => &$data) {
         if ($this->_pluginCache[$pluginName]['autoload'] === TRUE) {
             $methods = get_class_methods($data['className']);
             foreach ($methods as $method) {
                 if (preg_match('#^' . $autoMethodPrefix . '#', $method)) {
                     $event = strtolower(preg_replace('#' . $autoMethodPrefix . '(.+)#', '$1', $method));
                     Leelabot::message('Adding method $0, on event $1/$2', array($data['className'] . '::' . $method, $name, $event), E_DEBUG);
                     $this->addEvent($name, $pluginName, $event, array($data['obj'], $method));
                 }
             }
         }
     }
 }
Esempio n. 14
0
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details at
 * http://www.gnu.org/copyleft/gpl.html
 *
 * \section DESCRIPTION
 *
 * This scripts will parse any file or directory you give in parameter in searching output messages, and generate an output schema for Intl_Parser that you will just
 * have to fill with the good translations (in other words, it will generate a file with all #from and empty #to you will have to complete).
 */
//For access to method Leelabot::parseArgs()
require '../core/leelabot.class.php';
array_shift($argv);
$args = Leelabot::parseArgs($argv);
if (is_file($args[0])) {
    $contents = file_get_contents($args[0]);
    preg_match_all('#Leelabot::message\\(("|\')(.+)("|\',|\'\\))(.+\\))?;#isU', $contents, $matches);
    file_put_contents(pathinfo($args[0], PATHINFO_FILENAME) . '.lc', '#from ' . join("\n#to \n\n#from ", $matches[2]) . "\n#to ");
} elseif (is_dir($args[0])) {
    mkdir('lang');
    $dir = scandir($args[0]);
    foreach ($dir as $file) {
        $contents = file_get_contents($args[0] . '/' . $file);
        preg_match_all('#Leelabot::message\\(("|\')(.+)(",|"\\)|\',|\'\\))(.+\\))?;#isU', $contents, $matches);
        if (count($matches[2])) {
            file_put_contents('lang/' . $file . '.lc', '#from ' . join("\n#to \n\n#from ", $matches[2]) . "\n#to ");
        }
    }
} else {
Esempio n. 15
0
 /** Client message : notify it in the necessary logs.
  * This function is triggered by the say event. It will log the message in the chat log, and if it's a command, it will log it in the
  * commands log.
  * 
  * \param $id The ID of the client who sent a message.
  * \param $message The message itself.
  * 
  * \return Nothing.
  */
 public function SrvEventSay($id, $message)
 {
     Leelabot::message('Logging say message');
     print_r($this->_logFiles);
     $player = Server::getPlayer($id);
     $this->log('chat', $player->name . ' <' . $player->uuid . '>: ' . $message);
     $cmd = explode(' ', $message);
     //Checking if the message is a command
     if (strlen($cmd[0]) && $cmd[0][0] == '!') {
         if ($this->_plugins->eventExists('command', substr($cmd[0], 1))) {
             $cmdlevel = $this->_plugins->getEventLevel('command', substr($cmd[0], 1));
         } else {
             $cmdlevel = '?';
         }
         $this->log('commands', $player->name . ' <' . $player->uuid . '>: ' . $message);
         if (!empty($player->auth)) {
             $this->log('commands', "\t" . 'Authname: ' . $player->auth);
         }
         $this->log('commands', "\t" . 'Level check: ' . $player->level . '/' . $cmdlevel);
         if ($cmdlevel === '?') {
             $this->log('commands', "\t" . 'Command not found.');
         } elseif ($cmdlevel > $player->level) {
             $this->log('commands', "\t" . 'Access denied.');
         } else {
             $this->log('commands', "\t" . 'Access granted.');
         }
     }
 }
Esempio n. 16
0
 /** Saves the rights database.
  * This function saves the rights database into a file for later use.
  * 
  * \param $filename The file in which the database will be saved.
  * 
  * \return The size of the written file, or FALSE if an error occured.
  */
 public function saveRights($filename)
 {
     return file_put_contents($filename, Leelabot::generateINIStringRecursive($this->rights));
 }
Esempio n. 17
0
 /** Error handler for Leelabot
  * Handles errors thrown by PHP, writing them into the log along internal messages (useful for debugging from user experience).
  */
 public static function errorHandler($errno, $errstr, $errfile, $errline)
 {
     //Don't log error if it's a socket_accept() error (it floods the log)
     if (strpos($errstr, 'socket_accept') !== FALSE) {
         return TRUE;
     }
     if (Leelabot::$verbose >= 2 || $errno == E_ERROR) {
         Leelabot::message('Error in $0 at line $1 : $2', array($errfile, $errline, $errstr), $errno, FALSE, FALSE);
     }
 }
Esempio n. 18
0
 /** Loads the webserver and configures it.
  * This function loads the webserver and configures it from the data given in argument.
  * 
  * \param $config Configuration data
  * 
  * \return TRUE if server loaded successfully, FALSE otherwise.
  */
 public function load($config)
 {
     Leelabot::message('Loading OuterAPI...');
     include 'lib/nginyus/nginyus.php';
     NginyUS_load('lib/nginyus/');
     $this->_server = new NginyUS();
     //Checking validity of the IP/Port couple
     if (!isset($config['BindAddress']) || !isset($config['BindPort']) || !in_array($config['BindPort'], range(0, 65535)) || !filter_var($config['BindAddress'], FILTER_VALIDATE_IP)) {
         Leelabot::message('Bind address/port not found or incorrect', array(), E_WARNING);
         return FALSE;
     }
     $this->_server->setAddress($config['BindAddress'], $config['BindPort']);
     //Getting the SiteManager
     $this->_manager = $this->_server->manageSites();
     //Loading the webservice
     if (isset($config['Webservice']) && (!isset($config['Webservice']['Enable']) || Leelabot::parseBool($config['Webservice']['Enable']))) {
         Leelabot::message('Loading Webservice...');
         $this->_WSEnabled = TRUE;
         $WSConfig = $config['Webservice'];
         //Including the MLPFIM Webservice class
         include 'lib/mlpfim/mlpfimserver.php';
         //If there is aliases, we update them to add the API path to them
         if (!empty($WSConfig['Aliases'])) {
             $newAliases = array();
             foreach (explode(',', $WSConfig['Aliases']) as $alias) {
                 $newAliases[] = trim($alias) . '/api';
             }
             $WSConfig['Aliases'] = join(', ', $newAliases);
         } else {
             $WSConfig['Aliases'] = '';
         }
         //Creating site for that
         $this->_manager->newSite('webservice');
         $site = $this->_manager->getSite('webservice');
         $this->_manager->loadConfig('webservice', array('SiteRoot' => $config['BindAddress'] . '/api', 'Alias' => $WSConfig['Aliases'], 'DocumentRoot' => '.', 'ProcessFiles' => 'core/webservice.class.php'));
         if (isset($WSConfig['Authentication']) && Leelabot::parseBool($WSConfig['Authentication']) == TRUE && isset($WSConfig['AuthFile']) && is_file(Leelabot::$instance->getConfigLocation() . '/' . $WSConfig['AuthFile'])) {
             $this->_WSAuth = TRUE;
             $WSConfig['AuthFile'] = Leelabot::$instance->getConfigLocation() . '/' . $WSConfig['AuthFile'];
             $this->_WSAuthFile = $WSConfig['AuthFile'];
         } else {
             Leelabot::message('Using Webservice without authentication is not secure !', array(), E_WARNING, TRUE);
         }
     }
     //Loading the webadmin
     if (isset($config['Webadmin']) && (!isset($config['Webadmin']['Enable']) || Leelabot::parseBool($config['Webadmin']['Enable']))) {
         Leelabot::message('Loading Webadmin...');
         $this->_WAEnabled = TRUE;
         $WAConfig = $config['Webadmin'];
         //If there is aliases, we update them to add the admin path to them
         if (!empty($WAConfig['Aliases'])) {
             $newAliases = array();
             foreach (explode(',', $WAConfig['Aliases']) as $alias) {
                 $newAliases[] = trim($alias) . '/admin';
             }
             $WAConfig['Aliases'] = join(', ', $newAliases);
         } else {
             $WAConfig['Aliases'] = '';
         }
         //Creating the site in the webserver
         $this->_manager->newSite('webadmin');
         $site = $this->_manager->getSite('webadmin');
         $this->_manager->loadConfig('webadmin', array('SiteRoot' => $config['BindAddress'] . '/admin', 'Alias' => $WAConfig['Aliases'], 'DocumentRoot' => '.', 'ProcessFiles' => 'web/controllers/dispatcher.class.php'));
         if (isset($WAConfig['Authentication']) && Leelabot::parseBool($WAConfig['Authentication']) == TRUE && isset($WAConfig['AuthFile']) && is_file(Leelabot::$instance->getConfigLocation() . '/' . $WAConfig['AuthFile'])) {
             $this->_WAAuth = TRUE;
             $WAConfig['AuthFile'] = Leelabot::$instance->getConfigLocation() . '/' . $WAConfig['AuthFile'];
             $this->_WAAuthFile = $WAConfig['AuthFile'];
         } else {
             Leelabot::message('Using Webadmin without authentication is not secure !', array(), E_WARNING, TRUE);
         }
     }
     $this->_server->connect();
     //Setting InnerAPI classes
     if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) {
         Webadmin::setWAObject($this->_manager->getSite('webadmin')->classes['LeelabotAdmin']);
     }
     if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) {
         $this->_manager->getSite('webadmin')->classes['LeelabotAdmin']->setAuthentication($this->_WAAuth, $this->_WAAuthFile);
     }
     if (!empty($this->_manager->getSite('webadmin')->classes['LeelabotAdmin'])) {
         $this->_manager->getSite('webservice')->classes['LeelabotWebservice']->setAuthentication($this->_WSAuth, $this->_WSAuthFile);
     }
 }
Esempio n. 19
0
 /** Opens the log file.
  * This function opens the log file. If the log is on an FTP server, it will login, try to get its size, and open the local buffer file. If the size
  * 
  * \return TRUE if log loaded correctly, FALSE otherwise.
  */
 public function openLogFile($resume = FALSE)
 {
     switch ($this->_logfile['type']) {
         case 'file':
             Leelabot::message('Opening local game log file...');
             if (!($this->_logfile['fp'] = fopen($this->_logfile['location'], 'r'))) {
                 Leelabot::message('Can\'t open local log file : $0.', array($this->_logfile['location']), E_WARNING);
                 return FALSE;
             }
             if (!$resume) {
                 fseek($this->_logfile['fp'], 0, SEEK_END);
             }
             break;
         case 'ftp':
             Leelabot::message('Connecting to FTP server...');
             //Connecting to FTP server
             if (strpos($this->_logfile['server'], ':')) {
                 list($address, $port) = explode(':', $this->_logfile['server']);
             } else {
                 list($address, $port) = array($this->_logfile['server'], 21);
             }
             if (!($this->_logfile['ftp'] = ftp_connect($address, $port))) {
                 Leelabot::message('Can\'t connect to the log server.', array(), E_WARNING);
                 return FALSE;
             }
             ftp_set_option($this->_logfile['ftp'], FTP_AUTOSEEK, false);
             //Login
             if (!ftp_login($this->_logfile['ftp'], $this->_logfile['login'], $this->_logfile['password'])) {
                 Leelabot::message('Can\'t log in to the server.', array(), E_WARNING);
                 return FALSE;
             }
             if (!$resume) {
                 //Creating the buffer and getting end of remote log (to avoid entire log download)
                 Leelabot::message('Initializing online log read...');
                 $this->_logfile['fp'] = fopen('php://memory', 'r+');
                 $this->_logfile['state'] = FTP_FINISHED;
                 if (!($this->_logfile['origpointer'] = ftp_size($this->_logfile['ftp'], $this->_logfile['location']))) {
                     //If we can't get the size, we try to download the whole file into another temp file, and check its size
                     Leelabot::message('Can\'t get actual log size. Trying to download whole file (might be slow)...');
                     $tmpfile = fopen('php://memory', 'r+');
                     if (!ftp_get($this->_logfile['ftp'], $tmpfile, $this->_logfile['location'], FTP_BINARY)) {
                         Leelabot::message('Can\'t download log file.', array(), E_WARNING);
                         return FALSE;
                     }
                     $stat = stat($tmpfile);
                     $this->_logfile['origpointer'] = $stat['size'];
                     fclose($tmpfile);
                 }
                 $this->_logfile['pointer'] = 0;
             }
             break;
     }
     return TRUE;
 }
Esempio n. 20
0
<?php

error_reporting(E_ALL | E_STRICT);
//Defining debug level constant for user error (2^15)
define('E_DEBUG', 32768);
//Including all components needed by the program.
require 'core/db.class.php';
require 'core/innerapi.class.php';
require 'core/events.class.php';
require 'core/plugins.class.php';
require 'core/RCon.class.php';
require 'core/intl.class.php';
require 'core/instance.class.php';
require 'core/outerapi.class.php';
require 'core/leelabot.class.php';
//Strip script name from argument list
array_shift($argv);
$main = new Leelabot();
$main->init($argv);
$main->run();
Esempio n. 21
0
 /** Sends a command with translate on top
  * This functions sends a message to the server, visible by everyone on top.
  * 
  * \param $message The message to send. It will be parsed like in Leelabot::message().
  * \param $args The arguments of the message, for value replacement. Like in Leelabot::message().
  * \param $translate Boolean indicating if the method has to translate the message before sending. Default : TRUE.
  * 
  * \return Nothing.
  * \see RCon::tell()
  * \see RCon::say()
  */
 public static function topMessage($message, $args = array(), $translate = TRUE)
 {
     $self = self::getInstance();
     if (!$self->_server->isEnabled()) {
         return FALSE;
     }
     //Parsing message vars
     foreach ($args as $id => $value) {
         $message = str_replace('$' . $id, $value, $message);
     }
     if ($translate) {
         $message = Leelabot::$instance->intl->translate($message);
     }
     Leelabot::message('Message on top : $0', array($message), E_DEBUG);
     //Adding bot's name if defined
     if (!empty(Leelabot::$instance->botName)) {
         $message = '(' . Leelabot::$instance->botName . '): ' . $message;
     }
     //Splitting message to fit in the space allowed by the game to chat
     if (strlen($message) >= 137) {
         $message = wordwrap($message, 136, "\n", true);
         $message = explode("\n", $message);
         $rep = true;
         foreach ($message as $chunk) {
             $rep = $rep & self::send($chunk);
         }
     } else {
         return self::send($message);
     }
 }
Esempio n. 22
0
 /** Init function. Loads configuration.
  * This function is called at the plugin's creation, and loads the config from main config data (in Leelabot::$config).
  * 
  * \return Nothing.
  */
 public function init()
 {
     //What kind of stats will be displayed
     if (isset($this->config['ShowStats'])) {
         if (!is_array($this->config['ShowStats'])) {
             //Only if is the first load of plugin
             $this->config['ShowStats'] = explode(',', $this->config['ShowStats']);
         }
     } else {
         $this->config['ShowStats'] = array('hits', 'kills', 'deaths', 'streaks', 'heads', 'caps', 'ratio', 'round');
     }
     //What kind of awards will be displayed
     if (isset($this->config['ShowAwards'])) {
         if (!is_array($this->config['ShowAwards'])) {
             //Only if is the first load of plugin
             $this->config['ShowAwards'] = explode(',', $this->config['ShowAwards']);
         }
     } else {
         $this->config['ShowAwards'] = array('hits', 'kills', 'deaths', 'streaks', 'heads', 'caps', 'ratio', 'round');
     }
     //Displays flag captures on top
     if (isset($this->config['DisplayCaps'])) {
         if (!is_bool($this->config['DisplayCaps'])) {
             //Only if is the first load of plugin
             $this->config['DisplayCaps'] = Leelabot::parseBool($this->config['DisplayCaps']);
         }
     } else {
         $this->config['DisplayCaps'] = TRUE;
     }
     //Displays headshots on top (every 5 heads)
     if (isset($this->config['DisplayHeads'])) {
         if (!is_bool($this->config['DisplayHeads'])) {
             //Only if is the first load of plugin
             $this->config['DisplayHeads'] = Leelabot::parseBool($this->config['DisplayHeads']);
         }
     } else {
         $this->config['DisplayHeads'] = TRUE;
     }
     //Displays streaks on top (only if is the best streaks)
     if (isset($this->config['DisplayStreaks'])) {
         if (!is_bool($this->config['DisplayStreaks'])) {
             //Only if is the first load of plugin
             $this->config['DisplayStreaks'] = Leelabot::parseBool($this->config['DisplayStreaks']);
         }
     } else {
         $this->config['DisplayStreaks'] = TRUE;
     }
     //Default verbosity for the players and only if is the first load of plugin
     if (!(isset($this->config['StatsVerbosity']) && is_numeric($this->config['StatsVerbosity']) && in_array(intval($this->config['StatsVerbosity']), array(0, 1, 2, 3)))) {
         $this->config['StatsVerbosity'] = 2;
     }
     //Allows player to change their verbosity
     if (isset($this->config['AllowPlayerVerbosity'])) {
         if (!is_bool($this->config['AllowPlayerVerbosity'])) {
             //Only if is the first load of plugin
             $this->config['AllowPlayerVerbosity'] = Leelabot::parseBool($this->config['AllowPlayerVerbosity']);
         }
     } else {
         $this->config['AllowPlayerVerbosity'] = FALSE;
     }
     //IRC commands level (0:all , 1:voice, 2:operator)
     if ($this->_plugins->listenerExists('irc')) {
         $this->_plugins->setEventLevel('irc', 'stats', 1);
         $this->_plugins->setEventLevel('irc', 'awards', 0);
     }
     //Adding event listener
     $this->_plugins->addEventListener('stats', 'Stats');
     //We browse all servers for variables initialization
     $servers = ServerList::getList();
     foreach ($servers as $serv) {
         //Take server instance
         $server = ServerList::getServer($serv);
         //Variables needed by stats plugin
         $this->_initVars($server);
         //Initialize players variables
         $_stats = $server->get('stats');
         $_statsConfig = $server->get('statsConfig');
         $_ratioList = $server->get('ratioList');
         $players = array_keys($server->getPlayerList());
         foreach ($players as $id) {
             $_stats[$id] = array('hits' => 0, 'kills' => 0, 'deaths' => 0, 'streaks' => 0, 'curstreak' => 0, 'heads' => 0, 'caps' => 0, 'ratio' => 0, 'round' => 0);
             $_ratioList[$id] = 0;
             $_statsConfig[$id] = array('verbosity' => $this->config['StatsVerbosity']);
         }
         $server->set('stats', $_stats);
         $server->set('statsConfig', $_statsConfig);
         $server->set('ratioList', $_ratioList);
     }
 }