From dc66503f33929c2218a8f05151075329fac5005a Mon Sep 17 00:00:00 2001 From: Luke Fitzgerald Date: Sun, 13 Jun 2010 01:54:09 +0100 Subject: [PATCH] Added callback for pong (to update time till next ping required) --- plugins/Msn/extlib/phpmsnclass/msn.class.php | 24 +++++++++++--------- plugins/Msn/msnmanager.php | 13 +++++++++-- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/plugins/Msn/extlib/phpmsnclass/msn.class.php b/plugins/Msn/extlib/phpmsnclass/msn.class.php index b230e346f7..65525fe556 100644 --- a/plugins/Msn/extlib/phpmsnclass/msn.class.php +++ b/plugins/Msn/extlib/phpmsnclass/msn.class.php @@ -1573,7 +1573,7 @@ class MSN { // NS: >>> CHG {id} {status} {clientid} {msnobj} $this->ns_writeln("CHG $this->id NLN $this->clientid"); if($this->PhotoStickerFile!==false) - $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); + $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); // NS: >>> UUX {id} length $str = ''.htmlspecialchars($this->psm).''; $len = strlen($str); @@ -1935,7 +1935,7 @@ class MSN { $this->ns_writedata($fingerprint); $this->ns_writeln("CHG $this->id NLN $this->clientid"); if($this->PhotoStickerFile!==false) - $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); + $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); break; case 'CHG': // NS: <<< CHG {id} {status} {code} @@ -2012,9 +2012,9 @@ class MSN { case 'RNG': if($this->PhotoStickerFile!==false) - $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); + $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); else - $this->ns_writeln("CHG $this->id NLN $this->clientid"); + $this->ns_writeln("CHG $this->id NLN $this->clientid"); // someone is trying to talk to us // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0 $this->log_message("NS: <<< RNG $data"); @@ -2022,8 +2022,8 @@ class MSN { @list($sb_ip, $sb_port) = @explode(':', $server); if($this->IsIgnoreMail($email)) { - $this->log_message("*** Ignore RNG from $email"); - break; + $this->log_message("*** Ignore RNG from $email"); + break; } $this->log_message("*** RING from $email, $sb_ip:$sb_port"); $this->addContact($email,1,$email, true); @@ -3455,7 +3455,7 @@ X-OIM-Sequence-Num: 1 $this->ns_writedata($fingerprint); $this->ns_writeln("CHG $this->id NLN $this->clientid"); if($this->PhotoStickerFile!==false) - $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); + $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); break; case 'CHG': // NS: <<< CHG {id} {status} {code} @@ -3524,17 +3524,19 @@ X-OIM-Sequence-Num: 1 break; case 'QNG': // NS: <<< QNG {time} - //@list(/* QNG */, $this->ping_wait) = @explode(' ', $data); + @list(/* QNG */, $ping_wait) = @explode(' ', $data); //if ($this->ping_wait == 0) $this->ping_wait = 50; //if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping; //Mod by Ricky Set Online + + $this->callHandler('Pong', $ping_wait); break; case 'RNG': if($this->PhotoStickerFile!==false) - $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); + $this->ns_writeln("CHG $this->id NLN $this->clientid ".rawurlencode($this->MsnObj($this->PhotoStickerFile))); else - $this->ns_writeln("CHG $this->id NLN $this->clientid"); + $this->ns_writeln("CHG $this->id NLN $this->clientid"); // someone is trying to talk to us // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0 $this->log_message("NS: <<< RNG $data"); @@ -3711,7 +3713,7 @@ X-OIM-Sequence-Num: 1 * Registers a user handler * * Handler List - * IMIn + * IMIn, Pong * * @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 aae6906d6c..99ac219157 100644 --- a/plugins/Msn/msnmanager.php +++ b/plugins/Msn/msnmanager.php @@ -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);