]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Added callback for pong (to update time till next ping required)
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 13 Jun 2010 00:54:09 +0000 (01:54 +0100)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Sun, 13 Jun 2010 00:54:09 +0000 (01:54 +0100)
plugins/Msn/extlib/phpmsnclass/msn.class.php
plugins/Msn/msnmanager.php

index b230e346f75d88962bde78c32ad2735797137d85..65525fe5565893384c522a4e891b37694cc23452 100644 (file)
@@ -1573,7 +1573,7 @@ class MSN {
                     // NS: >>> CHG {id} {status} {clientid} {msnobj}\r
                     $this->ns_writeln("CHG $this->id NLN $this->clientid");                    \r
                     if($this->PhotoStickerFile!==false)\r
-                     $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
                     // NS: >>> UUX {id} length\r
                     $str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>';\r
                     $len = strlen($str);\r
@@ -1935,7 +1935,7 @@ class MSN {
                     $this->ns_writedata($fingerprint);\r
                     $this->ns_writeln("CHG $this->id NLN $this->clientid");                    \r
                     if($this->PhotoStickerFile!==false)\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
                     break;\r
                 case 'CHG':\r
                     // NS: <<< CHG {id} {status} {code}\r
@@ -2012,9 +2012,9 @@ class MSN {
 \r
                 case 'RNG':\r
                     if($this->PhotoStickerFile!==false)\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
                     else\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
                     // someone is trying to talk to us\r
                     // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0\r
                     $this->log_message("NS: <<< RNG $data");\r
@@ -2022,8 +2022,8 @@ class MSN {
                     @list($sb_ip, $sb_port) = @explode(':', $server);\r
                     if($this->IsIgnoreMail($email)) \r
                     {\r
-                     $this->log_message("*** Ignore RNG from $email");\r
-                     break;   \r
+                        $this->log_message("*** Ignore RNG from $email");\r
+                        break;\r
                     }\r
                     $this->log_message("*** RING from $email, $sb_ip:$sb_port");\r
                     $this->addContact($email,1,$email, true);\r
@@ -3455,7 +3455,7 @@ X-OIM-Sequence-Num: 1
                     $this->ns_writedata($fingerprint);\r
                     $this->ns_writeln("CHG $this->id NLN $this->clientid");                    \r
                     if($this->PhotoStickerFile!==false)\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
                     break;\r
                 case 'CHG':\r
                     // NS: <<< CHG {id} {status} {code}\r
@@ -3524,17 +3524,19 @@ X-OIM-Sequence-Num: 1
                     break;\r
                 case 'QNG':\r
                     // NS: <<< QNG {time}\r
-                    //@list(/* QNG */, $this->ping_wait) = @explode(' ', $data);\r
+                    @list(/* QNG */, $ping_wait) = @explode(' ', $data);\r
                     //if ($this->ping_wait == 0) $this->ping_wait = 50;\r
                     //if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping;\r
                     //Mod by Ricky Set Online\r
+                    \r
+                    $this->callHandler('Pong', $ping_wait);\r
                     break;\r
     \r
                 case 'RNG':\r
                     if($this->PhotoStickerFile!==false)\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile)));\r
                     else\r
-                    $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
+                        $this->ns_writeln("CHG $this->id NLN $this->clientid");\r
                     // someone is trying to talk to us\r
                     // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0\r
                     $this->log_message("NS: <<< RNG $data");\r
@@ -3711,7 +3713,7 @@ X-OIM-Sequence-Num: 1
      * Registers a user handler\r
      * \r
      * Handler List\r
-     * IMIn\r
+     * IMIn, Pong\r
      *\r
      * @param String $event Event name\r
      * @param String $handler User function to call\r
index aae6906d6c9643fd45da58126a586fc4f6103831..99ac2191574035c5c983d3903552007c5c71ee91 100644 (file)
@@ -36,7 +36,7 @@ class MsnManager extends ImManager
     
     protected $lastping = null;
     
-    const PING_INTERVAL = 50;
+    private $pingInterval;
     
     /**
      * Initialize connection to server.
@@ -70,7 +70,7 @@ class MsnManager extends ImManager
     public function idle($timeout=0)
     {
         $now = time();
-        if (empty($this->lastping) || $now - $this->lastping > self::PING_INTERVAL) {
+        if (empty($this->lastping) || $now - $this->lastping > $pingInterval) {
             $this->send_ping();
         }
     }
@@ -98,6 +98,7 @@ class MsnManager extends ImManager
                                 )
                         );
             $this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
+            $this->conn->registerHandler('Pong', array($this, 'update_ping_time'));
             $this->conn->signon();
             $this->lastping = time();
         }
@@ -117,6 +118,14 @@ class MsnManager extends ImManager
         return true;
     }
     
+    /**
+     * Update the time till the next ping
+     * @param $data Time till next ping
+     */
+    function update_ping_time($data) {
+        $pingInterval = $data;
+    }
+    
     function handle_msn_message($data)
     {
         $this->plugin->enqueue_incoming_raw($data);