Added callback for pong (to update time till next ping required)

This commit is contained in:
Luke Fitzgerald 2010-06-13 01:54:09 +01:00
parent 4007bce9aa
commit dc66503f33
2 changed files with 24 additions and 13 deletions

View File

@ -1573,7 +1573,7 @@ class MSN {
// NS: >>> CHG {id} {status} {clientid} {msnobj} // NS: >>> CHG {id} {status} {clientid} {msnobj}
$this->ns_writeln("CHG $this->id NLN $this->clientid"); $this->ns_writeln("CHG $this->id NLN $this->clientid");
if($this->PhotoStickerFile!==false) 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 // NS: >>> UUX {id} length
$str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>'; $str = '<Data><PSM>'.htmlspecialchars($this->psm).'</PSM><CurrentMedia></CurrentMedia><MachineGuid></MachineGuid></Data>';
$len = strlen($str); $len = strlen($str);
@ -1935,7 +1935,7 @@ class MSN {
$this->ns_writedata($fingerprint); $this->ns_writedata($fingerprint);
$this->ns_writeln("CHG $this->id NLN $this->clientid"); $this->ns_writeln("CHG $this->id NLN $this->clientid");
if($this->PhotoStickerFile!==false) 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; break;
case 'CHG': case 'CHG':
// NS: <<< CHG {id} {status} {code} // NS: <<< CHG {id} {status} {code}
@ -2012,9 +2012,9 @@ class MSN {
case 'RNG': case 'RNG':
if($this->PhotoStickerFile!==false) 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 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 // someone is trying to talk to us
// NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0 // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0
$this->log_message("NS: <<< RNG $data"); $this->log_message("NS: <<< RNG $data");
@ -2022,8 +2022,8 @@ class MSN {
@list($sb_ip, $sb_port) = @explode(':', $server); @list($sb_ip, $sb_port) = @explode(':', $server);
if($this->IsIgnoreMail($email)) if($this->IsIgnoreMail($email))
{ {
$this->log_message("*** Ignore RNG from $email"); $this->log_message("*** Ignore RNG from $email");
break; break;
} }
$this->log_message("*** RING from $email, $sb_ip:$sb_port"); $this->log_message("*** RING from $email, $sb_ip:$sb_port");
$this->addContact($email,1,$email, true); $this->addContact($email,1,$email, true);
@ -3455,7 +3455,7 @@ X-OIM-Sequence-Num: 1
$this->ns_writedata($fingerprint); $this->ns_writedata($fingerprint);
$this->ns_writeln("CHG $this->id NLN $this->clientid"); $this->ns_writeln("CHG $this->id NLN $this->clientid");
if($this->PhotoStickerFile!==false) 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; break;
case 'CHG': case 'CHG':
// NS: <<< CHG {id} {status} {code} // NS: <<< CHG {id} {status} {code}
@ -3524,17 +3524,19 @@ X-OIM-Sequence-Num: 1
break; break;
case 'QNG': case 'QNG':
// NS: <<< QNG {time} // 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 ($this->ping_wait == 0) $this->ping_wait = 50;
//if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping; //if (is_int($use_ping) && $use_ping > 0) $ping_wait = $use_ping;
//Mod by Ricky Set Online //Mod by Ricky Set Online
$this->callHandler('Pong', $ping_wait);
break; break;
case 'RNG': case 'RNG':
if($this->PhotoStickerFile!==false) 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 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 // someone is trying to talk to us
// NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0 // NS: <<< RNG {session_id} {server} {auth_type} {ticket} {email} {alias} U {client} 0
$this->log_message("NS: <<< RNG $data"); $this->log_message("NS: <<< RNG $data");
@ -3711,7 +3713,7 @@ X-OIM-Sequence-Num: 1
* Registers a user handler * Registers a user handler
* *
* Handler List * Handler List
* IMIn * IMIn, Pong
* *
* @param String $event Event name * @param String $event Event name
* @param String $handler User function to call * @param String $handler User function to call

View File

@ -36,7 +36,7 @@ class MsnManager extends ImManager
protected $lastping = null; protected $lastping = null;
const PING_INTERVAL = 50; private $pingInterval;
/** /**
* Initialize connection to server. * Initialize connection to server.
@ -70,7 +70,7 @@ class MsnManager extends ImManager
public function idle($timeout=0) public function idle($timeout=0)
{ {
$now = time(); $now = time();
if (empty($this->lastping) || $now - $this->lastping > self::PING_INTERVAL) { if (empty($this->lastping) || $now - $this->lastping > $pingInterval) {
$this->send_ping(); $this->send_ping();
} }
} }
@ -98,6 +98,7 @@ class MsnManager extends ImManager
) )
); );
$this->conn->registerHandler("IMIn", array($this, 'handle_msn_message')); $this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
$this->conn->registerHandler('Pong', array($this, 'update_ping_time'));
$this->conn->signon(); $this->conn->signon();
$this->lastping = time(); $this->lastping = time();
} }
@ -117,6 +118,14 @@ class MsnManager extends ImManager
return true; 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) function handle_msn_message($data)
{ {
$this->plugin->enqueue_incoming_raw($data); $this->plugin->enqueue_incoming_raw($data);