More work on adapting the phpmsnclass to work with the IM architecture (far from finished still)
This commit is contained in:
parent
d97b598214
commit
89808a86d5
@ -3203,13 +3203,6 @@ X-OIM-Sequence-Num: 1
|
|||||||
$data = $this->ns_readln();
|
$data = $this->ns_readln();
|
||||||
/*if($data===false)
|
/*if($data===false)
|
||||||
{
|
{
|
||||||
//If No NS Message Process SendMessageFileQueue
|
|
||||||
if (time()-$this->LastPing > $this->ping_wait)
|
|
||||||
{
|
|
||||||
// NS: >>> PNG
|
|
||||||
$this->ns_writeln("PNG");
|
|
||||||
$this->LastPing = time();
|
|
||||||
}
|
|
||||||
if(count($this->ChildProcess)<$this->MAXChildProcess)
|
if(count($this->ChildProcess)<$this->MAXChildProcess)
|
||||||
{
|
{
|
||||||
$Index=0;
|
$Index=0;
|
||||||
@ -3626,8 +3619,8 @@ 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 */, $this->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
|
||||||
break;
|
break;
|
||||||
@ -3682,31 +3675,100 @@ X-OIM-Sequence-Num: 1
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SendMessage($Message, $To) {
|
public function sendMessageViaSB($message, $to) {
|
||||||
if(!is_array($To))
|
$socket = $this->switchBoardSessions[$to]['socket'];
|
||||||
$To=array($To);
|
$lastActive = $this->switchBoardSessions[$to]['lastActive'];
|
||||||
$Receiver='';
|
$joined = $this->switchBoardSessions[$to]['joined'];
|
||||||
foreach($To as $Email)
|
|
||||||
|
//TODO Probably not needed (we're not running in a loop anymore)
|
||||||
|
/*if($this->kill_me)
|
||||||
{
|
{
|
||||||
list($name,$host,$network)=explode('@',$Email);
|
$this->log_message("*** SB Okay, kill me now!");
|
||||||
$network=$network==''?1:$network;
|
endSBSession($socket);
|
||||||
if($network==1 && isset($this->switchBoardSessions[$Email]) ) {
|
}*/
|
||||||
$this->debug_message("*** SendMessage to $Receiver use SB message queue.");
|
|
||||||
array_push($this->SwitchBoardMessageQueue,$Message);
|
if(!$Joined) {
|
||||||
continue;
|
// If our participant has not joined the session yet we can't message them!
|
||||||
}
|
//TODO Check the behaviour of the queue runner when we return false
|
||||||
$Receiver.="$name@$host@$network,";
|
return false;
|
||||||
}
|
}
|
||||||
if($Receiver=='') return;
|
|
||||||
$Receiver=substr($Receiver,0,-1);
|
$aMessage = $this->getMessage($Message);
|
||||||
$this->debug_message("*** SendMessage to $Receiver use File queue.");
|
//CheckEmotion...
|
||||||
file_put_contents($FileName,"TO: $Receiver\n$Message\n");
|
$MsnObjDefine=$this->GetMsnObjDefine($aMessage);
|
||||||
|
if($MsnObjDefine !== '')
|
||||||
|
{
|
||||||
|
$SendString="MIME-Version: 1.0\r\nContent-Type: text/x-mms-emoticon\r\n\r\n$MsnObjDefine";
|
||||||
|
$len = strlen($SendString);
|
||||||
|
$this->SB_writeln("MSG $id N $len");
|
||||||
|
$id++;
|
||||||
|
$this->SB_writedata($SendString);
|
||||||
|
$this->id++;
|
||||||
|
}
|
||||||
|
$len = strlen($aMessage);
|
||||||
|
$this->SB_writeln("MSG $id N $len");
|
||||||
|
|
||||||
|
// Increment the trID
|
||||||
|
$this->switchBoardSessions[$to]['id']++;
|
||||||
|
|
||||||
|
$this->SB_writedata($aMessage);
|
||||||
|
|
||||||
|
if (feof($this->SBFp))
|
||||||
|
{
|
||||||
|
// lost connection? error? try OIM later
|
||||||
|
@fclose($this->SBFp);
|
||||||
|
//TODO introduce callback to add offline message to queue?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->SB_writeln("OUT");
|
||||||
|
@fclose($this->SBFp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO Not sure if this is needed?
|
||||||
|
private function endSBSession($socket) {
|
||||||
|
if (feof($this->SBFp))
|
||||||
|
{
|
||||||
|
// lost connection? error? try OIM later
|
||||||
|
@fclose($this->SBFp);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$this->SB_writeln("OUT");
|
||||||
|
@fclose($this->SBFp);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendMessage($message, $to) {
|
||||||
|
if($message != '') {
|
||||||
|
list($name,$host,$network)=explode('@',$to);
|
||||||
|
$network=$network==''?1:$network;
|
||||||
|
|
||||||
|
if($network === 1 && isset($this->switchBoardSessions[$to])) {
|
||||||
|
$recipient = $name . $host;
|
||||||
|
$this->debug_message("*** Sending Message to $recipient using existing SB session");
|
||||||
|
$this->sendMessageViaSB($message, $recipient);
|
||||||
|
} else {
|
||||||
|
$this->debug_message("*** Not MSN network or no existing SB session");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a ping command
|
||||||
|
*
|
||||||
|
* Should be called about every 50 seconds
|
||||||
|
*/
|
||||||
|
public function send_ping() {
|
||||||
|
// NS: >>> PNG
|
||||||
|
$this->ns_writeln("PNG");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNSSocket() {
|
public function getNSSocket() {
|
||||||
return $this->NSfp;
|
return $this->NSfp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO Allow for multiple SB session sockets
|
||||||
public function getSBSocket() {
|
public function getSBSocket() {
|
||||||
return $this->SBfp;
|
return $this->SBfp;
|
||||||
}
|
}
|
||||||
|
@ -32,8 +32,12 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
|||||||
|
|
||||||
class MsnManager extends ImManager
|
class MsnManager extends ImManager
|
||||||
{
|
{
|
||||||
|
|
||||||
public $conn = null;
|
public $conn = null;
|
||||||
|
|
||||||
|
protected $lastping = null;
|
||||||
|
|
||||||
|
const PING_INTERVAL = 50;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize connection to server.
|
* Initialize connection to server.
|
||||||
* @return boolean true on success
|
* @return boolean true on success
|
||||||
@ -58,9 +62,21 @@ class MsnManager extends ImManager
|
|||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process AIM events that have come in over the wire.
|
* Idle processing for io manager's execution loop.
|
||||||
|
* Send keepalive pings to server.
|
||||||
|
*/
|
||||||
|
public function idle($timeout=0)
|
||||||
|
{
|
||||||
|
$now = time();
|
||||||
|
if (empty($this->lastping) || $now - $this->lastping > self::PING_INTERVAL) {
|
||||||
|
$this->send_ping();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process MSN events that have come in over the wire.
|
||||||
* @param resource $socket
|
* @param resource $socket
|
||||||
*/
|
*/
|
||||||
public function handleInput($socket)
|
public function handleInput($socket)
|
||||||
@ -83,10 +99,24 @@ class MsnManager extends ImManager
|
|||||||
);
|
);
|
||||||
$this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
|
$this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
|
||||||
$this->conn->signon();
|
$this->conn->signon();
|
||||||
|
$this->lastping = time();
|
||||||
}
|
}
|
||||||
return $this->conn;
|
return $this->conn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function send_ping() {
|
||||||
|
$this->connect();
|
||||||
|
if (!$this->conn) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$this->conn->send_ping();
|
||||||
|
$this->lastping = $now;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function handle_msn_message($data)
|
function handle_msn_message($data)
|
||||||
{
|
{
|
||||||
$this->plugin->enqueue_incoming_raw($data);
|
$this->plugin->enqueue_incoming_raw($data);
|
||||||
|
Loading…
Reference in New Issue
Block a user