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\User\Modules;
  4: 
  5: use Budabot\Core\DB;
  6: 
  7: /**
  8:  * Authors: 
  9:  *  - Tyrence (RK2)
 10:  *
 11:  * @Instance
 12:  *
 13:  * Commands this controller contains:
 14:  *  @DefineCommand(
 15:  *      command     = 'whois',
 16:  *      accessLevel = 'member', 
 17:  *      description = 'Show character info, online status, and name history', 
 18:  *      help        = 'whois.txt'
 19:  *  )
 20:  *  @DefineCommand(
 21:  *      command     = 'lookup',
 22:  *      accessLevel = 'all', 
 23:  *      description = 'Find the charId for a character', 
 24:  *      help        = 'lookup.txt'
 25:  *  )
 26:  */
 27: class WhoisController {
 28: 
 29:     /**
 30:      * Name of the module.
 31:      * Set automatically by module loader.
 32:      */
 33:     public $moduleName;
 34:     
 35:     /** @Inject */
 36:     public $db;
 37:     
 38:     /** @Inject */
 39:     public $chatBot;
 40: 
 41:     /** @Inject */
 42:     public $text;
 43:     
 44:     /** @Inject */
 45:     public $util;
 46:     
 47:     /** @Inject */
 48:     public $altsController;
 49:     
 50:     /** @Inject */
 51:     public $playerManager;
 52:     
 53:     /** @Inject */
 54:     public $buddylistManager;
 55: 
 56:     /** @Inject */
 57:     public $commandAlias;
 58:     
 59:     private $nameHistoryCache = array();
 60:     
 61:     private $replyInfo = null;
 62:     
 63:     /** @Setup */
 64:     public function setup() {
 65:         $this->db->loadSQLFile($this->moduleName, "name_history");
 66: 
 67:         $this->commandAlias->register($this->moduleName, "whois", "w");
 68:         $this->commandAlias->register($this->moduleName, "whois", "is");
 69:     }
 70:     
 71:     /**
 72:      * @Event("timer(1min)")
 73:      * @Description("Save cache of names and charIds to database")
 74:      */
 75:     public function saveCharIds($eventObj) {
 76:         if (!empty($this->nameHistoryCache) && !$this->db->inTransaction()) {
 77:             $this->db->beginTransaction();
 78:             forEach ($this->nameHistoryCache as $entry) {
 79:                 list($charid, $name) = $entry;
 80:                 if ($this->db->getType() == DB::SQLITE) {
 81:                     $this->db->exec("INSERT OR IGNORE INTO name_history (name, charid, dimension, dt) VALUES (?, ?, <dim>, ?)", $name, $charid, time());
 82:                 } else { // if ($this->db->getType() == DB::MYSQL)
 83:                     $this->db->exec("INSERT IGNORE INTO name_history (name, charid, dimension, dt) VALUES (?, ?, <dim>, ?)", $name, $charid, time());
 84:                 }
 85:             }
 86:             $this->db->commit();
 87: 
 88:             $this->nameHistoryCache = array();
 89:         }
 90:     }
 91:     
 92:     /**
 93:      * @Event("packet(20)")
 94:      * @Event("packet(21)")
 95:      * @Description("Records names and charIds")
 96:      */
 97:     public function recordCharIds($eventObj) {
 98:         $packet = $eventObj->packet;
 99:         if ($this->util->isValidSender($packet->args[0])) {
100:             $this->nameHistoryCache []= $packet->args;
101:         }
102:     }
103:     
104:     /**
105:      * @HandlesCommand("lookup")
106:      * @Matches("/^lookup ([0-9]+)$/i")
107:      */
108:     public function lookupIdCommand($message, $channel, $sender, $sendto, $args) {
109:         $charid = $args[1];
110:         $data = $this->db->query("SELECT * FROM name_history WHERE charid = ? AND dimension = <dim> ORDER BY dt DESC", $charid);
111:         $count = count($data);
112: 
113:         $blob = '';
114:         if ($count > 0) {
115:             forEach ($data as $row) {
116:                 $link = $this->text->makeChatcmd($row->name, "/tell <myname> lookup $row->name");
117:                 $blob .= "$link " . $this->util->date($row->dt) . "\n";
118:             }
119:             $msg = $this->text->makeBlob("Name History for $charid ($count)", $blob);
120:         } else {
121:             $msg = "No history available for character id <highlight>$charid<end>.";
122:         }
123: 
124:         $sendto->reply($msg);
125:     }
126:     
127:     /**
128:      * @HandlesCommand("lookup")
129:      * @Matches("/^lookup (.*)$/i")
130:      */
131:     public function lookupNameCommand($message, $channel, $sender, $sendto, $args) {
132:         $name = ucfirst(strtolower($args[1]));
133: 
134:         $data = $this->db->query("SELECT * FROM name_history WHERE name LIKE ? AND dimension = <dim> ORDER BY dt DESC", $name);
135:         $count = count($data);
136: 
137:         $blob = '';
138:         if ($count > 0) {
139:             forEach ($data as $row) {
140:                 $link = $this->text->makeChatcmd($row->charid, "/tell <myname> lookup $row->charid");
141:                 $blob .= "$link " . $this->util->date($row->dt) . "\n";
142:             }
143:             $msg = $this->text->makeBlob("Character Ids for $name ($count)", $blob);
144:         } else {
145:             $msg = "No history available for character <highlight>$name<end>.";
146:         }
147: 
148:         $sendto->reply($msg);
149:     }
150:     
151:     public function getNameHistory($charId, $rk_num) {
152:         $sql = "SELECT * FROM name_history WHERE charid = ? AND dimension = ? ORDER BY dt DESC";
153:         $data = $this->db->query($sql, $charId, $rk_num);
154: 
155:         $blob = "<header2>Name History<end>\n\n";
156:         if (count($data) > 0) {
157:             forEach ($data as $row) {
158:                 $blob .= "<highlight>{$row->name}<end> " . $this->util->date($row->dt) . "\n";
159:             }
160:         } else {
161:             $blob .= "No name history available\n";
162:         }
163: 
164:         return $blob;
165:     }
166:     
167:     /**
168:      * @HandlesCommand("whois")
169:      * @Matches("/^whois (.+)$/i")
170:      */
171:     public function whoisNameCommand($message, $channel, $sender, $sendto, $args) {
172:         $name = ucfirst(strtolower($args[1]));
173:         $uid = $this->chatBot->get_uid($name);
174:         if ($uid) {
175:             $online = $this->buddylistManager->isOnline($name);
176:             if ($online === null) {
177:                 $this->replyInfo['charname'] = $name;
178:                 $this->replyInfo['sendto'] = $sendto;
179:                 $this->buddylistManager->add($name, 'is_online');
180:             } else {
181:                 $sendto->reply($this->getOutput($name, $online));
182:             }
183:         } else {
184:             $sendto->reply("Character <highlight>{$name}<end> does not exist.");
185:         }
186:     }
187:     
188:     public function getOutput($name, $online) {
189:         $charId = $this->chatBot->get_uid($name);
190:         $lookupNameLink = $this->text->makeChatcmd("Lookup", "/tell <myname> lookup $name");
191:         $lookupCharIdLink = $this->text->makeChatcmd("Lookup", "/tell <myname> lookup $charId");
192:         $whois = $this->playerManager->getByName($name);
193:         if ($whois === null) {
194:             $blob = "<orange>Note: Could not retrieve detailed info for character.<end>\n\n";
195:             $blob .= "Name: <highlight>{$name}<end> {$lookupNameLink}\n";
196:             $blob .= "Character ID: <highlight>{$charId}<end> {$lookupCharIdLink}\n\n";
197:             $blob .= $this->getNameHistory($charId, $this->chatBot->vars['dimension']);
198: 
199:             $msg = $this->text->makeBlob("Basic Info for $name", $blob);
200:         } else {
201:             $orglistLink = $this->text->makeChatcmd("Orglist", "/tell <myname> orglist $whois->guild_id");
202: 
203:             $blob = "Name: <highlight>" . $this->getFullName($whois) . "<end> {$lookupNameLink}\n";
204:             if ($whois->guild) {
205:                 $blob .= "Guild: <highlight>{$whois->guild} ({$whois->guild_id})<end> $orglistLink\n";
206:                 $blob .= "Guild Rank: <highlight>{$whois->guild_rank} ({$whois->guild_rank_id})<end>\n";
207:             }
208:             $blob .= "Breed: <highlight>{$whois->breed}<end>\n";
209:             $blob .= "Gender: <highlight>{$whois->gender}<end>\n";
210:             $blob .= "Profession: <highlight>{$whois->profession} (" . trim($whois->prof_title) . ")<end>\n";
211:             $blob .= "Level: <highlight>{$whois->level}<end>\n";
212:             $blob .= "AI Level: <highlight>{$whois->ai_level} ({$whois->ai_rank})<end>\n";
213:             $blob .= "Faction: <highlight>{$whois->faction}<end>\n";
214:             $blob .= "Head Id: <highlight>{$whois->head_id}<end>\n";
215:             $blob .= "PVP Rating: <highlight>{$whois->pvp_rating}<end>\n";
216:             $blob .= "PVP Title: <highlight>{$whois->pvp_title}<end>\n";
217:             $blob .= "Status: ";
218:             if ($online) {
219:                 $blob .= "<green>Online<end>\n";
220:             } else {
221:                 $blob .= "<red>Offline<end>\n";
222:             }
223:             $blob .= "Character ID: <highlight>{$whois->charid}<end> {$lookupCharIdLink}\n\n";
224: 
225:             $blob .= "Source: $whois->source\n\n";
226: 
227:             $blob .= $this->getNameHistory($charId, $this->chatBot->vars['dimension']);
228: 
229:             $msg = $this->playerManager->getInfo($whois);
230:             if ($online) {
231:                 $msg .= " :: <green>Online<end>";
232:             } else {
233:                 $msg .= " :: <red>Offline<end>";
234:             }
235:             $msg .= " :: " . $this->text->makeBlob("More Info", $blob, "Detailed Info for {$name}");
236: 
237:             $altInfo = $this->altsController->getAltInfo($name);
238:             if (count($altInfo->alts) > 0) {
239:                 $msg .= " :: " . $altInfo->getAltsBlob(false, true);
240:             }
241:         }
242:         return $msg;
243:     }
244: 
245:     public function getFullName($whois) {
246:         $msg = "";
247:         
248:         if ($whois->firstname) {
249:             $msg .= $whois->firstname . " ";
250:         }
251: 
252:         $msg .= "\"{$whois->name}\"";
253: 
254:         if ($whois->lastname) {
255:             $msg .= " " . $whois->lastname;
256:         }
257: 
258:         return $msg;
259:     }
260:     
261:     /**
262:      * @Event("logOn")
263:      * @Description("Gets online status of character")
264:      */
265:     public function logonEvent($eventObj) {
266:         $name = $eventObj->sender;
267:         if ($this->replyInfo !== null && $name == $this->replyInfo['charname']) {
268:             $this->replyInfo['sendto']->reply($this->getOutput($name, 1));
269:             $this->buddylistManager->remove($name, 'is_online');
270:             $this->replyInfo = null;
271:         }
272:     }
273:     
274:     /**
275:      * @Event("logOff")
276:      * @Description("Gets offline status of character")
277:      */
278:     public function logoffEvent($eventObj) {
279:         $name = $eventObj->sender;
280:         if ($this->replyInfo !== null && $name == $this->replyInfo['charname']) {
281:             $this->replyInfo['sendto']->reply($this->getOutput($name, 0));
282:             $this->buddylistManager->remove($name, 'is_online');
283:             $this->replyInfo = null;
284:         }
285:     }
286: }
287: 
Budabot 4 Docs API documentation generated by ApiGen