Beispiel #1
0
 /** Disconnects the server.
  * This function disconnect properly the bot from the server, by sending fake events to the plugin to simulate client disconnections and server disconnection
  * before closing the link.
  * 
  * \return Nothing.
  */
 public function disconnect()
 {
     Leelabot::message('Disconnecting from server $0', array($this->_name));
     //Setting the server as current server
     RCon::setServer($this);
     Leelabot::message('Sending ClientDisconnect events to plugins', array(), E_DEBUG);
     foreach ($this->players as $id => $client) {
         $this->_leelabot->plugins->callServerEvent('ClientDisconnect', $id);
         unset($this->players[$id]);
     }
     //Calling the ShutdownGame event
     $this->_leelabot->plugins->callServerEvent('ShutdownGame');
     $this->_leelabot->plugins->callServerEvent('EndGame');
     //Finally, we close the links to the server and we ask to the main class to delete the instance
     if (isset($this->_logfile['ftp'])) {
         ftp_close($this->_logfile['ftp']);
     }
     fclose($this->_logfile['fp']);
     $this->_leelabot->unloadServer($this->_name);
 }
Beispiel #2
0
 /** Gets a RCon instance for the specified server.
  * This function returns an instance of RCon (the same as the innerAPI one) for the specified server in argument.
  * 
  * \param $server The wanted server's name.
  * 
  * \return If the server exists, it returns an instance of RCon class. Else, it returns FALSE.
  */
 public static function getServerRCon($server)
 {
     $self = self::getInstance();
     if (!isset($self->_leelabot->servers[$server])) {
         return FALSE;
     }
     $rcon = new RCon();
     $rcon->setServer($self->_leelabot->servers[$server]);
     return $rcon;
 }
Beispiel #3
0
 /** Loads all the server instances and defining their parameters
  * This function loads all the server instances found in Leelabot::$config, and initializes them with their config.
  * 
  * \returns TRUE if instances loaded successfully, FALSE otherwise.
  */
 public function loadServerInstances()
 {
     if (!isset($this->config['Server'])) {
         Leelabot::message('No server defined in configuration.', array(), E_ERROR);
         exit;
     }
     $this->servers = array();
     Leelabot::message('Loading server instances.');
     //Checking default configuration
     if (isset($this->config['Server']['default'])) {
         $defaultConfig = $this->config['Server']['default'];
         unset($this->config['Server']['default']);
     }
     foreach ($this->config['Server'] as $name => $instance) {
         if (isset($instance['name'])) {
             $name = $instance['name'];
         }
         Leelabot::message('Loading server "$0".', array($name));
         $this->servers[$name] = new ServerInstance($this);
         //Using config name if not specified
         $this->servers[$name]->setName($name);
         //Loading config
         if (!$this->servers[$name]->loadConfig($instance)) {
             Leelabot::message('Can\'t load config for server "$0".', array($name), E_WARNING);
             unset($this->servers[$name]);
             continue;
         }
         //Setting servers for static inner API
         RCon::setServer($this->servers[$name]);
         Server::setServer($this->servers[$name]);
         //Connecting to server
         if (!$this->servers[$name]->connect()) {
             Leelabot::message('Can\'t connect to server "$0".', array($name), E_WARNING);
             unset($this->servers[$name]);
         }
     }
 }