Net_SmartIRC
[ class tree: Net_SmartIRC ] [ index: Net_SmartIRC ] [ all elements ]

Source for file messagehandler.php

Documentation is available at messagehandler.php

  1. <?php
  2. /**
  3.  * $Id$
  4.  * $Revision$
  5.  * $Author$
  6.  * $Date$
  7.  *
  8.  * Copyright (c) 2002-2004 Mirco Bauer <meebey@meebey.net> <http://www.meebey.net>
  9.  *
  10.  * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
  11.  *
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26.  
  27. abstract class Net_SmartIRC_messagehandler extends Net_SmartIRC_irccommands
  28. {
  29.     /* misc */
  30.     protected function _event_ping($ircdata)
  31.     {
  32.         $this->log(SMARTIRC_DEBUG_CONNECTION'DEBUG_CONNECTION: Ping? Pong!',
  33.             __FILE____LINE__
  34.         );
  35.         $this->send('PONG :' $ircdata->messageSMARTIRC_CRITICAL);
  36.     }
  37.  
  38.     protected function _event_error($ircdata)
  39.     {
  40.         if ($this->_autoretry{
  41.             $this->reconnect();
  42.         else {
  43.             $this->disconnect(true);
  44.         }
  45.     }
  46.  
  47.     protected function _event_join($ircdata)
  48.     {
  49.         if ($this->_channelsyncing{
  50.             if ($this->_nick == $ircdata->nick{
  51.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  52.                     'DEBUG_CHANNELSYNCING: joining channel: '.$ircdata->channel,
  53.                     __FILE____LINE__
  54.                 );
  55.                 $channel = new Net_SmartIRC_channel();
  56.                 $channel->name = $ircdata->channel;
  57.                 $microint microtime(true);
  58.                 $channel->synctime_start = $microint;
  59.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  60.                     'DEBUG_CHANNELSYNCING: synctime_start for '
  61.                     .$ircdata->channel.' set to: '.$microint__FILE____LINE__
  62.                 );
  63.                 $this->_channels[strtolower($channel->name)$channel;
  64.  
  65.                 // the class will get his own who data from the whole who channel list
  66.                 $this->mode($channel->name);
  67.                 $this->who($channel->name);
  68.                 $this->ban($channel->name);
  69.             else {
  70.                 // the class didn't join but someone else, lets get his who data
  71.                 $this->who($ircdata->nick);
  72.             }
  73.  
  74.             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: '
  75.                 .$ircdata->nick.' joins channel: '.$ircdata->channel,
  76.                 __FILE____LINE__
  77.             );
  78.             $channel &$this->getChannel($ircdata->channel);
  79.             $user = new Net_SmartIRC_channeluser();
  80.             $user->nick = $ircdata->nick;
  81.             $user->ident = $ircdata->ident;
  82.             $user->host = $ircdata->host;
  83.  
  84.             $this->_adduser($channel$user);
  85.         }
  86.     }
  87.  
  88.     protected function _event_part($ircdata)
  89.     {
  90.         if ($this->_channelsyncing{
  91.             $this->_removeuser($ircdata);
  92.         }
  93.     }
  94.  
  95.     protected function _event_kick($ircdata)
  96.     {
  97.         if ($this->_channelsyncing{
  98.             $this->_removeuser($ircdata);
  99.         }
  100.     }
  101.  
  102.     protected function _event_quit($ircdata)
  103.     {
  104.         if ($this->_channelsyncing{
  105.             $this->_removeuser($ircdata);
  106.         }
  107.     }
  108.  
  109.     protected function _event_nick($ircdata)
  110.     {
  111.         if ($this->_channelsyncing{
  112.             $newnick $ircdata->params[0];
  113.             $lowerednewnick strtolower($newnick);
  114.             $lowerednick strtolower($ircdata->nick);
  115.  
  116.             $channelkeys array_keys($this->_channels);
  117.             foreach ($channelkeys as $channelkey{
  118.                 // loop through all channels
  119.                 $channel &$this->getChannel($channelkey);
  120.                 foreach ($channel->users as $uservalue{
  121.                     // loop through all user in this channel
  122.  
  123.                     if ($ircdata->nick == $uservalue->nick{
  124.                         // found him
  125.                         // time for updating the object and his nickname
  126.                         $channel->users[$lowerednewnick]
  127.                             = $channel->users[$lowerednick]
  128.                         ;
  129.                         $channel->users[$lowerednewnick]->nick = $newnick;
  130.  
  131.                         if ($lowerednewnick != $lowerednick{
  132.                             unset($channel->users[$lowerednick]);
  133.                         }
  134.  
  135.                         // he was maybe op or voice, update coming
  136.                         $lists = array('founders''admins''ops''hops',
  137.                             'voices'
  138.                         );
  139.                         foreach ($lists as $list{
  140.                             if (isset($channel->{$list}[$ircdata->nick])) {
  141.                                 $channel->{$list}[$newnick]
  142.                                     = $channel->{$list}[$ircdata->nick];
  143.                                 unset($channel->{$list}[$ircdata->nick]);
  144.                             }
  145.                         }
  146.                         break;
  147.                     }
  148.                 }
  149.             }
  150.         }
  151.     }
  152.  
  153.     protected function _event_mode($ircdata)
  154.     {
  155.         // check if its own usermode
  156.         if ($ircdata->params[0== $this->_nick{
  157.             $this->_usermode = $ircdata->message;
  158.         else if ($this->_channelsyncing{
  159.             // it's not, and we do channel syncing
  160.             $channel &$this->getChannel($ircdata->channel);
  161.             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  162.                 'DEBUG_CHANNELSYNCING: updating channel mode for: '
  163.                 .$channel->name__FILE____LINE__
  164.             );
  165.             $mode $ircdata->params[1];
  166.             $parameters array_slice($ircdata->params2);
  167.  
  168.             $add = false;
  169.             $remove = false;
  170.             $modelength strlen($mode);
  171.             for ($i = 0; $i $modelength$i++{
  172.                 switch($mode{$i}{
  173.                     case '-':
  174.                         $remove = true;
  175.                         $add = false;
  176.                         break;
  177.  
  178.                     case '+':
  179.                         $add = true;
  180.                         $remove = false;
  181.                         break;
  182.  
  183.                     // user modes
  184.                     case 'q':
  185.                         $nick array_shift($parameters);
  186.                         $lowerednick strtolower($nick);
  187.                         if ($add{
  188.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  189.                                 'DEBUG_CHANNELSYNCING: adding founder: '.$nick
  190.                                 .' to channel: '.$channel->name,
  191.                                 __FILE____LINE__
  192.                             );
  193.                             $channel->founders[$nick= true;
  194.                             $channel->users[$lowerednick]->founder = true;
  195.                         }
  196.                         if ($remove{
  197.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  198.                                 'DEBUG_CHANNELSYNCING: removing founder: '.$nick
  199.                                 .' to channel: '.$channel->name,
  200.                                 __FILE____LINE__
  201.                             );
  202.                             unset($channel->founders[$nick]);
  203.                             $channel->users[$lowerednick]->founder = false;
  204.                         }
  205.                         break;
  206.  
  207.                     case 'a':
  208.                         $nick array_shift($parameters);
  209.                         $lowerednick strtolower($nick);
  210.                         if ($add{
  211.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  212.                                 'DEBUG_CHANNELSYNCING: adding admin: '.$nick
  213.                                 .' to channel: '.$channel->name,
  214.                                 __FILE____LINE__
  215.                             );
  216.                             $channel->admins[$nick= true;
  217.                             $channel->users[$lowerednick]->admin = true;
  218.                         }
  219.                         if ($remove{
  220.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  221.                                 'DEBUG_CHANNELSYNCING: removing admin: '.$nick
  222.                                 .' to channel: '.$channel->name,
  223.                                 __FILE____LINE__
  224.                             );
  225.                             unset($channel->admins[$nick]);
  226.                             $channel->users[$lowerednick]->admin = false;
  227.                         }
  228.                         break;
  229.  
  230.                     case 'o':
  231.                         $nick array_shift($parameters);
  232.                         $lowerednick strtolower($nick);
  233.                         if ($add{
  234.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  235.                                 'DEBUG_CHANNELSYNCING: adding op: '.$nick
  236.                                 .' to channel: '.$channel->name,
  237.                                 __FILE____LINE__
  238.                             );
  239.                             $channel->ops[$nick= true;
  240.                             $channel->users[$lowerednick]->op = true;
  241.                         }
  242.                         if ($remove{
  243.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  244.                                 'DEBUG_CHANNELSYNCING: removing op: '.$nick
  245.                                 .' to channel: '.$channel->name,
  246.                                 __FILE____LINE__
  247.                             );
  248.                             unset($channel->ops[$nick]);
  249.                             $channel->users[$lowerednick]->op = false;
  250.                         }
  251.                         break;
  252.  
  253.                     case 'h':
  254.                         $nick array_shift($parameters);
  255.                         $lowerednick strtolower($nick);
  256.                         if ($add{
  257.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  258.                                 'DEBUG_CHANNELSYNCING: adding half-op: '.$nick
  259.                                 .' to channel: '.$channel->name,
  260.                                 __FILE____LINE__
  261.                             );
  262.                             $channel->hops[$nick= true;
  263.                             $channel->users[$lowerednick]->hop = true;
  264.                         }
  265.                         if ($remove{
  266.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  267.                                 'DEBUG_CHANNELSYNCING: removing half-op: '.$nick
  268.                                 .' to channel: '.$channel->name,
  269.                                 __FILE____LINE__
  270.                             );
  271.                             unset($channel->hops[$nick]);
  272.                             $channel->users[$lowerednick]->hop = false;
  273.                         }
  274.                         break;
  275.  
  276.                     case 'v':
  277.                         $nick array_shift($parameters);
  278.                         $lowerednick strtolower($nick);
  279.                         if ($add{
  280.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  281.                                 'DEBUG_CHANNELSYNCING: adding voice: '.$nick
  282.                                 .' to channel: '.$channel->name,
  283.                                 __FILE____LINE__
  284.                             );
  285.                             $channel->voices[$nick= true;
  286.                             $channel->users[$lowerednick]->voice = true;
  287.                         }
  288.                         if ($remove{
  289.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  290.                                 'DEBUG_CHANNELSYNCING: removing voice: '.$nick
  291.                                 .' to channel: '.$channel->name,
  292.                                 __FILE____LINE__
  293.                             );
  294.                             unset($channel->voices[$nick]);
  295.                             $channel->users[$lowerednick]->voice = false;
  296.                         }
  297.                         break;
  298.  
  299.                     case 'k':
  300.                         $key array_shift($parameters);
  301.                         if ($add{
  302.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  303.                                 'DEBUG_CHANNELSYNCING: stored channel key for: '
  304.                                 .$channel->name__FILE____LINE__
  305.                             );
  306.                             $channel->key = $key;
  307.                         }
  308.                         if ($remove{
  309.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  310.                                 'DEBUG_CHANNELSYNCING: removed channel key for: '
  311.                                 .$channel->name__FILE____LINE__
  312.                             );
  313.                             $channel->key = '';
  314.                         }
  315.                         break;
  316.  
  317.                     case 'l':
  318.                         if ($add{
  319.                             $limit array_shift($parameters);
  320.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  321.                                 'DEBUG_CHANNELSYNCING: stored user limit for: '
  322.                                 .$channel->name__FILE____LINE__
  323.                             );
  324.                             $channel->user_limit = $limit;
  325.                         }
  326.                         if ($remove{
  327.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  328.                                 'DEBUG_CHANNELSYNCING: removed user limit for: '
  329.                                 .$channel->name__FILE____LINE__
  330.                             );
  331.                             $channel->user_limit = false;
  332.                         }
  333.                         break;
  334.  
  335.                     default:
  336.                         // channel modes
  337.                         if ($mode{$i== 'b'{
  338.                             $hostmask array_shift($parameters);
  339.                             if ($add{
  340.                                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  341.                                     'DEBUG_CHANNELSYNCING: adding ban: '
  342.                                     .$hostmask.' for: '.$channel->name,
  343.                                     __FILE____LINE__
  344.                                 );
  345.                                 $channel->bans[$hostmask= true;
  346.                             }
  347.                             if ($remove{
  348.                                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  349.                                     'DEBUG_CHANNELSYNCING: removing ban: '
  350.                                     .$hostmask.' for: '.$channel->name,
  351.                                     __FILE____LINE__
  352.                                 );
  353.                                 unset($channel->bans[$hostmask]);
  354.                             }
  355.                         else {
  356.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  357.                                 'DEBUG_CHANNELSYNCING: updating unknown channelmode ('
  358.                                 .$mode{$i}.') in channel->mode for: '
  359.                                 .$channel->name__FILE____LINE__
  360.                             );
  361.                             if ($add{
  362.                                 $channel->mode .= $mode{$i};
  363.                             }
  364.                             if ($remove{
  365.                                 $channel->mode = str_replace($mode{$i}'',
  366.                                     $channel->mode
  367.                                 );
  368.                             }
  369.                         }
  370.                 }
  371.             }
  372.         }
  373.     }
  374.  
  375.     protected function _event_topic($ircdata)
  376.     {
  377.         if ($this->_channelsyncing{
  378.             $channel &$this->getChannel($ircdata->channel);
  379.             $channel->topic = $ircdata->message;
  380.         }
  381.     }
  382.  
  383.     protected function _event_privmsg($ircdata)
  384.     {
  385.         if ($ircdata->type SMARTIRC_TYPE_CTCP_REQUEST{
  386.             // substr must be 1,4 because of \001 in CTCP messages
  387.             if (substr($ircdata->message14== 'PING'{
  388.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick,
  389.                     'PING'.substr($ircdata->message5-1)
  390.                 );
  391.             elseif (substr($ircdata->message17== 'VERSION'{
  392.                 if (!empty($this->_ctcpversion)) {
  393.                     $versionstring $this->_ctcpversion;
  394.                 else {
  395.                     $versionstring SMARTIRC_VERSIONSTRING;
  396.                 }
  397.  
  398.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick,
  399.                     'VERSION '.$versionstring
  400.                 );
  401.             elseif (substr($ircdata->message110== 'CLIENTINFO'{
  402.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick,
  403.                     'CLIENTINFO PING VERSION CLIENTINFO'
  404.                 );
  405.             }
  406.         }
  407.     }
  408.  
  409.     /* rpl_ */
  410.     protected function _event_rpl_welcome($ircdata)
  411.     {
  412.         $this->_loggedin = true;
  413.  
  414.         // updating our nickname, that we got (maybe cutted...)
  415.         $this->_nick = $ircdata->params[0];
  416.  
  417.         $this->log(SMARTIRC_DEBUG_CONNECTION'DEBUG_CONNECTION: logged in as '
  418.             . $this->_nick__FILE____LINE__
  419.         );
  420.  
  421.     }
  422.  
  423.     protected function _event_rpl_motdstart($ircdata)
  424.     {
  425.         $this->_motd[$ircdata->message;
  426.     }
  427.  
  428.     protected function _event_rpl_motd($ircdata)
  429.     {
  430.         $this->_motd[$ircdata->message;
  431.     }
  432.  
  433.     protected function _event_rpl_endofmotd($ircdata)
  434.     {
  435.         $this->_motd[$ircdata->message;
  436.     }
  437.  
  438.     protected function _event_rpl_umodeis($ircdata)
  439.     {
  440.         $this->_usermode = $ircdata->message;
  441.     }
  442.  
  443.     protected function _event_rpl_channelmodeis(&$ircdata{
  444.         if ($this->_channelsyncing && $this->isJoined($ircdata->channel)) {
  445.             $ircdata->params[0'';
  446.  
  447.             // let _mode() handle the received mode
  448.             $this->_event_mode($ircdata);
  449.         }
  450.     }
  451.  
  452.     protected function _event_rpl_whoreply($ircdata)
  453.     {
  454.         if ($this->_channelsyncing{
  455.             $offset = (int) ($ircdata->params[0== $this->_nick);
  456.             $nick $ircdata->params[4 + $offset];
  457.  
  458.             if ($ircdata->channel == '*'{
  459.                 // we got who info without channel info, so search the user
  460.                 // on all channels and update him
  461.                 foreach ($this->_channels as $channel{
  462.                     if ($this->isJoined($channel->name$nick)) {
  463.                         $ircdata->channel = $channel->name;
  464.                         $this->_event_rpl_whoreply($ircdata);
  465.                     }
  466.                 }
  467.             else {
  468.                 if (!$this->isJoined($ircdata->channel$nick)) {
  469.                     return;
  470.                 }
  471.  
  472.                 $user = new Net_SmartIRC_channeluser();
  473.                 $user->ident = $ircdata->params[1 + $offset];
  474.                 $user->host = $ircdata->params[2 + $offset];
  475.                 $user->server = $ircdata->params[3 + $offset];
  476.                 $user->nick = $nick;
  477.  
  478.                 $user->ircop = false;
  479.                 $user->founder = false;
  480.                 $user->admin = false;
  481.                 $user->op = false;
  482.                 $user->hop = false;
  483.                 $user->voice = false;
  484.  
  485.                 $usermode $ircdata->params[5 + $offset];
  486.                 $user->modes = $usermode;
  487.  
  488.                 $usermodelength strlen($usermode);
  489.                 for ($i = 0; $i $usermodelength$i++{
  490.                     switch ($usermode{$i}{
  491.                         case 'H':
  492.                             $user->away = false;
  493.                             break;
  494.  
  495.                         case 'G':
  496.                             $user->away = true;
  497.                             break;
  498.  
  499.                         case '*':
  500.                             $user->ircop = true;
  501.                             break;
  502.  
  503.                         case '~':
  504.                             $user->founder = true;
  505.                             break;
  506.  
  507.                         case '&':
  508.                             $user->admin = true;
  509.                             break;
  510.  
  511.                         case '@':
  512.                             $user->op = true;
  513.                             break;
  514.  
  515.                         case '%':
  516.                             $user->hop = true;
  517.                             break;
  518.  
  519.                         case '+':
  520.                             $user->voice = true;
  521.                     }
  522.                 }
  523.  
  524.                 $user->hopcount = $ircdata->messageex[0];
  525.                 $user->realname = implode(array_slice($ircdata->messageex1)' ');
  526.  
  527.                 $channel &$this->getChannel($ircdata->channel);
  528.                 $this->_adduser($channel$user);
  529.             }
  530.         }
  531.     }
  532.  
  533.     protected function _event_rpl_namreply($ircdata)
  534.     {
  535.         if ($this->_channelsyncing{
  536.             $userarray explode(' 'rtrim($ircdata->message));
  537.             $userarraycount count($userarray);
  538.             for ($i = 0; $i $userarraycount$i++{
  539.                 $user = new Net_SmartIRC_channeluser();
  540.  
  541.                 switch ($userarray[$i]{0}{
  542.                     case '~':
  543.                         $user->founder = true;
  544.                         $user->nick = substr($userarray[$i]1);
  545.                         break;
  546.  
  547.                     case '&':
  548.                         $user->admin = true;
  549.                         $user->nick = substr($userarray[$i]1);
  550.                         break;
  551.  
  552.                     case '@':
  553.                         $user->op = true;
  554.                         $user->nick = substr($userarray[$i]1);
  555.                         break;
  556.  
  557.                     case '%':
  558.                         $user->hop = true;
  559.                         $user->nick = substr($userarray[$i]1);
  560.                         break;
  561.  
  562.                     case '+':
  563.                         $user->voice = true;
  564.                         $user->nick = substr($userarray[$i]1);
  565.                         break;
  566.  
  567.                     default:
  568.                         $user->nick = $userarray[$i];
  569.                 }
  570.  
  571.                 $channel &$this->getChannel($ircdata->channel);
  572.                 $this->_adduser($channel$user);
  573.             }
  574.         }
  575.     }
  576.  
  577.     protected function _event_rpl_banlist($ircdata)
  578.     {
  579.         if ($this->_channelsyncing && $this->isJoined($ircdata->channel)) {
  580.             $channel &$this->getChannel($ircdata->channel);
  581.             $hostmask $ircdata->params[1];
  582.             $channel->bans[$hostmask= true;
  583.         }
  584.     }
  585.  
  586.     protected function _event_rpl_endofbanlist($ircdata)
  587.     {
  588.         if ($this->_channelsyncing && $this->isJoined($ircdata->channel)) {
  589.             $channel &$this->getChannel($ircdata->channel);
  590.             if ($channel->synctime_stop == 0{
  591.                 // we received end of banlist and the stop timestamp is not set yet
  592.                 $channel->synctime_stop = microtime(true);
  593.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  594.                     'DEBUG_CHANNELSYNCING: synctime_stop for '.$ircdata->channel
  595.                     .' set to: '.$channel->synctime_stop__FILE____LINE__
  596.                 );
  597.  
  598.                 $channel->synctime = (float)$channel->synctime_stop
  599.                     - (float)$channel->synctime_start
  600.                 ;
  601.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING,
  602.                     'DEBUG_CHANNELSYNCING: synced channel '.$ircdata->channel
  603.                     .' in '.round($channel->synctime2).' secs',
  604.                     __FILE____LINE__
  605.                 );
  606.             }
  607.         }
  608.     }
  609.  
  610.     protected function _event_rpl_topic($ircdata)
  611.     {
  612.         if ($this->_channelsyncing{
  613.             $channel &$this->getChannel($ircdata->channel);
  614.             $channel->topic = $ircdata->message;
  615.         }
  616.     }
  617.  
  618.     /* err_ */
  619.     protected function _event_err_nicknameinuse($ircdata)
  620.     {
  621.         $newnick substr($this->_nick05rand(0999);
  622.         $this->changeNick($newnickSMARTIRC_CRITICAL);
  623.     }
  624. }

Documentation generated on Thu, 25 Jul 2019 12:49:08 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.