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: class InvalidHttpRequest extends Exception {
  8: }
  9: 
 10: class HttpRequest {
 11: 
 12:     private $method;
 13:     private $uri;
 14:     private $extraHeaders  = array();
 15:     private $queryParams   = array();
 16:     private $streamScheme  = null;
 17:     private $streamPort    = null;
 18:     private $streamHost    = null;
 19:     private $uriComponents = array();
 20: 
 21:     // user for integration tests
 22:     /** @internal */
 23:     static public $overridePathPrefix = null;
 24: 
 25:     public function __construct($method, $uri, $queryParams, $extraHeaders) {
 26:         $this->method = $method;
 27:         $this->uri = $uri;
 28:         $this->queryParams = $queryParams;
 29:         $this->extraHeaders = $extraHeaders;
 30: 
 31:         $this->parseUri();
 32: 
 33:         $this->extractStreamScheme();
 34:         $this->extractStreamPort();
 35:         $this->extractStreamHost();
 36:     }
 37: 
 38:     private function parseUri() {
 39:         $this->uriComponents = parse_url($this->uri);
 40:         if (!is_array($this->uriComponents)) {
 41:             throw new InvalidHttpRequest("Invalid URI: '{$this->uri}'");
 42:         }
 43:     }
 44: 
 45:     private function extractStreamScheme() {
 46:         if ($this->uriComponents['scheme'] == 'http') {
 47:             $this->streamScheme = 'tcp';
 48:         } else if ($this->uriComponents['scheme'] == 'https') {
 49:             $this->streamScheme = 'ssl';
 50:         } else {
 51:             throw new InvalidHttpRequest("URI has no valid scheme: '{$this->uri}'");
 52:         }
 53:     }
 54: 
 55:     private function extractStreamPort() {
 56:         if ($this->uriComponents['scheme'] == 'http') {
 57:             if (isset($this->uriComponents['port'])) {
 58:                 $this->streamPort = $this->uriComponents['port'];
 59:             } else {
 60:                 $this->streamPort = 80;
 61:             }
 62:         } else if ($this->uriComponents['scheme'] == 'https') {
 63:             if (isset($this->uriComponents['port'])) {
 64:                 $this->streamPort = $this->uriComponents['port'];
 65:             } else {
 66:                 $this->streamPort = 443;
 67:             }
 68:         } else {
 69:             throw new InvalidHttpRequest("URI has no valid scheme: '{$this->uri}'");
 70:         }
 71:     }
 72: 
 73:     private function extractStreamHost() {
 74:         if (!isset($this->uriComponents['host'])) {
 75:             throw new InvalidHttpRequest("URI has no host: '{$this->uri}'");
 76:         }
 77:         $this->streamHost = $this->uriComponents['host'];
 78:     }
 79: 
 80:     public function getHost() {
 81:         return $this->streamHost;
 82:     }
 83: 
 84:     public function getPort() {
 85:         return $this->streamPort;
 86:     }
 87: 
 88:     public function getScheme() {
 89:         return $this->streamScheme;
 90:     }
 91: 
 92:     public function getData() {
 93:         $data = $this->getHeaderData();
 94:         if ($this->method == 'post') {
 95:             $data .= $this->getPostQueryStr();
 96:         }
 97: 
 98:         return $data;
 99:     }
100: 
101:     private function getHeaderData() {
102:         $path = $this->getRequestPath();
103:         $data = strtoupper($this->method) . " $path HTTP/1.0\r\n";
104: 
105:         forEach ($this->getHeaders() as $header => $value) {
106:             $data .= "$header: $value\r\n";
107:         }
108: 
109:         $data .= "\r\n";
110:         return $data;
111:     }
112: 
113:     private function getRequestPath() {
114:         $path     = isset($this->uriComponents['path']) ? $this->uriComponents['path'] : '/';
115:         $queryStr = isset($this->uriComponents['query']) ? $this->uriComponents['query'] : null;
116: 
117:         if ($this->method == 'get') {
118:             parse_str($queryStr, $queryArray);
119:             $queryArray = array_merge($queryArray, $this->queryParams);
120:             $queryStr = http_build_query($queryArray);
121:         } else if ($this->method == 'post') {
122:         } else {
123:             throw new InvalidHttpRequest("Invalid http method: '{$this->method}'");
124:         }
125: 
126:         if (self::$overridePathPrefix) {
127:             $path = self::$overridePathPrefix . $path;
128:         }
129: 
130:         return "$path?$queryStr";
131:     }
132: 
133:     private function getHeaders() {
134:         $headers = array();
135:         $headers['Host'] = $this->streamHost;
136:         if ($this->method == 'post' && $this->queryParams) {
137:             $headers['Content-Type'] = 'application/x-www-form-urlencoded';
138:             $headers['Content-Length'] = strlen($this->getPostQueryStr());
139:         }
140: 
141:         $headers = array_merge($headers, $this->extraHeaders);
142:         return $headers;
143:     }
144: 
145:     private function getPostQueryStr() {
146:         return http_build_query($this->queryParams);
147:     }
148: }
149: 
Budabot 4 Docs API documentation generated by ApiGen