示例#1
0
 public function init()
 {
     if (!isset($this->config['RightsFile']) || !is_file($this->_main->getConfigLocation() . '/' . $this->config['RightsFile']) && !touch($this->_main->getConfigLocation() . '/' . $this->config['RightsFile'])) {
         Leelabot::message("Can't load rights file. Rights will not be saved", array(), E_WARNING);
         if (!isset($this->config['FirstPasswd'])) {
             Leelabot::message("There is no initial password for super-user. Rights management will not work.", array(), E_WARNING);
         }
         return FALSE;
     }
     $this->config['RightsFile'] = $this->_main->getConfigLocation() . '/' . $this->config['RightsFile'];
     $this->loadRights($this->config['RightsFile']);
     if (empty($this->rights) && !isset($this->config['FirstPasswd'])) {
         Leelabot::message("There is no initial password for super-user. Rights management will not work.", array(), E_WARNING);
     }
     if (!isset($this->config['FirstPasswd'])) {
         $this->deleteCommand('setadmin');
     }
     if (isset($this->config['Verbose'])) {
         $this->config['Verbose'] = Leelabot::parseBool($this->config['Verbose']);
     } else {
         $this->config['Verbose'] = FALSE;
     }
     //Adding event listener
     $this->_plugins->addEventListener('rights', 'Rights');
     //Setting command !giverights level
     $this->setCommandLevel('giverights', 100);
 }
示例#2
0
文件: logs.php 项目: Geolim4/Leelabot
 /** The bot connects to a server, initialize the log.
  * This function is triggered when the bot is being connected to a server. The corresponding log will be open if necessary.
  * 
  * \param $server The server which is being connected.
  * 
  * \return Nothing.
  */
 public function SrvEventStartupGame($server)
 {
     $logs = array();
     if (isset($this->config['CommandLog'])) {
         if (!is_array($this->config['CommandLog']) && Leelabot::parseBool($this->config['CommandLog']) || isset($this->config['CommandLog'][$server]) && Leelabot::parseBool($this->config['CommandLog'][$server])) {
             $logs['commands'] = fopen($this->config['LogRoot'] . $server . '/commands.log', $this->_mode);
         }
     }
     if (isset($this->config['ConnectionLog'])) {
         if (!is_array($this->config['ConnectionLog']) && Leelabot::parseBool($this->config['ConnectionLog']) || isset($this->config['ConnectionLog'][$server]) && Leelabot::parseBool($this->config['ConnectionLog'][$server])) {
             $logs['connection'] = fopen($this->config['LogRoot'] . $server . '/connections.log', $this->_mode);
         }
     }
     if (isset($this->config['ChatLog'])) {
         if (!is_array($this->config['ChatLog']) && Leelabot::parseBool($this->config['ChatLog']) || isset($this->config['ChatLog'][$server]) && Leelabot::parseBool($this->config['ChatLog'][$server])) {
             $logs['chat'] = fopen($this->config['LogRoot'] . $server . '/chat.log', $this->_mode);
         }
     }
     if (!empty($logs)) {
         if (!is_dir($this->config['LogRoot'] . $server)) {
             mkdir($this->config['LogRoot'] . $server);
         }
         $this->_logFiles[$server] = $logs;
     }
 }
示例#3
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);
     }
 }
示例#4
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;
     }
 }
示例#5
0
 /** Loads a server configuration.
  * This loads a configuration for the server, by calling other methods of the class.
  * 
  * \param $config The server's configuration.
  * 
  * \return TRUE if server config loaded correctly, FALSE otherwise.
  */
 public function loadConfig($config)
 {
     $addr = $port = NULL;
     foreach ($config as $name => $value) {
         switch ($name) {
             case 'Address':
                 $addr = $value;
                 break;
             case 'Port':
                 $port = $value;
                 break;
             case 'RConPassword':
                 $this->_rconpassword = $value;
                 break;
             case 'RecoverPassword':
                 $this->_recoverPassword = $value;
                 break;
             case 'RConSendInterval':
                 $this->_rconWaiting = Leelabot::parseBool($value);
                 break;
             case 'Logfile':
                 if (!$this->setLogFile($value)) {
                     return FALSE;
                 }
                 break;
             case 'UsePlugins':
                 $this->_plugins = explode(',', str_replace(', ', ',', $value));
                 if (!in_array('core', $this->_plugins)) {
                     $this->_plugins[] = 'core';
                 }
                 break;
             case 'DefaultLevel':
                 $this->_defaultLevel = $value;
                 break;
             case 'AutoHold':
                 if (Leelabot::parseBool($value) == TRUE) {
                     $this->_autoHold = TRUE;
                 }
                 break;
         }
     }
     if ($addr || $port) {
         if (!$this->setAddress($addr, $port)) {
             return FALSE;
         }
     }
     return TRUE;
 }
