Overview

Namespaces

  • Budabot
    • Core
      • Modules
    • User
      • Modules
  • None
  • Tyrence
    • Modules

Classes

  • AccessLevel
  • Budabot\Core\AccessManager
  • Budabot\Core\AdminManager
  • Budabot\Core\AOChat
  • Budabot\Core\AOChatPacket
  • Budabot\Core\AOChatQueue
  • Budabot\Core\AOExtMsg
  • Budabot\Core\AsyncHttp
  • Budabot\Core\AutoInject
  • Budabot\Core\BotRunner
  • Budabot\Core\Budabot
  • Budabot\Core\BuddylistManager
  • Budabot\Core\CacheManager
  • Budabot\Core\CacheResult
  • Budabot\Core\ClassLoader
  • Budabot\Core\ColorSettingHandler
  • Budabot\Core\CommandAlias
  • Budabot\Core\CommandManager
  • Budabot\Core\ConfigFile
  • Budabot\Core\DB
  • Budabot\Core\DBRow
  • Budabot\Core\EventLoop
  • Budabot\Core\EventManager
  • Budabot\Core\GuildChannelCommandReply
  • Budabot\Core\GuildManager
  • Budabot\Core\HelpManager
  • Budabot\Core\Http
  • Budabot\Core\HttpRequest
  • Budabot\Core\LegacyLogger
  • Budabot\Core\LimitsController
  • Budabot\Core\LoggerWrapper
  • Budabot\Core\MMDBParser
  • Budabot\Core\Modules\AdminController
  • Budabot\Core\Modules\AliasController
  • Budabot\Core\Modules\AltInfo
  • Budabot\Core\Modules\AltsController
  • Budabot\Core\Modules\BanController
  • Budabot\Core\Modules\BuddylistController
  • Budabot\Core\Modules\ColorsController
  • Budabot\Core\Modules\CommandlistController
  • Budabot\Core\Modules\CommandSearchController
  • Budabot\Core\Modules\ConfigController
  • Budabot\Core\Modules\EventlistController
  • Budabot\Core\Modules\HelpController
  • Budabot\Core\Modules\LogsController
  • Budabot\Core\Modules\PlayerLookupController
  • Budabot\Core\Modules\ProfileCommandReply
  • Budabot\Core\Modules\ProfileController
  • Budabot\Core\Modules\SettingsController
  • Budabot\Core\Modules\SQLController
  • Budabot\Core\Modules\SystemController
  • Budabot\Core\Modules\UsageController
  • Budabot\Core\Modules\WhitelistController
  • Budabot\Core\NumberSettingHandler
  • Budabot\Core\OptionsSettingHandler
  • Budabot\Core\PlayerHistory
  • Budabot\Core\PlayerHistoryManager
  • Budabot\Core\PlayerManager
  • Budabot\Core\Preferences
  • Budabot\Core\PrivateChannelCommandReply
  • Budabot\Core\PrivateMessageCommandReply
  • Budabot\Core\Registry
  • Budabot\Core\SettingHandler
  • Budabot\Core\SettingManager
  • Budabot\Core\SettingObject
  • Budabot\Core\SocketManager
  • Budabot\Core\SocketNotifier
  • Budabot\Core\SubcommandManager
  • Budabot\Core\Text
  • Budabot\Core\TextSettingHandler
  • Budabot\Core\Timer
  • Budabot\Core\TimerEvent
  • Budabot\Core\TimeSettingHandler
  • Budabot\Core\Util
  • Budabot\Core\xml
  • Budabot\User\Modules\AlienArmorController
  • Budabot\User\Modules\AlienBioController
  • Budabot\User\Modules\AlienMiscController
  • Budabot\User\Modules\AOSpeakController
  • Budabot\User\Modules\AOUController
  • Budabot\User\Modules\AXPController
  • Budabot\User\Modules\BankController
  • Budabot\User\Modules\BosslootController
  • Budabot\User\Modules\BroadcastController
  • Budabot\User\Modules\BuffPerksController
  • Budabot\User\Modules\CacheController
  • Budabot\User\Modules\ChatAssistController
  • Budabot\User\Modules\ChatCheckController
  • Budabot\User\Modules\ChatLeaderController
  • Budabot\User\Modules\ChatRallyController
  • Budabot\User\Modules\ChatSayController
  • Budabot\User\Modules\ChatTopicController
  • Budabot\User\Modules\CityWaveController
  • Budabot\User\Modules\CloakController
  • Budabot\User\Modules\ClusterController
  • Budabot\User\Modules\CountdownController
  • Budabot\User\Modules\DevController
  • Budabot\User\Modules\DingController
  • Budabot\User\Modules\EventsController
  • Budabot\User\Modules\FightController
  • Budabot\User\Modules\FindOrgController
  • Budabot\User\Modules\FindPlayerController
  • Budabot\User\Modules\FunController
  • Budabot\User\Modules\GitController
  • Budabot\User\Modules\GuideController
  • Budabot\User\Modules\GuildController
  • Budabot\User\Modules\HelpbotController
  • Budabot\User\Modules\HtmlDecodeController
  • Budabot\User\Modules\ImplantController
  • Budabot\User\Modules\ImplantDesignerController
  • Budabot\User\Modules\InactiveMemberController
  • Budabot\User\Modules\ItemsController
  • Budabot\User\Modules\KillOnSightController
  • Budabot\User\Modules\LevelController
  • Budabot\User\Modules\LinksController
  • Budabot\User\Modules\LootListsController
  • Budabot\User\Modules\MdbController
  • Budabot\User\Modules\MessageInfoCommandReply
  • Budabot\User\Modules\MockCommandReply
  • Budabot\User\Modules\NanoController
  • Budabot\User\Modules\NewsController
  • Budabot\User\Modules\NotesController
  • Budabot\User\Modules\OnlineController
  • Budabot\User\Modules\OrgHistoryController
  • Budabot\User\Modules\OrglistController
  • Budabot\User\Modules\OrgMembersController
  • Budabot\User\Modules\OSController
  • Budabot\User\Modules\PlayerHistoryController
  • Budabot\User\Modules\PlayfieldController
  • Budabot\User\Modules\PocketbossController
  • Budabot\User\Modules\PremadeImplantController
  • Budabot\User\Modules\PrivateChannelController
  • Budabot\User\Modules\QuoteController
  • Budabot\User\Modules\RaffleController
  • Budabot\User\Modules\RaidController
  • Budabot\User\Modules\RandomController
  • Budabot\User\Modules\RecipeController
  • Budabot\User\Modules\RelayController
  • Budabot\User\Modules\ReputationController
  • Budabot\User\Modules\ResearchController
  • Budabot\User\Modules\RunAsController
  • Budabot\User\Modules\SendTellController
  • Budabot\User\Modules\ShoppingController
  • Budabot\User\Modules\SilenceController
  • Budabot\User\Modules\SkillsController
  • Budabot\User\Modules\SpiritsController
  • Budabot\User\Modules\StopwatchController
  • Budabot\User\Modules\Teamspeak3
  • Budabot\User\Modules\TeamspeakController
  • Budabot\User\Modules\TestController
  • Budabot\User\Modules\TimeController
  • Budabot\User\Modules\TimerController
  • Budabot\User\Modules\TimezoneController
  • Budabot\User\Modules\TowerController
  • Budabot\User\Modules\TrackerController
  • Budabot\User\Modules\TrickleController
  • Budabot\User\Modules\UnixtimeController
  • Budabot\User\Modules\VoteController
  • Budabot\User\Modules\WeatherController
  • Budabot\User\Modules\WhatBuffsController
  • Budabot\User\Modules\WhereisController
  • Budabot\User\Modules\WhoisController
  • Budabot\User\Modules\WhoisOrgController
  • Budabot\User\Modules\WhompahController
  • Command
  • DefaultStatus
  • DefineCommand
  • Description
  • Event
  • HandlesCommand
  • Help
  • Inject
  • Instance
  • Intoptions
  • Matches
  • Options
  • Setting
  • Setup
  • Type
  • Tyrence\Modules\DemoResponseCommandReply
  • Tyrence\Modules\SameChannelResponseController
  • Visibility

