From: Luke Fitzgerald Date: Sun, 13 Jun 2010 03:14:29 +0000 (+0100) Subject: Added some more event handlers and corrected aADL scope X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f3c1e9da9a0784dc3e071ad8610f701197ab0c84;p=quix0rs-gnu-social.git Added some more event handlers and corrected aADL scope --- diff --git a/plugins/Msn/extlib/phpmsnclass/msn.class.php b/plugins/Msn/extlib/phpmsnclass/msn.class.php index ef4f45b441..36b47f8e9c 100644 --- a/plugins/Msn/extlib/phpmsnclass/msn.class.php +++ b/plugins/Msn/extlib/phpmsnclass/msn.class.php @@ -112,6 +112,7 @@ class MSN { // Begin added for StatusNet private $aContactList = array(); + private $aADL = array(); private $switchBoardSessions = array(); /** @@ -2172,9 +2173,9 @@ class MSN { $msg_header = "MIME-Version: 1.0\r\nContent-Type: text/plain; charset=UTF-8\r\nX-MMS-IM-Format: FN=$this->font_fn; EF=$this->font_ef; CO=$this->font_co; CS=0; PF=22\r\n\r\n"; $msg_header_len = strlen($msg_header); if ($network == 1) - $maxlen = $this->max_msn_message_len - $msg_header_len; + $maxlen = $this->max_msn_message_len - $msg_header_len; else - $maxlen = $this->max_yahoo_message_len - $msg_header_len; + $maxlen = $this->max_yahoo_message_len - $msg_header_len; $sMessage=str_replace("\r", '', $sMessage); $msg=substr($sMessage,0,$maxlen); return $msg_header.$msg; @@ -3004,7 +3005,8 @@ X-OIM-Sequence-Num: 1 while(!$this->connect($this->user, $this->password)) { $this->log_message("!!! Can't connect to server: $this->error"); - if(!$this->NSRetryWait($this->retry_wait)) return; + $this->callHandler('ConnectFailed', NULL); + $this->NSRetryWait($this->retry_wait); } $this->UpdateContacts(); $this->LastPing=time(); @@ -3061,7 +3063,7 @@ X-OIM-Sequence-Num: 1 $str = ''; $len += strlen($str); if ($len > 7400) { - $aADL[$n] = ''.$sList.''; + $this->aADL[$n] = ''.$sList.''; $n++; $sList = ''; $len = strlen($str); @@ -3075,7 +3077,7 @@ X-OIM-Sequence-Num: 1 // so we use 7475 if ($len > 7475) { $sList .= ''; - $aADL[$n] = ''.$sList.''; + $this->aADL[$n] = ''.$sList.''; $n++; $sList = ''.$str; $len = strlen($sList); @@ -3087,10 +3089,10 @@ X-OIM-Sequence-Num: 1 $sList .= ''; } } - $aADL[$n] = ''.$sList.''; + $this->aADL[$n] = ''.$sList.''; // NS: >>> BLP {id} BL $this->ns_writeln("BLP $this->id BL"); - foreach ($aADL as $str) { + foreach ($this->aADL as $str) { $len = strlen($str); // NS: >>> ADL {id} {size} $this->ns_writeln("ADL $this->id $len"); @@ -3116,16 +3118,16 @@ X-OIM-Sequence-Num: 1 public function NSreceive() { $this->log_message("*** startup ***"); - $aADL = array(); - // Sign in again if not signed in or socket failed if (!is_resource($this->NSfp) || feof($this->NSfp)) { + $this->callHandler('Reconnect', NULL); $this->signon(); } $data = $this->ns_readln(); if($data === false) { // There was no data / an error when reading from the socket so reconnect + $this->callHandler('Reconnect', NULL); $this->signon(); } else { switch (substr($data,0,3)) @@ -3139,8 +3141,8 @@ X-OIM-Sequence-Num: 1 // FIXME: // NS: <<< RFS ??? // refresh ADL, so we re-send it again - if (is_array($aADL)) { - foreach ($aADL as $str) { + if (is_array($this->aADL)) { + foreach ($this->aADL as $str) { $len = strlen($str); // NS: >>> ADL {id} {size} $this->ns_writeln("ADL $this->id $len"); @@ -3701,8 +3703,6 @@ X-OIM-Sequence-Num: 1 private function callHandler($event, $data) { if (isset($this->myEventHandlers[$event])) { call_user_func($this->myEventHandlers[$event], $data); - } else { - $this->noHandler($data); } } @@ -3710,7 +3710,7 @@ X-OIM-Sequence-Num: 1 * Registers a user handler * * Handler List - * IMIn, Pong + * IMIn, Pong, ConnectFailed, Reconnect * * @param String $event Event name * @param String $handler User function to call diff --git a/plugins/Msn/msnmanager.php b/plugins/Msn/msnmanager.php index 1ef496f56f..354ed0f3ef 100644 --- a/plugins/Msn/msnmanager.php +++ b/plugins/Msn/msnmanager.php @@ -99,6 +99,8 @@ class MsnManager extends ImManager ); $this->conn->registerHandler("IMIn", array($this, 'handle_msn_message')); $this->conn->registerHandler('Pong', array($this, 'update_ping_time')); + $this->conn->registerHandler('ConnectFailed', array($this, 'handle_connect_failed')); + $this->conn->registerHandler('Reconnect', array($this, 'handle_reconnect')); $this->conn->signon(); $this->lastping = time(); } @@ -131,6 +133,14 @@ class MsnManager extends ImManager $this->plugin->enqueue_incoming_raw($data); return true; } + + function handle_connect_failed($data) { + common_log(LOG_NOTICE, 'MSN connect failed, retrying'); + } + + function handle_reconnect($data) { + common_log(LOG_NOTICE, 'MSN reconnecting'); + } function send_raw_message($data) {