示例#6
0
 /** Initializes the bot.
  * Initializes the bot, by reading arguments, parsing configs sections, initializes server instances, and many other things.
  * 
  * \param $CLIArguments list of arguments provided to the launcher, or generated ones (for further integration into other systems).
  * \return TRUE in case of success, FALSE otherwise.
  */
 public function init($CLIArguments)
 {
     //Start Cpu Monitoring
     $this->cpuRequestStart();
     //Setting default values for class attributes
     Leelabot::$instance =& $this;
     $this->_configDirectory = 'conf';
     Leelabot::$verbose = FALSE;
     $this->servers = array();
     $this->system = php_uname('a');
     $this->_showIPS = FALSE;
     $this->_iterations = 0;
     $this->_IPSHistory = array_fill(0, 10, 0);
     //Parsing CLI arguments
     $logContent = NULL;
     $CLIArguments = Leelabot::parseArgs($CLIArguments);
     //Checking CLI argument for root modification, and modification in case
     if ($rootParam = array_intersect(array('r', 'root'), array_keys($CLIArguments))) {
         chdir($CLIArguments[$rootParam[0]]);
     }
     //Setting root
     $this->root = getcwd();
     //Opening default log file (can be modified after, if requested)
     Leelabot::$_logFile = fopen('leelabot.log', 'a+');
     fseek(Leelabot::$_logFile, 0, SEEK_END);
     $initPos = ftell(Leelabot::$_logFile);
     //Loading Intl class (if it is not loadable, load a dummy substitute)
     $this->intl = new Intl(Leelabot::DEFAULT_LOCALE);
     if (!$this->intl->init) {
         $this->intl = new Intl();
         //Load class without a locale defined
         Leelabot::message('Can\'t load Intl class with default locale ($0).', array(Leelabot::DEFAULT_LOCALE), E_ERROR);
         exit;
     }
     Leelabot::message('Leelabot version $0 starting...', array(Leelabot::VERSION), E_NOTICE, TRUE);
     //Loading plugin manager class
     $this->plugins = new PluginManager($this);
     Plugins::setPluginManager($this->plugins);
     //Pre-parsing CLI arguments (these arguments are relative to config loading and files location)
     $this->processCLIPreparsingArguments($CLIArguments);
     //Loading config
     if (!$this->loadConfig()) {
         Leelabot::message("Startup aborted : Can't parse startup config.", array(), E_ERROR);
         exit;
     }
     //Checking if the number of servers defined in the config is not greater than the limit defined in the CLI
     if ($this->maxServers > 0 && count($this->config['Server']) > $this->maxServers) {
         Leelabot::message("Number of set servers in the config is greater than the limit (\$0).", array($this->maxServers), E_ERROR);
         exit;
     }
     //Processing loaded config (for main parameters)
     if (isset($this->config['Main'])) {
         $logContent = '';
         //Setting the locale in accordance with the configuration (if set)
         foreach ($this->config['Main'] as $name => $value) {
             switch ($name) {
                 case 'Locale':
                     Leelabot::message('Changed locale by configuration : $0', array($this->config['Main']['Locale']));
                     if (!$this->intl->setLocale($this->config['Main']['Locale'])) {
                         Leelabot::message('Cannot change locale to "$0"', array($this->config['Main']['Locale']), E_WARNING);
                     } else {
                         Leelabot::message('Locale successfully changed to "$0".', array($this->config['Main']['Locale']));
                     }
                     break;
                 case 'UseLog':
                     if (Leelabot::parseBool($value) == FALSE) {
                         Leelabot::message('Disabling log (by Config).');
                         //Save log content for later parameters (like when using --nolog -log file.log)
                         if (Leelabot::$_logFile) {
                             $logContent = '';
                             fseek(Leelabot::$_logFile, $initPos);
                             while (!feof(Leelabot::$_logFile)) {
                                 $logContent .= fgets(Leelabot::$_logFile);
                             }
                             //If the file was empty before logging into it, delete it
                             if ($initPos == 0) {
                                 $logFileInfo = stream_get_meta_data(Leelabot::$_logFile);
                                 fclose(Leelabot::$_logFile);
                                 unlink($logFileInfo['uri']);
                             } else {
                                 fclose(Leelabot::$_logFile);
                             }
                             Leelabot::$_logFile = FALSE;
                         }
                     }
                     break;
                 case 'BotName':
                     $this->botName = $value;
                     break;
                 case 'ShowIPS':
                     $this->_showIPS = Leelabot::parseBool($value);
                     break;
                 case 'LogFile':
                     Leelabot::message('Changing log file to $0 (by Config)', array($value));
                     //Save log content for later parameters (like when using --nolog -log file.log)
                     if (Leelabot::$_logFile) {
                         $logContent = '';
                         fseek(Leelabot::$_logFile, $initPos);
                         while (!feof(Leelabot::$_logFile)) {
                             $logContent .= fgets(Leelabot::$_logFile);
                         }
                         //If the file was empty before logging into it, delete it
                         if ($initPos == 0) {
                             $logFileInfo = stream_get_meta_data(Leelabot::$_logFile);
                             fclose(Leelabot::$_logFile);
                             unlink($logFileInfo['uri']);
                         } else {
                             fclose(Leelabot::$_logFile);
                         }
                         Leelabot::$_logFile = FALSE;
                     }
                     //Load new file, and put the old log content into it (if opening has not failed, else we re-open the old log file)
                     if (!(Leelabot::$_logFile = fopen($value, 'a+'))) {
                         Leelabot::$_logFile = fopen($logFileInfo['uri'], 'a+');
                         Leelabot::message('Cannot open new log file ($0), reverting to old.', array($value), E_WARNING);
                     } else {
                         fseek(Leelabot::$_logFile, 0, SEEK_END);
                         $initPos = ftell(Leelabot::$_logFile);
                         fputs(Leelabot::$_logFile, $logContent);
                     }
                     break;
             }
         }
         unset($logContent);
     }
     //Post-parsing CLI arguments (after loading the config because they override file configuration)
     $this->processCLIPostparsingArguments($CLIArguments, $initPos);
     //Loading ServerList InnerAPI class
     ServerList::setLeelabotClass($this);
     //Loading Locale InnerAPI class
     Locales::init($this->intl);
     //Loading the OuterAPI (if required, i.e. There is an API section in config and if there's an Enable parameter, it is active)
     if (isset($this->config['API']) && (!isset($this->config['API']['Enable']) || Leelabot::parseBool($this->config['API']['Enable']) == TRUE)) {
         $this->outerAPI = new OuterAPI();
         $this->outerAPI->load($this->config['API']);
     } else {
         $this->outerAPI = NULL;
     }
     //Loading Update class if needed.
     if (isset($this->config['Update']) && isset($this->config['Update']['Enabled']) && Leelabot::parseBool($this->config['Update']['Enabled'])) {
         include 'core/update.class.php';
         $this->update = new Updater($this->config['Update'], $this->plugins);
     }
     //Loading plugins (throws a warning if there is no plugin general config, because using leelabot without plugins is as useful as eating corn flakes hoping to fly)
     if (isset($this->config['Plugins']) && isset($this->config['Plugins']['AutoLoad']) && $this->config['Plugins']['AutoLoad']) {
         //Getting automatically loaded plugins
         $this->config['Plugins']['AutoLoad'] = explode(',', $this->config['Plugins']['AutoLoad']);
         //Setting priority order.
         $order = array();
         $unordered = array();
         foreach ($this->config['Plugins']['AutoLoad'] as $plugin) {
             $plugin = trim($plugin);
             if (strpos($plugin, '/')) {
                 $priority = explode('/', $plugin);
                 $i = 0;
                 for (; isset($order[$priority[1] . '.' . $i]); $i++) {
                 }
                 $order[$priority[0] . '.' . $i] = $priority[0];
             } else {
                 $unordered[] = $plugin;
             }
         }
         ksort($order);
         $this->config['Plugins']['AutoLoad'] = array_merge(array_values($order), $unordered);
         //Setting default right level for commands
         if (isset($this->config['Commands']['DefaultLevel'])) {
             $this->plugins->setDefaultRightLevel($this->config['Commands']['DefaultLevel']);
         } else {
             $this->plugins->setDefaultRightLevel(0);
         }
         //We load plugins
         $this->plugins->loadPlugins($this->config['Plugins']['AutoLoad'], TRUE);
         //Setting user-defined levels for commands
         if (isset($this->config['Commands']['Levels'])) {
             foreach ($this->config['Commands']['Levels'] as $key => $value) {
                 if ($key[0] = '!') {
                     //We check if the param name is a command
                     $this->plugins->setCommandLevel($key, $value, TRUE);
                 } elseif (intval($key) == $key) {
                     $value = explode(',', $value);
                     foreach ($value as $command) {
                         $this->plugins->setCommandLevel($command, $key, TRUE);
                     }
                 }
             }
         }
         //Setting the verbosity for the command replies
         if (isset($this->config['Commands']['QuietReplies'])) {
             $this->plugins->setQuietReply($this->config['Commands']['QuietReplies']);
         }
     } else {
         Leelabot::message('There is no plugin configuration', array(), E_WARNING);
     }
     //Loading server instances
     $this->loadServerInstances();
     //Notice that we have loaded successfully if more than one server loaded
     if (count($this->servers)) {
         Leelabot::message('Leelabot loaded successfully for $0 server$1', array(count($this->servers), count($this->servers) > 1 ? 's' : ''));
     } else {
         Leelabot::message('Can\'t load Leelabot for any configured server.', array(), E_ERROR);
         exit;
     }
 }
示例#7
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);
     }
 }
示例#8
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);
     }
 }
示例#9
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);
     }
 }
示例#10
0
 /** Sets the sending of automatic replies.
  * This function sets if the replies for inexistent commands and forbidden access (too low level). By default it is enabled.
  * 
  * \param $quiet The new quietReply state (Boolean or string, which will be interpreted with Leelabot::parseBool()).
  * 
  * \return The set state as a boolean (can be used to verify the goodness of the set value).
  */
 public function setQuietReply($quiet = TRUE)
 {
     if (is_string($quiet)) {
         $this->_quietReply = Leelabot::parseBool($quiet);
     } else {
         $this->_quietReply = (bool) $quiet;
     }
     return $this->_quietReply;
 }