]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added some more event handlers and corrected aADL scope
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 13 Jun 2010 03:14:29 +0000 (04:14 +0100)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 13 Jun 2010 03:14:29 +0000 (04:14 +0100)
plugins/Msn/extlib/phpmsnclass/msn.class.php
plugins/Msn/msnmanager.php

index ef4f45b44158ecec174c82c0605b9a879b7f21de..36b47f8e9c749e06cb01ab446dfbd49262a6b0bc 100644 (file)
@@ -112,6 +112,7 @@ class MSN {
     // Begin added for StatusNet\r
     \r
     private $aContactList = array();\r
+    private $aADL = array();\r
     private $switchBoardSessions = array();\r
     \r
     /**\r
@@ -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";\r
         $msg_header_len = strlen($msg_header);\r
         if ($network == 1)\r
-        $maxlen = $this->max_msn_message_len - $msg_header_len;\r
+            $maxlen = $this->max_msn_message_len - $msg_header_len;\r
         else\r
-        $maxlen = $this->max_yahoo_message_len - $msg_header_len;\r
+            $maxlen = $this->max_yahoo_message_len - $msg_header_len;\r
         $sMessage=str_replace("\r", '', $sMessage);\r
         $msg=substr($sMessage,0,$maxlen);\r
         return $msg_header.$msg;\r
@@ -3004,7 +3005,8 @@ X-OIM-Sequence-Num: 1
         while(!$this->connect($this->user, $this->password))\r
         {\r
             $this->log_message("!!! Can't connect to server: $this->error");\r
-            if(!$this->NSRetryWait($this->retry_wait)) return;\r
+            $this->callHandler('ConnectFailed', NULL);\r
+            $this->NSRetryWait($this->retry_wait);\r
         }\r
         $this->UpdateContacts();\r
         $this->LastPing=time();\r
@@ -3061,7 +3063,7 @@ X-OIM-Sequence-Num: 1
                 $str = '<d n="'.$u_domain.'">';\r
                 $len += strlen($str);\r
                 if ($len > 7400) {\r
-                    $aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+                    $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
                     $n++;\r
                     $sList = '';\r
                     $len = strlen($str);\r
@@ -3075,7 +3077,7 @@ X-OIM-Sequence-Num: 1
                         // so we use 7475\r
                         if ($len > 7475) {\r
                             $sList .= '</d>';\r
-                            $aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+                            $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
                             $n++;\r
                             $sList = '<d n="'.$u_domain.'">'.$str;\r
                             $len = strlen($sList);\r
@@ -3087,10 +3089,10 @@ X-OIM-Sequence-Num: 1
                 $sList .= '</d>';\r
             }\r
         }\r
-        $aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
+        $this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';\r
         // NS: >>> BLP {id} BL\r
         $this->ns_writeln("BLP $this->id BL");\r
-        foreach ($aADL as $str) {\r
+        foreach ($this->aADL as $str) {\r
             $len = strlen($str);\r
             // NS: >>> ADL {id} {size}\r
             $this->ns_writeln("ADL $this->id $len");\r
@@ -3116,16 +3118,16 @@ X-OIM-Sequence-Num: 1
     public function NSreceive() {\r
         $this->log_message("*** startup ***");\r
         \r
-        $aADL = array();\r
-        \r
         // Sign in again if not signed in or socket failed\r
         if (!is_resource($this->NSfp) || feof($this->NSfp)) {\r
+            $this->callHandler('Reconnect', NULL);\r
             $this->signon();\r
         }\r
         \r
         $data = $this->ns_readln();\r
         if($data === false) {\r
             // There was no data / an error when reading from the socket so reconnect\r
+            $this->callHandler('Reconnect', NULL);\r
             $this->signon();\r
         } else {\r
             switch (substr($data,0,3))\r
@@ -3139,8 +3141,8 @@ X-OIM-Sequence-Num: 1
                     // FIXME:\r
                     // NS: <<< RFS ???\r
                     // refresh ADL, so we re-send it again\r
-                    if (is_array($aADL)) {\r
-                        foreach ($aADL as $str) {\r
+                    if (is_array($this->aADL)) {\r
+                        foreach ($this->aADL as $str) {\r
                             $len = strlen($str);\r
                             // NS: >>> ADL {id} {size}\r
                             $this->ns_writeln("ADL $this->id $len");\r
@@ -3701,8 +3703,6 @@ X-OIM-Sequence-Num: 1
     private function callHandler($event, $data) {\r
         if (isset($this->myEventHandlers[$event])) {\r
             call_user_func($this->myEventHandlers[$event], $data);\r
-        } else {\r
-            $this->noHandler($data);\r
         }\r
     }\r
     \r
@@ -3710,7 +3710,7 @@ X-OIM-Sequence-Num: 1
      * Registers a user handler\r
      * \r
      * Handler List\r
-     * IMIn, Pong\r
+     * IMIn, Pong, ConnectFailed, Reconnect\r
      *\r
      * @param String $event Event name\r
      * @param String $handler User function to call\r
index 1ef496f56f39219f73e4a83753e7afdeca1920b0..354ed0f3ef45cc597533fff17a1048d4d1434199 100644 (file)
@@ -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)
     {