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\Modules;
  4: 
  5: /**
  6:  * Authors: 
  7:  *  - Tyrence (RK2)
  8:  *
  9:  * @Instance
 10:  *
 11:  * Commands this controller contains:
 12:  *  @DefineCommand(
 13:  *      command       = 'alts',
 14:  *      accessLevel   = 'member',
 15:  *      description   = 'Alt character handling',
 16:  *      help          = 'alts.txt'
 17:  *  )
 18:  *  @DefineCommand(
 19:  *      command       = 'alts main (.+)',
 20:  *      accessLevel   = 'member',
 21:  *      description   = 'Add yourself as an alt to a main'
 22:  *  )
 23:  *  @DefineCommand(
 24:  *      command       = 'altvalidate',
 25:  *      accessLevel   = 'member',
 26:  *      description   = 'Validate alts for admin privileges',
 27:  *      help          = 'altvalidate.txt'
 28:  *  )
 29:  */
 30: class AltsController {
 31: 
 32:     /**
 33:      * Name of the module.
 34:      * Set automatically by module loader.
 35:      */
 36:     public $moduleName;
 37: 
 38:     /** @Inject */
 39:     public $chatBot;
 40: 
 41:     /** @Inject */
 42:     public $settingManager;
 43: 
 44:     /** @Inject */
 45:     public $playerManager;
 46: 
 47:     /** @Inject */
 48:     public $db;
 49: 
 50:     /**
 51:      * @Setup
 52:      * This handler is called on bot startup.
 53:      */
 54:     public function setup() {
 55:         $this->db->loadSQLFile($this->moduleName, 'alts');
 56:     }
 57: 
 58:     /**
 59:      * This command handler adds alt character.
 60:      *
 61:      * @HandlesCommand("alts")
 62:      * @Matches("/^alts add ([a-z0-9- ]+)$/i")
 63:      */
 64:     public function addAltCommand($message, $channel, $sender, $sendto, $args) {
 65:         /* get all names in an array */
 66:         $names = explode(' ', $args[1]);
 67:     
 68:         $sender = ucfirst(strtolower($sender));
 69:     
 70:         $senderAltInfo = $this->getAltInfo($sender);
 71:         $main = $senderAltInfo->main;
 72:     
 73:         $success = 0;
 74:     
 75:         // Pop a name from the array until none are left
 76:         forEach ($names as $name) {
 77:             $name = ucfirst(strtolower($name));
 78:     
 79:             $uid = $this->chatBot->get_uid($name);
 80:             if (!$uid) {
 81:                 $msg = "Character <highlight>{$name}<end> does not exist.";
 82:                 $sendto->reply($msg);
 83:                 continue;
 84:             }
 85:     
 86:             $altInfo = $this->getAltInfo($name);
 87:             if ($altInfo->main == $senderAltInfo->main) {
 88:                 // already registered to self
 89:                 $msg = "<highlight>$name<end> is already registered to you.";
 90:                 $sendto->reply($msg);
 91:                 continue;
 92:             }
 93:     
 94:             if (count($altInfo->alts) > 0) {
 95:                 // already registered to someone else
 96:                 if ($altInfo->main == $name) {
 97:                     $msg = "Cannot add alt because <highlight>$name<end> is already registered as a main with alts.";
 98:                 } else {
 99:                     $msg = "Cannot add alt because <highlight>$name<end> is already registered as an of alt of <highlight>{$altInfo->main}<end>.";
100:                 }
101:                 $sendto->reply($msg);
102:                 continue;
103:             }
104:     
105:             $validated = 0;
106:             if ($senderAltInfo->isValidated($sender)) {
107:                 $validated = 1;
108:             }
109:     
110:             // insert into database
111:             $this->addAlt($senderAltInfo->main, $name, $validated);
112:             $success++;
113:     
114:             // update character information
115:             $this->playerManager->getByName($name);
116:         }
117:     
118:         if ($success > 0) {
119:             $msg = ($success == 1 ? "Alt" : "$success alts") . " added successfully.";
120:             $sendto->reply($msg);
121:         }
122:     }
123: 
124:     /**
125:      * This command handler removes alt character.
126:      *
127:      * @HandlesCommand("alts")
128:      * @Matches("/^alts (rem|del|remove|delete) ([a-z0-9-]+)$/i")
129:      */
130:     public function removeAltCommand($message, $channel, $sender, $sendto, $args) {
131:         $name = ucfirst(strtolower($args[2]));
132:     
133:         $altInfo = $this->getAltInfo($sender);
134:     
135:         if ($altInfo->main == $name) {
136:             $msg = "You cannot remove <highlight>{$name}<end> as your main.";
137:         } else if (!array_key_exists($name, $altInfo->alts)) {
138:             $msg = "<highlight>{$name}<end> is not registered as your alt.";
139:         } else if (!$altInfo->isValidated($sender) && $altInfo->isValidated($name)) {
140:             $msg = "You must be on a validated alt to remove another alt that is validated.";
141:         } else {
142:             $this->remAlt($altInfo->main, $name);
143:             $msg = "<highlight>{$name}<end> has been removed as your alt.";
144:         }
145:         $sendto->reply($msg);
146:     }
147: 
148:     /**
149:      * This command handler sets main character.
150:      *
151:      * @HandlesCommand("alts")
152:      * @Matches("/^alts setmain$/i")
153:      */
154:     public function setMainCommand($message, $channel, $sender, $sendto, $args) {
155:         $altInfo = $this->getAltInfo($sender);
156:     
157:         if ($altInfo->main == $sender) {
158:             $msg = "<highlight>{$sender}<end> is already registered as your main.";
159:             $sendto->reply($msg);
160:             return;
161:         }
162:     
163:         if (!$altInfo->isValidated($sender)) {
164:             $msg = "You must run this command from a validated character.";
165:             $sendto->reply($msg);
166:             return;
167:         }
168:     
169:         // remove all the old alt information
170:         $this->db->exec("DELETE FROM `alts` WHERE `main` = '{$altInfo->main}'");
171:     
172:         // add current main to new main as an alt
173:         $this->addAlt($sender, $altInfo->main, 1);
174:     
175:         // add current alts to new main
176:         forEach ($altInfo->alts as $alt => $validated) {
177:             if ($alt != $sender) {
178:                 $this->addAlt($sender, $alt, $validated);
179:             }
180:         }
181:     
182:         $msg = "Your main is now <highlight>{$sender}<end>.";
183:         $sendto->reply($msg);
184:     }
185: 
186:     /**
187:      * This command handler lists alt characters.
188:      *
189:      * @HandlesCommand("alts")
190:      * @Matches("/^alts ([a-z0-9-]+)$/i")
191:      * @Matches("/^alts$/i")
192:      */
193:     public function altsCommand($message, $channel, $sender, $sendto, $args) {
194:         if (isset($args[1])) {
195:             $showValidateLinks = false;
196:             $name = ucfirst(strtolower($args[1]));
197:         } else {
198:             $showValidateLinks = true;
199:             $name = $sender;
200:         }
201:     
202:         $altInfo = $this->getAltInfo($name);
203:         if (count($altInfo->alts) == 0) {
204:             $msg = "No alts are registered for <highlight>{$name}<end>.";
205:         } else {
206:             $msg = $altInfo->getAltsBlob($showValidateLinks);
207:         }
208:     
209:         $sendto->reply($msg);
210:     }
211: 
212:     /**
213:      * This command handler adds yourself as an alt to a main.
214:      *
215:      * @HandlesCommand("alts main (.+)")
216:      * @Matches("/^alts main ([a-z0-9-]+)$/i")
217:      */
218:     public function altsMainCommand($message, $channel, $sender, $sendto, $args) {
219:         $new_main = $this->getAltInfo($args[1])->main;
220:     
221:         $uid = $this->chatBot->get_uid($new_main);
222:         if (!$uid) {
223:             $msg = "Character <highlight>$new_main<end> does not exist.";
224:             $sendto->reply($msg);
225:             return;
226:         }
227:     
228:         $altInfo = $this->getAltInfo($sender);
229:     
230:         if ($altInfo->main == $new_main) {
231:             $msg = "You are already registered as an alt of <highlight>{$new_main}<end>.";
232:             $sendto->reply($msg);
233:             return;
234:         }
235:     
236:         if ($altInfo->main == $sender && count($altInfo->alts) > 0) {
237:             $msg = "You must not have any alts already registered.";
238:             $sendto->reply($msg);
239:             return;
240:         }
241:     
242:         // let them know if they are changing the main for this player
243:         if ($altInfo->main != $sender) {
244:             $this->remAlt($altInfo->main, $sender);
245:             $msg = "You have been removed as an alt of <highlight>{$altInfo->main}<end>.";
246:             $sendto->reply($msg);
247:         }
248:     
249:         $this->addAlt($new_main, $sender, 0);
250:         $msg = "You have been registered as an alt of <highlight>{$new_main}<end>.";
251:         $sendto->reply($msg);
252:     }
253: 
254:     /**
255:      * This command handler validate alts for admin privileges.
256:      *
257:      * @HandlesCommand("altvalidate")
258:      * @Matches("/^altvalidate ([a-z0-9- ]+)$/i")
259:      */
260:     public function altvalidateCommand($message, $channel, $sender, $sendto, $args) {
261:         $altInfo = $this->getAltInfo($sender);
262:         $alt = ucfirst(strtolower($args[1]));
263:     
264:         if (!$altInfo->isValidated($sender)) {
265:             $sendto->reply("<highlight>$alt<end> cannot be validated from an alt that is not validated.");
266:             return;
267:         }
268:     
269:         // Make sure the character being validated is an alt of the person sending the command
270:         $isAlt = false;
271:         forEach ($altInfo->alts as $a => $validated) {
272:             if ($a == $alt) {
273:                 $isAlt = true;
274:     
275:                 if ($validated == 1) {
276:                     $sendto->reply("<highlight>$alt<end> is already validated as your alt.");
277:                     return;
278:                 }
279:             }
280:         }
281:     
282:         if (!$isAlt) {
283:             $sendto->reply("<highlight>$alt<end> is not registered as your alt.");
284:         } else {
285:             $this->db->exec("UPDATE `alts` SET `validated` = ? WHERE `alt` LIKE ? AND `main` LIKE ?", '1', $alt, $altInfo->main);
286:             $sendto->reply("<highlight>$alt<end> has been validated as your alt.");
287:         }
288:     }
289: 
290:     /**
291:      * @Event("logOn")
292:      * @Description("Reminds players logging in to validate alts")
293:      */
294:     public function checkUnvalidatedAltsEvent($eventObj) {
295:         if ($this->chatBot->isReady()) {
296:             $altInfo = $this->getAltInfo($eventObj->sender);
297:         
298:             if ($altInfo->hasUnvalidatedAlts() && $altInfo->isValidated($eventObj->sender)) {
299:                 $msg = "You have unvalidated alts. Please validate them.";
300:                 $this->chatBot->sendTell($msg, $eventObj->sender);
301:                 $this->chatBot->sendTell($altInfo->getAltsBlob(true), $eventObj->sender);
302:             }
303:         }
304:     }
305: 
306:     public function getAltInfo($player) {
307:         $player = ucfirst(strtolower($player));
308: 
309:         $ai = new AltInfo();
310: 
311:         $sql = "SELECT `alt`, `main`, `validated` FROM `alts` WHERE (`main` LIKE ?) OR (`main` LIKE (SELECT `main` FROM `alts` WHERE `alt` LIKE ?))";
312:         $data = $this->db->query($sql, $player, $player);
313: 
314:         if (count($data) > 0) {
315:             forEach ($data as $row) {
316:                 $ai->main = $row->main;
317:                 $ai->alts[$row->alt] = $row->validated;
318:             }
319:         } else {
320:             $ai->main = $player;
321:         }
322: 
323:         return $ai;
324:     }
325: 
326:     /**
327:      * This method adds given @a $alt as @a $main's alt character.
328:      */
329:     public function addAlt($main, $alt, $validated) {
330:         $main = ucfirst(strtolower($main));
331:         $alt = ucfirst(strtolower($alt));
332: 
333:         $sql = "INSERT INTO `alts` (`alt`, `main`, `validated`) VALUES (?, ?, ?)";
334:         return $this->db->exec($sql, $alt, $main, $validated);
335:     }
336: 
337:     /**
338:      * This method removes given @a $alt from being @a $main's alt character.
339:      */
340:     public function remAlt($main, $alt) {
341:         $sql = "DELETE FROM `alts` WHERE `alt` LIKE ? AND `main` LIKE ?";
342:         return $this->db->exec($sql, $alt, $main);
343:     }
344: }
345: 
Budabot 4 Docs API documentation generated by ApiGen