/**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if ($target[0] != '#') {
         $target = $messageEx[1];
         unset($messageEx[1]);
         $messageEx = array_values($messageEx);
     }
     $access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
     if ($access < $this->bot->getNeededAccess($target, $this->originalName)) {
         return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
     }
     if (count($messageEx) == 2) {
         // check target access
         if ($access < $this->bot->getAccess($target, Services::getUserManager()->getUserByNick($messageEx[1])->accountname)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
         } else {
             Services::getConnection()->getProtocol()->sendKick($this->bot->getUuid(), $target, $messageEx[1], $user->getNick());
         }
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     } else {
         unset($messageEx[0]);
         $username = $messageEx[1];
         unset($messageEx[1]);
         // check target access
         // todo: abort when target has no account
         if ($access < $this->bot->getAccess($target, Services::getUserManager()->getUserByNick($username)->accountname)) {
             return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
         } else {
             Services::getConnection()->getProtocol()->sendKick($this->bot->getUuid(), $target, $username, $user->getNick() . ': ' . implode(' ', $messageEx));
         }
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     }
 }
 /**
  * Handles joins on channels registered with chanserv
  * @param	string	$data
  */
 public function handleJoin($data)
 {
     // get chanserv address
     $chanserv = Services::getModuleManager()->lookupModule('ChanServ');
     // check for registered channel
     if (call_user_func(array($chanserv, 'isRegistered'), $data['channel'])) {
         foreach ($data['userList'] as $user) {
             // get user from array
             $user = $user['user'];
             // get channel access
             $access = Services::getModuleManager()->getBot($chanserv)->getAccess($data['channel'], $user->accountname);
             if ($access >= 500) {
                 Services::getConnection()->getProtocol()->sendMode(Services::getModuleManager()->getBot($chanserv)->getUuid(), $data['channel'], '+q ' . $user->getNick());
             } else {
                 if ($access >= Services::getModuleManager()->getBot($chanserv)->getNeededAccess($data['channel'], 'getOp')) {
                     Services::getConnection()->getProtocol()->sendMode(Services::getModuleManager()->getBot($chanserv)->getUuid(), $data['channel'], '+o ' . $user->getNick());
                 } else {
                     if ($access >= Services::getModuleManager()->getBot($chanserv)->getNeededAccess($data['channel'], 'getVoice')) {
                         Services::getConnection()->getProtocol()->sendMode(Services::getModuleManager()->getBot($chanserv)->getUuid(), $data['channel'], '+v ' . $user->getNick());
                     }
                 }
             }
         }
     }
 }
 /**
  * Creates a new instance of type Bot
  *
  * @param	UserType	$bot
  */
 public function __construct(UserType $bot, $trigger = '')
 {
     $this->bot = $bot;
     $this->trigger = $trigger;
     $this->registerEvents();
     // join channel
     $this->join(Services::getConnection()->getProtocol()->getServiceChannel());
 }
 /**
  * Sets the accountname for the given uuid
  *
  * @param	string	$uuid
  * @param	string	$accountname
  * @retuen	void
  */
 public function setAccount($uuid, $accountname)
 {
     Services::getUserManager()->getUser($uuid)->accountname = $accountname;
     if (isset($this->accountToUser[$accountname])) {
         $this->accountToUser[$accountname][] = $uuid;
     } else {
         $this->accountToUser[$accountname] = array($uuid);
     }
     // set umode +r
     Services::getConnection()->getProtocol()->sendMode($this->getUuid(), $uuid, '+r');
 }
 /**
  * Handles an incoming KICK event
  * @param	array	$data
  */
 public function handleKick($data)
 {
     // get chanserv
     $chanserv = Services::getModuleManager()->lookupModule('ChanServ');
     // ignore unregistered channels
     if (call_user_func(array($chanserv, 'isRegistered'), $data['target'])) {
         // check permissions
         if (call_user_func(array($chanserv, 'getAccess'), $data['target'], Services::getUserManager()->getUser($data['issuer'])->accountname) < call_user_func(array($chanserv, 'getAccess'), $data['target'], Services::getUserManager()->getUser($data['victim'])->accountname) || call_user_func(array($chanserv, 'getAccess'), $data['target'], Services::getUserManager()->getUser($data['issuer'])->accountname) < call_user_func(array($chanserv, 'kick'), $data['target'])) {
             // rejoin victim if needed
             Services::getConnection()->getProtocol()->sendSvsjoin($data['victim'], $data['target']);
         }
     }
 }
 /**
  * Add an item to the server
  * Note: Stores variable var with key only if such key doesn't exist at the server yet
  *
  * @param	string	$key
  * @param	mixed	$var
  * @param	integer	$expire
  * @return	void
  */
 public function add($key, $var, $expire = self::CACHE_TIMEOUT)
 {
     // add to log
     $this->cacheList[$key] = array('timestamp' => time(), 'value' => $var);
     // add to cache
     if (self::get($key) !== false) {
         parent::set($key, $var, MEMCACHE_COMPRESSED, $expire);
     } else {
         parent::add($key, $var, MEMCACHE_COMPRESSED, $expire);
     }
     // log
     if (defined('DEBUG')) {
         Services::getConnection()->getProtocol()->sendLogLine("Stored key '" . $key . "' with hash '" . sha1(is_array(self::get($key)) ? serialize(self::get($key)) : self::get($key)) . "'");
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if ($target[0] != '#') {
         $target = $messageEx[1];
         unset($messageEx[1]);
     }
     $access = $this->bot->getAccess($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
     if ($access < $this->bot->getNeededAccess($target, $this->originalName)) {
         return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.permissionDenied'));
     }
     if (count($messageEx) == 1) {
         $this->bot->setStandardModes($target);
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     } else {
         unset($messageEx[0]);
         $modeString = implode(' ', $messageEx);
         Services::getConnection()->getProtocol()->sendMode($this->bot->getUuid(), $target, str_replace(array('q', 'r', 'a', 'v', 'o', 'b', 'h', 'A', 'O', 'e', 'P'), '', $modeString));
         $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success'));
     }
 }
 /**
  * @see lib/modules/CommandModule::execute()
  */
 public function execute($user, $target, $message)
 {
     // split message
     $messageEx = explode(' ', $message);
     if ($target[0] != '#') {
         $target = $messageEx[1];
         unset($messageEx[1]);
         $messageEx = array_values($messageEx);
     }
     if ($this->bot->isRegistered($target)) {
         return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.alreadyRegistered'));
     }
     $users = Services::getChannelManager()->getChannel($target)->getUserList();
     foreach ($users as $channelUser) {
         if ($channelUser['user']->getUuid() == $user->getUuid()) {
             if (stripos($channelUser['mode'], 'o')) {
                 $this->bot->register($target, Services::getUserManager()->getUser($user->getUuid())->accountname);
                 Services::getConnection()->getProtocol()->sendMode($this->bot->getUuid(), $target, '+q ' . $user->getNick());
                 return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.success', $target));
             }
         }
     }
     return $this->bot->sendMessage($user->getUuid(), Services::getLanguage()->get($user->languageID, 'command.' . $this->originalName . '.noOp'));
 }
 /**
  * @see lib/system/user/AbstractUserType::__set()
  */
 public function __set($variable, $value)
 {
     parent::__set($variable, $value);
     // send metadata
     Services::getConnection()->getProtocol()->sendMetadata($this->getUuid(), $variable, $value);
 }
 /**
  * Handles the SERVER command
  *
  * @param	string		$input
  * @param	array<string>	$inputEx
  * @return	void
  */
 public static function SERVER($input, $inputEx)
 {
     Services::getEvent()->fire(Services::getConnection()->getProtocol(), 'serverCreated', array('name' => $inputEx[2]));
     Services::getConnection()->getProtocol()->serverList[] = $inputEx[2];
 }
 /**
  * Unregisters the channel
  *
  * @param	string	$channel
  * @return	void
  */
 public function unregister($channel)
 {
     // remove +r
     Services::getConnection()->getProtocol()->sendMode($this->getUuid(), $channel, '-r');
     $sql = "DELETE FROM\r\n\t\t\t\tchanserv_channels\r\n\t\t\tWHERE\r\n\t\t\t\tchannel = '" . escapeString($channel) . "'";
     Services::getDB()->sendQuery($sql);
     $sql = "DELETE FROM\r\n\t\t\t\tchanserv_channels_to_users\r\n\t\t\tWHERE\r\n\t\t\t\tchannel = '" . escapeString($channel) . "'";
     Services::getDB()->sendQuery($sql);
     $sql = "DELETE FROM\r\n\t\t\t\tchanserv_channel_accessLevel\r\n\t\t\tWHERE\r\n\t\t\t\tchannel = '" . escapeString($channel) . "'";
     Services::getDB()->sendQuery($sql);
     // part the channel
     $this->part($channel, 'Unregistered');
 }
 /**
  * Creates a new bot instance
  * @param	string	$moduleAddress
  * @param	string	$trigger
  * @param	string	$nick
  * @param	string	$hostname
  * @param	string	$ident
  * @param	string	$ip
  * @param	string	$modes
  * @param	string	$gecos
  */
 public function createBotInstance($moduleAddress, $trigger, $nick, $hostname, $ident, $ip, $modes, $gecos)
 {
     // validate
     if (!$this->moduleLoaded($moduleAddress)) {
         throw new ModuleException("No module found at address " . $moduleAddress . "!");
     }
     // validate module information
     if ($this->moduleInformation[$moduleAddress]['type'] != 'Bot') {
         throw new ModuleException("You can only create instances of bot modules!");
     }
     // create bot user
     $user = Services::getConnection()->getProtocol()->createBot($nick, $hostname, $ident, $ip, $modes, $gecos);
     // create instance of BotModule
     $this->runningBots[$moduleAddress] = new $moduleAddress($user, $trigger);
 }
 /**
  * Sends a QUIT to server
  * @param	string	$uuid
  * @param	string	$message
  */
 public function sendQuit($uuid, $message)
 {
     Services::getConnection()->sendLine($this->formateUserLine($uuid, "QUIT :" . $message));
 }
 /**
  * Sends a QUIT to server
  * @param	string	$message
  */
 public function quit($message = "Shutting down ...")
 {
     Services::getConnection()->getProtocol()->sendQuit($this->getUuid(), $message);
 }