Guest User

Untitled

a guest
Jan 30th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.74 KB | None | 0 0
  1. <?php
  2. /**
  3.  *
  4.  * \file plugins/botmanager.php
  5.  * \author Yohann Lorant <[email protected]>
  6.  * \version 0.5
  7.  * \brief Bot manager plugin for leelabot. Allows to manage bots somewhat easier.
  8.  * \depends adminbase
  9.  *
  10.  * \section LICENSE
  11.  *
  12.  * This program is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU General Public License as
  14.  * published by the Free Software Foundation; either version 2 of
  15.  * the License, or (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful, but
  18.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20.  * General Public License for more details at
  21.  * http://www.gnu.org/copyleft/gpl.html
  22.  *
  23.  * \section DESCRIPTION
  24.  *
  25.  * This file contains the Bot manager plugin for Leelabot, which allows the user to create and delete bots.
  26.  */
  27. class PluginBotManager extends Plugin
  28. {
  29.     private $presets;
  30.    
  31.     public function init()
  32.     {
  33.         if(isset($this->config["Presets"]))
  34.         {
  35.             $this->presets = $this->config["Presets"];
  36.             foreach($this->presets as &$preset)
  37.                 $preset = explode(';', $preset);
  38.         }
  39.         else
  40.             $this->presets = array();
  41.        
  42.         if(!empty($this->config["Servers"]))
  43.             $this->config["Servers"] = explode(',', $this->config["Servers"]);
  44.        
  45.         $this->setCommandLevel('addbot', 100);
  46.     }
  47.    
  48.     public function SrvEventInitGame($id)
  49.     {
  50.         //Checking if the game has the bot_enable var set, and if not, setting it to 1 and reloading the server
  51.         if(!empty($this->config["Servers"]))
  52.         {
  53.             if(in_array(Server::getName(), $this->config["Servers"]))
  54.             {
  55.                 RCon::send("bot_enable");
  56.                 $reply = RCon::getReply();
  57.                 if(strpos($reply, '"bot_enable" is:"0^7"') === 0)
  58.                 {
  59.                     RCon::set("bot_enable", 1);
  60.                     RCon::reload();
  61.                 }
  62.             }
  63.         }
  64.     }
  65.        
  66.     public function CommandAddbot($id, $command)
  67.     {
  68.         if(empty($command[0]))
  69.             return;
  70.        
  71.         if(in_array($command[0], array_keys($this->presets)))
  72.             RCon::addbot(join(' ', $this->presets[$command[0]]));
  73.     }
  74.    
  75.     public function CommandDelbot($id, $command)
  76.     {
  77.         if(empty($command[0]))
  78.             return;
  79.        
  80.         $search = Server::searchPlayer($command[0]);
  81.        
  82.         if($search === FALSE)
  83.             return RCon::tell($id, "No player found.");
  84.         elseif(is_array($search))
  85.             return RCon::tell($id, "More than 1 player found: $0", array(join(', ', Server::getPlayerNames($search))));
  86.         elseif(Server::getPlayer($id)->isBot == FALSE)
  87.             return RCon::tell($id, "This player is not a bot.");
  88.         else
  89.             return RCon::kick($search);
  90.     }
  91. }
  92.  
  93. $this->addPluginData(array(
  94. 'name' => 'botmanager',
  95. 'className' => 'PluginBotManager',
  96. 'display' => 'Bot manager plugin',
  97. 'dependencies' => array(),
  98. 'autoload' => TRUE));
Advertisement
Add Comment
Please, Sign In to add comment