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 stdClass;
  6: 
  7: /**
  8:  * Authors: 
  9:  *  - Tyrence (RK2)
 10:  *  - Lucier (RK1)
 11:  *
 12:  * @Instance
 13:  *
 14:  * Commands this controller contains:
 15:  *  @DefineCommand(
 16:  *      command     = 'orglist',
 17:  *      accessLevel = 'guild',
 18:  *      description = 'Check an org roster',
 19:  *      help        = 'orglist.txt'
 20:  *  )
 21:  */
 22: class OrglistController {
 23: 
 24:     /**
 25:      * Name of the module.
 26:      * Set automatically by module loader.
 27:      */
 28:     public $moduleName;
 29: 
 30:     /** @Inject */
 31:     public $db;
 32:     
 33:     /** @Inject */
 34:     public $chatBot;
 35:     
 36:     /** @Inject */
 37:     public $buddylistManager;
 38:     
 39:     /** @Inject */
 40:     public $guildManager;
 41: 
 42:     /** @Inject */
 43:     public $text;
 44:     
 45:     /** @Inject */
 46:     public $util;
 47:     
 48:     /** @Inject */
 49:     public $playerManager;
 50:     
 51:     /** @Inject */
 52:     public $findOrgController;
 53:     
 54:     protected $orglist = null;
 55:     protected $orgrankmap = array();
 56:     
 57:     public function __construct() {
 58:         $this->orgrankmap["Anarchism"]  = array("Anarchist");
 59:         $this->orgrankmap["Monarchy"]   = array("Monarch",   "Counsil",      "Follower");
 60:         $this->orgrankmap["Feudalism"]  = array("Lord",      "Knight",       "Vassal",          "Peasant");
 61:         $this->orgrankmap["Republic"]   = array("President", "Advisor",      "Veteran",         "Member",         "Applicant");
 62:         $this->orgrankmap["Faction"]    = array("Director",  "Board Member", "Executive",       "Member",         "Applicant");
 63:         $this->orgrankmap["Department"] = array("President", "General",      "Squad Commander", "Unit Commander", "Unit Leader", "Unit Member", "Applicant");
 64:     }
 65:     
 66:     /**
 67:      * @HandlesCommand("orglist")
 68:      * @Matches("/^orglist end$/i")
 69:      */
 70:     public function orglistEndCommand($message, $channel, $sender, $sendto, $args) {
 71:         if (isset($this->orglist)) {
 72:             $this->orglistEnd();
 73:         } else {
 74:             $sendto->reply("There is no orglist currently running.");
 75:         }
 76:     }
 77:     
 78:     /**
 79:      * @HandlesCommand("orglist")
 80:      * @Matches("/^orglist (.+)$/i")
 81:      */
 82:     public function orglistCommand($message, $channel, $sender, $sendto, $args) {
 83:         $search = $args[1];
 84: 
 85:         if (preg_match("/^[0-9]+$/", $search)) {
 86:             $this->checkOrglist($search, $sendto);
 87:         } else {
 88:             $orgs = $this->getMatches($search);
 89:             $count = count($orgs);
 90: 
 91:             if ($count == 0) {
 92:                 $msg = "Could not find any orgs (or players in orgs) that match <highlight>$search<end>.";
 93:                 $sendto->reply($msg);
 94:             } else if ($count == 1) {
 95:                 $this->checkOrglist($orgs[0]->id, $sendto);
 96:             } else {
 97:                 $blob = $this->findOrgController->formatResults($orgs);
 98:                 $msg = $this->text->makeBlob("Org Search Results for '{$search}' ($count)", $blob);
 99:                 $sendto->reply($msg);
100:             }
101:         }
102:     }
103:     
104:     public function getMatches($search) {
105:         $orgs = $this->findOrgController->lookupOrg($search);
106: 
107:         // check if search is a character and add character's org to org list if it's not already in the list       
108:         $name = ucfirst(strtolower($search));
109:         $whois = $this->playerManager->getByName($name);
110:         if ($whois !== null && $whois->guild_id != 0) {
111:             $found = false;
112:             forEach ($orgs as $org) {
113:                 if ($org->id == $whois->guild_id) {
114:                     $found = true;
115:                     break;
116:                 }
117:             }
118:             
119:             if (!$found) {
120:                 $obj = new stdClass;
121:                 $obj->name = $whois->guild;
122:                 $obj->id = $whois->guild_id;
123:                 $obj->faction = $whois->faction;
124:                 $obj->num_members = 'unknown';
125:                 $orgs []= $obj;
126:             }
127:         }
128: 
129:         return $orgs;
130:     }
131:     
132:     public function checkOrglist($orgid, $sendto) {
133:         // Check if we are already doing a list.
134:         if (isset($this->orglist)) {
135:             $msg = "There is already an orglist running. You may force it to end by using <symbol>orglist end.";
136:             $sendto->reply($msg);
137:             return;
138:         }
139:         
140:         $this->orglist["start"] = time();
141:         $this->orglist["sendto"] = $sendto;
142: 
143:         $sendto->reply("Downloading org roster for org id $orgid...");
144: 
145:         $org = $this->guildManager->getById($orgid);
146: 
147:         if ($org === null) {
148:             $msg = "Error in getting the Org info. Either org does not exist or AO's server was too slow to respond.";
149:             $sendto->reply($msg);
150:             unset($this->orglist);
151:             return;
152:         }
153: 
154:         $this->orglist["org"] = $org->orgname;
155:         $this->orglist["orgtype"] = $this->getOrgGoverningForm($org->members);
156: 
157:         // Check each name if they are already on the buddylist (and get online status now)
158:         // Or make note of the name so we can add it to the buddylist later.
159:         forEach ($org->members as $member) {
160:             // Writing the whois info for all names
161:             // Name (Level 1/1, Sex Breed Profession)
162:             $thismember  = '<highlight>'.$member->name.'<end>';
163:             $thismember .= ' (Level <highlight>'.$member->level."<end>";
164:             if ($member->ai_level > 0) {
165:                 $thismember .= "<green>/".$member->ai_level."<end>";
166:             }
167:             $thismember .= ", ".$member->gender;
168:             $thismember .= " ".$member->breed;
169:             $thismember .= " <highlight>".$member->profession."<end>)";
170: 
171:             $this->orglist["result"][$member->name]["post"] = $thismember;
172: 
173:             $this->orglist["result"][$member->name]["name"] = $member->name;
174:             $this->orglist["result"][$member->name]["rank_id"] = $member->guild_rank_id;
175:         }
176: 
177:         $sendto->reply("Checking online status for " . count($org->members) ." members of '$org->orgname'...");
178:         
179:         $this->checkOnline($org->members);
180:         $this->addOrgMembersToBuddylist();
181: 
182:         unset($org);
183:         
184:         if (count($this->orglist["added"]) == 0) {
185:             $this->orglistEnd();
186:         }
187:     }
188:     
189:     public function getOrgGoverningForm($members) {
190:         $governingForm = '';
191:         $forms = $this->orgrankmap;
192:         forEach ($members as $member) {
193:             forEach ($forms as $name => $ranks) {
194:                 if ($ranks[$member->guild_rank_id] != $member->guild_rank) {
195:                     unset($forms[$name]);
196:                 }
197:             }
198:             if (count($forms) == 1) {
199:                 break;
200:             }
201:         }
202:         
203:         // it's possible we haven't narrowed it down to 1 at this point
204:         // If we haven't found the org yet, it can only be
205:         // Republic or Department with only a president.
206:         // choose the first one
207:         return array_shift($forms);
208:     }
209:     
210:     public function checkOnline($members) {
211:         forEach ($members as $member) {
212:             $buddy_online_status = $this->buddylistManager->isOnline($member->name);
213:             if ($buddy_online_status !== null) {
214:                 $this->orglist["result"][$member->name]["online"] = $buddy_online_status;
215:             } else if ($this->chatBot->vars["name"] == $member->name) {
216:                 $this->orglist["result"][$member->name]["online"] = 1;
217:             } else {
218:                 // check if they exist
219:                 if ($this->chatBot->get_uid($member->name)) {
220:                     $this->orglist["check"][$member->name] = 1;
221:                 }
222:             }
223:         }
224:     }
225:     
226:     public function addOrgMembersToBuddylist() {
227:         forEach ($this->orglist["check"] as $name => $value) {
228:             if (!$this->checkBuddylistSize()) {
229:                 break;
230:             }
231: 
232:             $this->orglist["added"][$name] = 1;
233:             unset($this->orglist["check"][$name]);
234:             $this->buddylistManager->add($name, 'onlineorg');
235:         }
236:     }
237:     
238:     public function orglistEnd() {
239:         $orgcolor["offline"] = "<font color='#555555'>";   // Offline names
240: 
241:         $msg = $this->orgmatesformat($this->orglist, $orgcolor, $this->orglist["start"], $this->orglist["org"]);
242:         $this->orglist["sendto"]->reply($msg);
243: 
244:         // in case it was ended early
245:         forEach ($this->orglist["added"] as $name => $value) {
246:             $this->buddylistManager->remove($name, 'onlineorg');
247:         }
248:         unset($this->orglist);
249:     }
250:     
251:     function orgmatesformat($memberlist, $orgcolor, $timestart, $orgname) {
252:         $map = $memberlist["orgtype"];
253: 
254:         $totalonline = 0;
255:         $totalcount = count($memberlist["result"]);
256:         forEach ($memberlist["result"] as $amember) {
257:             $newlist[$amember["rank_id"]][] = $amember["name"];
258:         }
259: 
260:         $blob = '';
261: 
262:         for ($rankid = 0; $rankid < count($map); $rankid++) {
263:             $onlinelist = "";
264:             $offlinelist = "";
265:             $olcount = 0;
266:             $rank_online = 0;
267:             $rank_total = count($newlist[$rankid]);
268: 
269:             sort($newlist[$rankid]);
270:             for ($i = 0; $i < $rank_total; $i++) {
271:                 if ($memberlist["result"][$newlist[$rankid][$i]]["online"]) {
272:                     $rank_online++;
273:                     $onlinelist .= "  " . $memberlist["result"][$newlist[$rankid][$i]]["post"] . "\n";
274:                 } else {
275:                     if ($offlinelist != "") {
276:                         $offlinelist .= ", ";
277:                         if (($olcount % 50) == 0) {
278:                             $offlinelist .= "<end><pagebreak>" . $orgcolor["offline"];
279:                         }
280:                     }
281:                     $offlinelist .= $newlist[$rankid][$i];
282:                     $olcount++;
283:                 }
284:             }
285: 
286:             $totalonline += $rank_online;
287: 
288:             $blob .= "\n<header2>" . $map[$rankid] . "<end> ({$rank_online} / {$rank_total})\n";
289: 
290:             if ($onlinelist != "") {
291:                 $blob .= $onlinelist;
292:             }
293:             if ($offlinelist != "") {
294:                 $blob .= $orgcolor["offline"] . $offlinelist . "<end>\n";
295:             }
296:             $blob .= "\n";
297:         }
298: 
299:         $totaltime = time() - $timestart;
300:         $blob .= "\nLookup took $totaltime seconds.";
301:         
302:         return $this->text->makeBlob("Orglist for '".$this->orglist["org"]."' ($totalonline / $totalcount)", $blob);
303:     }
304:     
305:     /**
306:      * @Event("logOn")
307:      * @Event("logOff")
308:      * @Description("Records online status of org members")
309:      */
310:     public function orgMemberLogonEvent($eventObj) {
311:         $this->updateOrglist($eventObj->sender, $eventObj->type);
312:     }
313: 
314:     /**
315:      * @Event("packet(41)")
316:      * @Description("Records online status of org members")
317:      */
318:     public function buddyRemovedEvent($eventObj) {
319:         if (isset($this->orglist)) {
320:             $this->addOrgMembersToBuddylist();
321:         }
322:     }
323: 
324:     public function updateOrglist($sender, $type) {
325:         if (isset($this->orglist["added"][$sender])) {
326:             if ($type == "logon") {
327:                 $this->orglist["result"][$sender]["online"] = 1;
328:             } else if ($type == "logoff") {
329:                 $this->orglist["result"][$sender]["online"] = 0;
330:             }
331: 
332:             $this->buddylistManager->remove($sender, 'onlineorg');
333:             unset($this->orglist["added"][$sender]);
334: 
335:             if (count($this->orglist["check"]) == 0 && count($this->orglist["added"]) == 0) {
336:                 $this->orglistEnd();
337:             }
338:         }
339:     }
340:     
341:     public function checkBuddylistSize() {
342:         return count($this->buddylistManager->buddyList) < ($this->chatBot->getBuddyListSize() - 5);
343:     }
344: }
345: 
346: 
Budabot 4 Docs API documentation generated by ApiGen