forked from GNUsocial/gnu-social
Added some more event handlers and corrected aADL scope
This commit is contained in:
parent
0083e58db3
commit
f3c1e9da9a
@ -112,6 +112,7 @@ class MSN {
|
|||||||
// Begin added for StatusNet
|
// Begin added for StatusNet
|
||||||
|
|
||||||
private $aContactList = array();
|
private $aContactList = array();
|
||||||
|
private $aADL = array();
|
||||||
private $switchBoardSessions = 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 = "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);
|
$msg_header_len = strlen($msg_header);
|
||||||
if ($network == 1)
|
if ($network == 1)
|
||||||
$maxlen = $this->max_msn_message_len - $msg_header_len;
|
$maxlen = $this->max_msn_message_len - $msg_header_len;
|
||||||
else
|
else
|
||||||
$maxlen = $this->max_yahoo_message_len - $msg_header_len;
|
$maxlen = $this->max_yahoo_message_len - $msg_header_len;
|
||||||
$sMessage=str_replace("\r", '', $sMessage);
|
$sMessage=str_replace("\r", '', $sMessage);
|
||||||
$msg=substr($sMessage,0,$maxlen);
|
$msg=substr($sMessage,0,$maxlen);
|
||||||
return $msg_header.$msg;
|
return $msg_header.$msg;
|
||||||
@ -3004,7 +3005,8 @@ X-OIM-Sequence-Num: 1
|
|||||||
while(!$this->connect($this->user, $this->password))
|
while(!$this->connect($this->user, $this->password))
|
||||||
{
|
{
|
||||||
$this->log_message("!!! Can't connect to server: $this->error");
|
$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->UpdateContacts();
|
||||||
$this->LastPing=time();
|
$this->LastPing=time();
|
||||||
@ -3061,7 +3063,7 @@ X-OIM-Sequence-Num: 1
|
|||||||
$str = '<d n="'.$u_domain.'">';
|
$str = '<d n="'.$u_domain.'">';
|
||||||
$len += strlen($str);
|
$len += strlen($str);
|
||||||
if ($len > 7400) {
|
if ($len > 7400) {
|
||||||
$aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
$this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
||||||
$n++;
|
$n++;
|
||||||
$sList = '';
|
$sList = '';
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
@ -3075,7 +3077,7 @@ X-OIM-Sequence-Num: 1
|
|||||||
// so we use 7475
|
// so we use 7475
|
||||||
if ($len > 7475) {
|
if ($len > 7475) {
|
||||||
$sList .= '</d>';
|
$sList .= '</d>';
|
||||||
$aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
$this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
||||||
$n++;
|
$n++;
|
||||||
$sList = '<d n="'.$u_domain.'">'.$str;
|
$sList = '<d n="'.$u_domain.'">'.$str;
|
||||||
$len = strlen($sList);
|
$len = strlen($sList);
|
||||||
@ -3087,10 +3089,10 @@ X-OIM-Sequence-Num: 1
|
|||||||
$sList .= '</d>';
|
$sList .= '</d>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
$this->aADL[$n] = '<ml l="1">'.$sList.'</ml>';
|
||||||
// NS: >>> BLP {id} BL
|
// NS: >>> BLP {id} BL
|
||||||
$this->ns_writeln("BLP $this->id BL");
|
$this->ns_writeln("BLP $this->id BL");
|
||||||
foreach ($aADL as $str) {
|
foreach ($this->aADL as $str) {
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
// NS: >>> ADL {id} {size}
|
// NS: >>> ADL {id} {size}
|
||||||
$this->ns_writeln("ADL $this->id $len");
|
$this->ns_writeln("ADL $this->id $len");
|
||||||
@ -3116,16 +3118,16 @@ X-OIM-Sequence-Num: 1
|
|||||||
public function NSreceive() {
|
public function NSreceive() {
|
||||||
$this->log_message("*** startup ***");
|
$this->log_message("*** startup ***");
|
||||||
|
|
||||||
$aADL = array();
|
|
||||||
|
|
||||||
// Sign in again if not signed in or socket failed
|
// Sign in again if not signed in or socket failed
|
||||||
if (!is_resource($this->NSfp) || feof($this->NSfp)) {
|
if (!is_resource($this->NSfp) || feof($this->NSfp)) {
|
||||||
|
$this->callHandler('Reconnect', NULL);
|
||||||
$this->signon();
|
$this->signon();
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $this->ns_readln();
|
$data = $this->ns_readln();
|
||||||
if($data === false) {
|
if($data === false) {
|
||||||
// There was no data / an error when reading from the socket so reconnect
|
// There was no data / an error when reading from the socket so reconnect
|
||||||
|
$this->callHandler('Reconnect', NULL);
|
||||||
$this->signon();
|
$this->signon();
|
||||||
} else {
|
} else {
|
||||||
switch (substr($data,0,3))
|
switch (substr($data,0,3))
|
||||||
@ -3139,8 +3141,8 @@ X-OIM-Sequence-Num: 1
|
|||||||
// FIXME:
|
// FIXME:
|
||||||
// NS: <<< RFS ???
|
// NS: <<< RFS ???
|
||||||
// refresh ADL, so we re-send it again
|
// refresh ADL, so we re-send it again
|
||||||
if (is_array($aADL)) {
|
if (is_array($this->aADL)) {
|
||||||
foreach ($aADL as $str) {
|
foreach ($this->aADL as $str) {
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
// NS: >>> ADL {id} {size}
|
// NS: >>> ADL {id} {size}
|
||||||
$this->ns_writeln("ADL $this->id $len");
|
$this->ns_writeln("ADL $this->id $len");
|
||||||
@ -3701,8 +3703,6 @@ X-OIM-Sequence-Num: 1
|
|||||||
private function callHandler($event, $data) {
|
private function callHandler($event, $data) {
|
||||||
if (isset($this->myEventHandlers[$event])) {
|
if (isset($this->myEventHandlers[$event])) {
|
||||||
call_user_func($this->myEventHandlers[$event], $data);
|
call_user_func($this->myEventHandlers[$event], $data);
|
||||||
} else {
|
|
||||||
$this->noHandler($data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3710,7 +3710,7 @@ X-OIM-Sequence-Num: 1
|
|||||||
* Registers a user handler
|
* Registers a user handler
|
||||||
*
|
*
|
||||||
* Handler List
|
* Handler List
|
||||||
* IMIn, Pong
|
* IMIn, Pong, ConnectFailed, Reconnect
|
||||||
*
|
*
|
||||||
* @param String $event Event name
|
* @param String $event Event name
|
||||||
* @param String $handler User function to call
|
* @param String $handler User function to call
|
||||||
|
@ -99,6 +99,8 @@ 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->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->conn->signon();
|
||||||
$this->lastping = time();
|
$this->lastping = time();
|
||||||
}
|
}
|
||||||
@ -132,6 +134,14 @@ class MsnManager extends ImManager
|
|||||||
return true;
|
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)
|
function send_raw_message($data)
|
||||||
{
|
{
|
||||||
$this->connect();
|
$this->connect();
|
||||||
|
Loading…
Reference in New Issue
Block a user