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: /**
  6:  * @name: MMDBParser
  7:  * @author: Tyrence (RK2)
  8:  * @description: reads entries from the text.mdb file
  9:  */
 10: class MMDBParser {
 11:     private $mmdb = array();
 12:     private $file;
 13:     
 14:     private $logger;
 15:     
 16:     public function __construct($file) {
 17:         $this->file = $file;
 18:         $this->logger = new LoggerWrapper('MMDBParser');
 19:     }
 20: 
 21:     public function getMessageString($categoryId, $instanceId) {
 22:         // check for entry in cache
 23:         if (isset($this->mmdb[$categoryId][$instanceId])) {
 24:             return $this->mmdb[$categoryId][$instanceId];
 25:         }
 26: 
 27:         $in = $this->openFile();
 28:         if ($in === null) {
 29:             return null;
 30:         }
 31: 
 32:         // start at offset = 8 since that is where the categories start
 33:         // find the category
 34:         $category = $this->findEntry($in, $categoryId, 8);
 35:         if ($category === null) {
 36:             $this->logger->log('error', "Could not find categoryID: '{$categoryId}'");
 37:             fclose($in);
 38:             return null;
 39:         }
 40: 
 41:         // find the instance
 42:         $instance = $this->findEntry($in, $instanceId, $category['offset']);
 43:         if ($instance === null) {
 44:             $this->logger->log('error', "Could not find instance id: '{$instanceId}' for categoryId: '{$categoryId}'");
 45:             fclose($in);
 46:             return null;
 47:         }
 48: 
 49:         fseek($in, $instance['offset']);
 50:         $message = $this->readString($in);
 51:         $this->mmdb[$categoryId][$instanceId] = $message;
 52: 
 53:         fclose($in);
 54: 
 55:         return $message;
 56:     }
 57: 
 58:     public function findAllInstancesInCategory($categoryId) {
 59:         $in = $this->openFile();
 60:         if ($in === null) {
 61:             return null;
 62:         }
 63: 
 64:         // start at offset = 8 since that is where the categories start
 65:         // find the category
 66:         $category = $this->findEntry($in, $categoryId, 8);
 67:         if ($category === null) {
 68:             $this->logger->log('error', "Could not find categoryID: '{$categoryId}'");
 69:             fclose($in);
 70:             return null;
 71:         }
 72:         
 73:         fseek($in, $category['offset']);
 74: 
 75:         // find all instances
 76:         $instances = array();
 77:         $instance = $this->readEntry($in);
 78:         while ($previousInstance == null || $instance['id'] > $previousInstance['id']) {
 79:             $instances[] = $instance;
 80:             $previousInstance = $instance;
 81:             $instance = $this->readEntry($in);
 82:         }
 83:         
 84:         fclose($in);
 85: 
 86:         return $instances;
 87:     }
 88:     
 89:     public function getCategories() {
 90:         $in = $this->openFile();
 91:         if ($in === null) {
 92:             return null;
 93:         }
 94: 
 95:         // start at offset = 8 since that is where the categories start
 96:         fseek($in, 8);
 97: 
 98:         // find all categories
 99:         $categories = array();
100:         $category = $this->readEntry($in);
101:         while ($previousCategory == null || $category['id'] > $previousCategory['id']) {
102:             $categories[] = $category;
103:             $previousCategory = $category;
104:             $category = $this->readEntry($in);
105:         }
106:         
107:         fclose($in);
108: 
109:         return $categories;
110:     }
111: 
112:     private function openFile($filename = "data/text.mdb") {
113:         $in = fopen($filename, 'rb');
114:         if (!$in) {
115:             $this->logger->log('error', "Could not open file: '{$filename}'");
116:             fclose($in);
117:             return null;
118:         }
119: 
120:         // make sure first 4 chars are 'MMDB'
121:         $entry = $this->readEntry($in);
122:         if ($entry['id'] != 1111772493) {
123:             $this->logger->log('error', "Not an mmdb file: '{$filename}'");
124:             fclose($in);
125:             return null;
126:         }
127: 
128:         return $in;
129:     }
130: 
131:     private function findEntry($in, $id, $offset) {
132:         fseek($in, $offset);
133: 
134:         do {
135:             $previousEntry = $entry;
136:             $entry = $this->readEntry($in);
137: 
138:             if ($previousEntry != null && $entry['id'] < $previousEntry['id']) {
139:                 return null;
140:             }
141:         } while ($id != $entry['id']);
142: 
143:         return $entry;
144:     }
145: 
146:     /**
147:      * @returns array($id, $offset)
148:      */
149:     private function readEntry($in) {
150:         return array('id' => $this->readLong($in), 'offset' => $this->readLong($in));
151:     }
152: 
153:     private function readLong($in) {
154:         return array_pop(unpack("L", fread($in, 4)));
155:     }
156: 
157:     private function readString($in) {
158:         $message = '';
159:         $char = '';
160: 
161:         $char = fread($in, 1);
162:         while ($char !== "\0") {
163:             $message .= $char;
164:             $char = fread($in, 1);
165:         }
166: 
167:         return $message;
168:     }
169: }
170: 
Budabot 4 Docs API documentation generated by ApiGen