3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
23 * AIM background connection manager for AIM-using queue handlers,
24 * allowing them to send outgoing messages on the right connection.
26 * Input is handled during socket select loop, keepalive pings during idle.
27 * Any incoming messages will be handled.
29 * In a multi-site queuedaemon.php run, one connection will be instantiated
30 * for each site being handled by the current process that has XMPP enabled.
33 class MsnManager extends ImManager
37 protected $lastping = null;
39 private $pingInterval;
42 * Initialize connection to server.
43 * @return boolean true on success
45 public function start($master)
47 if(parent::start($master))
56 public function getSockets()
60 return $this->conn->getSockets();
67 * Idle processing for io manager's execution loop.
68 * Send keepalive pings to server.
70 public function idle($timeout=0)
73 if (empty($this->lastping) || $now - $this->lastping > $pingInterval) {
79 * Process MSN events that have come in over the wire.
80 * @param resource $socket
82 public function handleInput($socket)
84 common_log(LOG_DEBUG, "Servicing the MSN queue.");
85 $this->stats('msn_process');
86 $this->conn->receive();
92 $this->conn=new MSN(array(
93 'user' => $this->plugin->user,
94 'password' => $this->plugin->password,
95 'alias' => $this->plugin->nickname,
96 'psm' => 'Send me a message to post a notice',
100 $this->conn->registerHandler("IMIn", array($this, 'handle_msn_message'));
101 $this->conn->registerHandler('Pong', array($this, 'update_ping_time'));
102 $this->conn->signon();
103 $this->lastping = time();
108 function send_ping() {
116 $this->conn->send_ping();
117 $this->lastping = $now;
122 * Update the time till the next ping
123 * @param $data Time till next ping
125 function update_ping_time($data) {
126 $pingInterval = $data;
129 function handle_msn_message($data)
131 $this->plugin->enqueue_incoming_raw($data);
135 function send_raw_message($data)
141 $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);
143 // Sending a command updates the time till next ping
144 $this->lastping = time();
145 $this->pingInterval = 50;