Changeset 96
- Timestamp:
- 03/01/08 20:50:42 (9 months ago)
- Files:
-
- trunk/Phergie/Bot.php (modified) (1 diff)
- trunk/Phergie/Driver/Abstract.php (modified) (2 diffs)
- trunk/Phergie/Driver/Streams.php (modified) (5 diffs)
- trunk/Phergie/Plugin/Abstract/AdminCommand.php (modified) (2 diffs)
- trunk/Phergie/phergie.ini (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Phergie/Bot.php
r82 r96 162 162 * Execute the event handling loop for the client 163 163 */ 164 $client->run(); 164 while(true) { 165 $state = $client->run(); 166 167 switch($state) 168 { 169 case Phergie_Driver_Abstract::RETURN_RECONNECT: 170 sleep(1); 171 break; 172 case Phergie_Driver_Abstract::RETURN_KEEPALIVE: 173 sleep(15); 174 break; 175 case Phergie_Driver_Abstract::RETURN_END: 176 break 2; 177 } 178 } trunk/Phergie/Driver/Abstract.php
r92 r96 12 12 abstract class Phergie_Driver_Abstract 13 13 { 14 /**#@+ 15 * Return codes for the run function, that tells the Bot script whether 16 * it should re-run or not 17 */ 18 const RETURN_RECONNECT = "reconnect"; 19 const RETURN_KEEPALIVE = "keepalive"; 20 const RETURN_END = "end"; 21 /**#@-*/ 22 14 23 /** 15 24 * Associative array mapping configuration setting names to their … … 112 121 * 113 122 * @param string $reason Reason for connection termination (optional) 114 * @return void 115 */ 116 public abstract function doQuit($reason = null); 123 * @param bool $reconnect if true, the bot will reconnect to the server 124 * @return void 125 */ 126 public abstract function doQuit($reason = null, $reconnect = false); 117 127 118 128 /** trunk/Phergie/Driver/Streams.php
r88 r96 117 117 public function run() 118 118 { 119 $returnCode = $this->getIni('keepalive') ? self::RETURN_KEEPALIVE : self::RETURN_END; 119 120 $server = $this->getIni('server'); 120 121 $port = $this->getIni('port'); … … 128 129 $errstr 129 130 ); 131 132 if ($this->getIni('timeout') !== null) { 133 stream_set_timeout($this->socket, $this->getIni('timeout') * 60); 134 } elseif ($this->getIni('keepalive')) { 135 stream_set_timeout($this->socket, 400); 136 } 130 137 131 138 unset($port); … … 166 173 while (empty ($buffer)) { 167 174 $buffer = fgets($this->socket, 512); 175 176 $checkTimeout = stream_get_meta_data($this->socket); 177 if ($checkTimeout['timed_out'] === true) { 178 $this->debug('Timed out'); 179 foreach ($this->plugins as $plugin) { 180 $plugin->shutdown(); 181 } 182 break 2; 183 } 168 184 } 169 185 $buffer = rtrim($buffer); … … 260 276 $plugin->shutdown(); 261 277 } 278 if (isset($this->queue['quit'][0][1])) { 279 $returnCode = ($this->queue['quit'][0][1] === true ? self::RETURN_RECONNECT : self::RETURN_END); 280 } 262 281 $this->doQuit($reason); 263 282 break; 264 283 } 284 265 285 unset($this->queue, $event, $command, $arguments); 266 286 } 267 287 268 288 fclose($this->socket); 289 290 return $returnCode; 269 291 } 270 292 … … 299 321 * 300 322 * @param string $reason Reason for connection termination (optional) 301 */ 302 public function doQuit($reason = null) 303 { 304 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason)); 323 * @param bool $reconnect if true, the bot will reconnect to the server 324 */ 325 public function doQuit($reason = null, $reconnect = false) 326 { 327 $this->send(Phergie_Event_Request::TYPE_QUIT, array($reason, $reconnect)); 305 328 } 306 329 trunk/Phergie/Plugin/Abstract/AdminCommand.php
r78 r96 96 96 // Escape regex meta characters 97 97 $admin = str_replace( 98 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{','}'),98 array('\\', '^', '$', '.', '[', ']', '|', '(', ')', '?', '+', '{', '}'), 99 99 array('\\\\', '\\^', '\\$', '\\.', '\\[', '\\]', '\\|', '\\(', '\\)', '\\?', '\\+', '\\{', '\\}'), 100 100 $admin … … 110 110 * Returns whether or not the plugin's dependencies are met. 111 111 * 112 * @param array $plugins List of short names for plugins that the 112 * @param array $plugins List of short names for plugins that the 113 113 * bootstrap file intends to instantiate 114 114 * @return bool TRUE if the plugins dependencies are met, FALSE otherwise trunk/Phergie/phergie.ini
r93 r96 29 29 password = 30 30 31 ; keepalive : 32 ; boolean flag indicating whether or not the bot should reconnect when it 33 ; gets disconnected from the server, defaults to false. 34 ; if this is set to true, you should set timeout value to 6 or above. 35 keepalive = false 36 37 ; timeout : 38 ; defines the number of minutes to wait until a connection times out, if the 39 ; bot gets disconnected when it shouldn't (i.e. when your connection didn't 40 ; die), increase the timeout value so it waits longer before disconnecting. 41 ; 0 means it will never time out, but if you use keepalive you should set 42 ; this to 6 or above. 43 timeout = 44 31 45 ; gender : 32 46 ; M or F to indicate the gender of the bot for instances when the bot must … … 37 51 ; boolean flag indicating whether or not the bot is allowed to use curses, 38 52 ; bad words, etc. defaults to false. 39 curses = 53 curses = false 40 54 41 55 ; plugins : … … 50 64 ; class would be Autojoin) 51 65 ; plugins = all 52 plugins = all66 plugins = "all" 53 67 54 68 ; debug : … … 57 71 58 72 ; log : 59 ; path to a file to which debugging output will be written if debugging 73 ; path to a file to which debugging output will be written if debugging 60 74 ; mode is enabled 61 75 log = debug.log … … 68 82 ; positive integer indicating the maximum number of possible meanings for 69 83 ; an acronym that should be displayed in a given instance (defaults to 5) 70 acronym.limit = 84 acronym.limit = 5 71 85 72 86 ; acronym.filter : 73 87 ; comma- or space-delimited list of acronyms for which meanings should not 74 88 ; be returned 75 acronym.filter = 89 acronym.filter = "" 76 90 77 91 ;----------------------------------------------------------------------------- … … 83 97 ; bot's admin features, must be enclosed by double quotes and entries are 84 98 ; separated by spaces or commas 85 admincommand.admins = 99 admincommand.admins = "" 86 100 87 101 ; admincommand.ops : … … 106 120 ; a comma-delimited list of channels which the bot should automatically 107 121 ; join upon successfully connecting 108 autojoin.channels = 122 autojoin.channels = "" 109 123 110 124 ;----------------------------------------------------------------------------- … … 146 160 ; karma.static : 147 161 ; If non-empty, the static karma response to use for the bot's nick 148 karma.static = 162 karma.static = "" 149 163 150 164 ;-----------------------------------------------------------------------------