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 * IRC background connection manager for IRC-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 IRC enabled.
33 class IrcManager extends ImManager {
37 * Initialize connection to server.
38 * @return boolean true on success
40 public function start($master) {
41 if (parent::start($master)) {
49 public function getSockets() {
52 return array($this->conn->myConnection);
59 * Process IRC events that have come in over the wire.
60 * @param resource $socket
62 public function handleInput($socket) {
63 common_log(LOG_DEBUG, 'Servicing the IRC queue.');
64 $this->stats('irc_process');
65 $this->conn->receive();
70 $this->conn = new Phergie_Extended_Bot;
72 $password = isset($this->plugin->password) ? $this->plugin->password : '';
73 $transport = isset($this->plugin->transport) ? $this->plugin->transport : 'tcp';
74 $encoding = isset($this->plugin->encoding) ? $this->plugin->encoding : 'ISO-8859-1';
75 $channels = isset($this->plugin->channels) ? $this->plugin->channels : array();
76 $nickservpassword = isset($this->plugin->nickservpassword) ? $this->plugin->nickservpassword : '';
78 $config = new Phergie_Extended_Config;
81 // One array per connection, pretty self-explanatory
82 'connections' => array(
84 'host' => $this->plugin->host,
85 'port' => $this->plugin->port,
86 'username' => $this->plugin->username,
87 'realname' => $this->plugin->realname,
88 'nick' => $this->plugin->nickname,
89 'password' => $password,
90 'transport' => $transport,
91 'encoding' => $encoding
95 'processor' => 'async',
96 'processor.options' => array('usec' => 200000),
102 'Statusnet_Callback',
105 'plugins.autoload' => true,
107 'ui.enabled' => true,
109 'nickserv.password' => $nickservpassword,
110 'autojoin.channels' => $channels
114 $this->conn->setConfig($config);
115 $this->conn->connect();
120 function handle_irc_message($data) {
121 $this->plugin->enqueue_incoming_raw($data);
125 function send_raw_message($data) {
130 $this->conn->sflapSend($data[0],$data[1],$data[2],$data[3]);