Interfaces

  • Budabot\Core\CommandReply

Exceptions

  • Budabot\Core\InvalidHttpRequest
  • Budabot\Core\SQLException
  • Budabot\Core\StopExecutionException

Functions

  • Budabot\Core\isWindows
  • Budabot\Core\Modules\read_input
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: namespace Budabot\Core;
  4: 
  5: use Exception;
  6: 
  7: /**
  8:  * The AccessLevel class provides functionality for checking a player's access level.
  9:  *
 10:  * @Instance
 11:  */
 12: class AccessManager {
 13:     private static $ACCESS_LEVELS = array('none' => 0, 'superadmin' => 1,  'admin' => 2, 'mod' => 3, 'guild' => 4, 'member' => 5, 'rl' => 6, 'all' => 7);
 14: 
 15:     /** @Inject */
 16:     public $db;
 17: 
 18:     /** @Inject */
 19:     public $setting;
 20: 
 21:     /** @Inject */
 22:     public $chatBot;
 23: 
 24:     /** @Inject */
 25:     public $adminManager;
 26: 
 27:     /** @Logger */
 28:     public $logger;
 29: 
 30:     /** @Inject */
 31:     public $altsController;
 32:     
 33:     /** @Inject */
 34:     public $chatLeaderController;
 35: 
 36:     /**
 37:      * This method checks if given $sender has at least $accessLevel rights.
 38:      *
 39:      * Normally, you don't have to worry about access levels in the bot.
 40:      * The bot will automatically restrict access to commands based on the
 41:      * access level setting on the command and the access level of the user
 42:      * trying to access the command.
 43:      * 
 44:      * However, there are some cases where you may need this functionality.
 45:      * For instance, you may have a command that displays the names of the last
 46:      * ten people to send a tell to the bot.  You may wish to display a "ban"
 47:      * link when a moderator or higher uses that command.
 48:      * 
 49:      * To check if a character named 'Tyrence' has moderator access,
 50:      * you would do:
 51:      * 
 52:      * <code>
 53:      * if ($this->accessManager->checkAccess("Tyrence", "moderator")) {
 54:      *    // Tyrence has [at least] moderator access level
 55:      * } else {
 56:      *    // Tyrence does not have moderator access level
 57:      * }
 58:      * </code>
 59:      * 
 60:      * Note that this will return true if 'Tyrence' is a moderator on your
 61:      * bot, but also if he is anything higher, such as administrator, or superadmin.
 62:      *
 63:      * This command will check the character's "effective" access level, meaning
 64:      * the higher of it's own access level and that of it's main, if it has a main
 65:      * and if it has been validated as an alt.
 66:      * 
 67:      * @param string $sender - the name of the person you want to check access on
 68:      * @param string $accessLevel - can be one of: superadmin, admininistrator, moderator, guild, member, raidleader, all
 69:      * @return bool true if $sender has at least $accessLevel, false otherwise
 70:      */
 71:     public function checkAccess($sender, $accessLevel) {
 72:         $this->logger->log("DEBUG", "Checking access level '$accessLevel' against character '$sender'");
 73: 
 74:         $returnVal = $this->checkSingleAccess($sender, $accessLevel);
 75: 
 76:         if ($returnVal === false) {
 77:             // if current character doesn't have access,
 78:             // and if the current character is not a main character,
 79:             // and if the current character is validated,
 80:             // then check access against the main character,
 81:             // otherwise just return the result
 82:             $altInfo = $this->altsController->getAltInfo($sender);
 83:             if ($sender != $altInfo->main && $altInfo->isValidated($sender)) {
 84:                 $this->logger->log("DEBUG", "Checking access level '$accessLevel' against the main of '$sender' which is '$altInfo->main'");
 85:                 $returnVal = $this->checkSingleAccess($altInfo->main, $accessLevel);
 86:             }
 87:         }
 88: 
 89:         return $returnVal;
 90:     }
 91: 
 92:     public function checkSingleAccess($sender, $accessLevel) {
 93:         $sender = ucfirst(strtolower($sender));
 94: 
 95:         $charAccessLevel = $this->getSingleAccessLevel($sender);
 96:         return ($this->compareAccessLevels($charAccessLevel, $accessLevel) >= 0);
 97:     }
 98: 
 99:     public function getDisplayName($accessLevel) {
100:         $displayName = $this->getAccessLevel($accessLevel);
101:         switch ($displayName) {
102:             case "rl":
103:                 $displayName = "raidleader";
104:                 break;
105:             case "mod":
106:                 $displayName = "moderator";
107:                 break;
108:             case "admin":
109:                 $displayName = "administrator";
110:                 break;
111:         }
112: 
113:         return $displayName;
114:     }
115: 
116:     /**
117:      * Returns the access level of $sender, ignoring guild admin and inheriting access level from main
118:      */
119:     public function getSingleAccessLevel($sender) {
120:         if ($this->chatBot->vars["SuperAdmin"] == $sender){
121:             return "superadmin";
122:         }
123:         if (isset($this->adminManager->admins[$sender])) {
124:             $level = $this->adminManager->admins[$sender]["level"];
125:             if ($level >= 4) {
126:                 return "admin";
127:             }
128:             if ($level >= 3) {
129:                 return "mod";
130:             }
131:         }
132:         if ($this->chatLeaderController !== null && $this->chatLeaderController->getLeader() == $sender) {
133:             return "rl";
134:         }
135:         if (isset($this->chatBot->guildmembers[$sender])) {
136:             return "guild";
137:         }
138: 
139:         $sql = "SELECT name FROM members_<myname> WHERE `name` = ?";
140:         $row = $this->db->queryRow($sql, $sender);
141:         if ($row !== null) {
142:             return "member";
143:         }
144:         return "all";
145:     }
146: 
147:     /**
148:      * Returns the access level of $sender, accounting for guild admin and inheriting access level from main
149:      */
150:     public function getAccessLevelForCharacter($sender) {
151:         $sender = ucfirst(strtolower($sender));
152: 
153:         $accessLevel = $this->getSingleAccessLevel($sender);
154: 
155:         $altInfo = $this->altsController->getAltInfo($sender);
156:         if ($sender != $altInfo->main && $altInfo->isValidated($sender)) {
157:             $mainAccessLevel = $this->getSingleAccessLevel($altInfo->main);
158:             if ($this->compareAccessLevels($mainAccessLevel, $accessLevel) > 0) {
159:                 $accessLevel = $mainAccessLevel;
160:             }
161:         }
162: 
163:         return $accessLevel;
164:     }
165: 
166:     /**
167:      * Returns a positive number if $accessLevel1 is a greater access level than $accessLevel2,
168:      * a negative number if $accessLevel1 is a lesser access level than $accessLevel2,
169:      * and 0 if the access levels are equal.
170:      */
171:     public function compareAccessLevels($accessLevel1, $accessLevel2) {
172:         $accessLevel1 = $this->getAccessLevel($accessLevel1);
173:         $accessLevel2 = $this->getAccessLevel($accessLevel2);
174:         
175:         $accessLevels = $this->getAccessLevels();
176: 
177:         return $accessLevels[$accessLevel2] - $accessLevels[$accessLevel1];
178:     }
179: 
180:     /**
181:      * Returns a positive number if the access level of $char1 is greater than the access level of $char2,
182:      * a negative number if the access level of $char1 is less than the access level of $char2,
183:      * and 0 if the access levels of $char1 and $char2 are equal.
184:      */
185:     public function compareCharacterAccessLevels($char1, $char2) {
186:         $char1 = ucfirst(strtolower($char1));
187:         $char2 = ucfirst(strtolower($char2));
188: 
189:         $char1AccessLevel = $this->getAccessLevelForCharacter($char1);
190:         $char2AccessLevel = $this->getAccessLevelForCharacter($char2);
191: 
192:         return $this->compareAccessLevels($char1AccessLevel, $char2AccessLevel);
193:     }
194:     
195:     public function getAccessLevel($accessLevel) {
196:         $accessLevel = strtolower($accessLevel);
197:         switch ($accessLevel) {
198:             case "raidleader":
199:                 $accessLevel = "rl";
200:                 break;
201:             case "moderator":
202:                 $accessLevel = "mod";
203:                 break;
204:             case "administrator":
205:                 $accessLevel = "admin";
206:                 break;
207:         }
208:     
209:         $accessLevels = $this->getAccessLevels();
210:         if (isset($accessLevels[$accessLevel])) {
211:             return strtolower($accessLevel);
212:         } else {
213:             throw new Exception("Invalid access level '$accessLevel'.");
214:         }
215:     }
216:     
217:     public function getAccessLevels() {
218:         return self::$ACCESS_LEVELS;
219:     }
220: }
221: 
Budabot 4 Docs API documentation generated by ApiGen