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: messagehandler.php 241017 2007-08-10 09:22:02Z amir $
  4.  * $Revision: 241017 $
  5.  * $Author: amir $
  6.  * $Date: 2007-08-10 18:52:02 +0930 (Fri, 10 Aug 2007) $
  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. {
  28.     /* misc */
  29.     function _event_ping(&$ircdata)
  30.     {
  31.         $this->_pong(substr($ircdata->rawmessage5));
  32.     }
  33.     
  34.     function _event_error(&$ircdata)
  35.     {
  36.         if ($this->_autoretry == true{
  37.             $this->_delayReconnect();
  38.             $this->reconnect();
  39.         else {
  40.             $this->disconnect(true);
  41.         }
  42.     }
  43.     
  44.     function _event_join(&$ircdata)
  45.     {
  46.         if ($this->_channelsyncing == true{
  47.             if ($this->_nick == $ircdata->nick{
  48.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: joining channel: '.$ircdata->channel__FILE____LINE__);
  49.                 $channel &new Net_SmartIRC_channel();
  50.                 $channel->name = $ircdata->channel;
  51.                 $microint $this->_microint();
  52.                 $channel->synctime_start = $microint;
  53.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: synctime_start for '.$ircdata->channel.' set to: '.$microint__FILE____LINE__);
  54.                 $this->_channels[strtolower($channel->name)&$channel;
  55.                 
  56.                 // the class will get his own who data from the whole who channel list
  57.                 $this->mode($channel->name);
  58.                 $this->who($channel->name);
  59.                 $this->ban($channel->name);
  60.             else {
  61.                 // the class didn't join but someone else, lets get his who data
  62.                 $this->who($ircdata->nick);
  63.             }
  64.             
  65.             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: '.$ircdata->nick.' joins channel: '.$ircdata->channel__FILE____LINE__);
  66.             $channel &$this->_channels[strtolower($ircdata->channel)];
  67.             $user &new Net_SmartIRC_channeluser();
  68.             $user->nick = $ircdata->nick;
  69.             $user->ident = $ircdata->ident;
  70.             $user->host = $ircdata->host;
  71.             
  72.             $this->_adduser($channel$user);
  73.         }
  74.     }
  75.     
  76.     function _event_part(&$ircdata)
  77.     {
  78.         if ($this->_channelsyncing == true{
  79.             $this->_removeuser($ircdata);
  80.         }
  81.     }
  82.     
  83.     function _event_kick(&$ircdata)
  84.     {
  85.         if ($this->_channelsyncing == true{
  86.             $this->_removeuser($ircdata);
  87.         }
  88.     }
  89.     
  90.     function _event_quit(&$ircdata)
  91.     {
  92.         if ($this->_channelsyncing == true{
  93.             $this->_removeuser($ircdata);
  94.         }
  95.     }
  96.     
  97.     function _event_nick(&$ircdata)
  98.     {
  99.         if ($this->_channelsyncing == true{
  100.             $newnick substr($ircdata->rawmessageex[2]1);
  101.             $lowerednewnick strtolower($newnick);
  102.             $lowerednick strtolower($ircdata->nick);
  103.             
  104.             $channelkeys array_keys($this->_channels);
  105.             foreach ($channelkeys as $channelkey{
  106.                 // loop through all channels
  107.                 $channel &$this->_channels[$channelkey];
  108.                 foreach ($channel->users as $uservalue{
  109.                     // loop through all user in this channel
  110.                     
  111.                     if ($ircdata->nick == $uservalue->nick{
  112.                         // found him
  113.                         // time for updating the object and his nickname
  114.                         $channel->users[$lowerednewnick$channel->users[$lowerednick];
  115.                         $channel->users[$lowerednewnick]->nick = $newnick;
  116.                         
  117.                         if ($lowerednewnick != $lowerednick{
  118.                             unset($channel->users[$lowerednick]);
  119.                         }
  120.                         
  121.                         // he was maybe op or voice, update comming
  122.                         if (isset($channel->ops[$ircdata->nick])) {
  123.                             $channel->ops[$newnick$channel->ops[$ircdata->nick];
  124.                             unset($channel->ops[$ircdata->nick]);
  125.                         }
  126.                         if (isset($channel->voices[$ircdata->nick])) {
  127.                             $channel->voices[$newnick$channel->voices[$ircdata->nick];
  128.                             unset($channel->voices[$ircdata->nick]);
  129.                         }
  130.                         
  131.                         break;
  132.                     }
  133.                 }
  134.             }
  135.         }
  136.     }
  137.     
  138.     function _event_mode(&$ircdata)
  139.     {
  140.         // check if its own usermode
  141.         if ($ircdata->rawmessageex[2== $this->_nick{
  142.             $this->_usermode substr($ircdata->rawmessageex[3]1);
  143.         else if ($this->_channelsyncing == true{
  144.             // it's not, and we do channel syching
  145.             $channel &$this->_channels[strtolower($ircdata->channel)];
  146.             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: updating channel mode for: '.$channel->name__FILE____LINE__);
  147.             $mode $ircdata->rawmessageex[3];
  148.             $parameters array_slice($ircdata->rawmessageex4);
  149.             
  150.             $add = false;
  151.             $remove = false;
  152.             $modelength strlen($mode);
  153.             for ($i = 0; $i $modelength$i++{
  154.                 switch($mode[$i]{
  155.                     case '-':
  156.                         $remove = true;
  157.                         $add = false;
  158.                     break;
  159.                     case '+':
  160.                         $add = true;
  161.                         $remove = false;
  162.                     break;
  163.                     // user modes
  164.                     case 'o':
  165.                         $nick array_shift($parameters);
  166.                         $lowerednick strtolower($nick);
  167.                         if ($add{
  168.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: adding op: '.$nick.' to channel: '.$channel->name__FILE____LINE__);
  169.                             $channel->ops[$nick= true;
  170.                             $channel->users[$lowerednick]->op = true;
  171.                         }
  172.                         if ($remove{
  173.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: removing op: '.$nick.' to channel: '.$channel->name__FILE____LINE__);
  174.                             unset($channel->ops[$nick]);
  175.                             $channel->users[$lowerednick]->op = false;
  176.                         }
  177.                     break;
  178.                     case 'v':
  179.                         $nick array_shift($parameters);
  180.                         $lowerednick strtolower($nick);
  181.                         if ($add{
  182.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: adding voice: '.$nick.' to channel: '.$channel->name__FILE____LINE__);
  183.                             $channel->voices[$nick= true;
  184.                             $channel->users[$lowerednick]->voice = true;
  185.                         }
  186.                         if ($remove{
  187.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: removing voice: '.$nick.' to channel: '.$channel->name__FILE____LINE__);
  188.                             unset($channel->voices[$nick]);
  189.                             $channel->users[$lowerednick]->voice = false;
  190.                         }
  191.                     break;
  192.                     case 'k':
  193.                         $key array_shift($parameters);
  194.                         if ($add{
  195.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: stored channel key for: '.$channel->name__FILE____LINE__);
  196.                             $channel->key = $key;
  197.                         }
  198.                         if ($remove{
  199.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: removed channel key for: '.$channel->name__FILE____LINE__);
  200.                             $channel->key = '';
  201.                         }
  202.                     break;
  203.                     case 'l':
  204.                         if ($add{
  205.                             $limit array_shift($parameters);
  206.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: stored user limit for: '.$channel->name__FILE____LINE__);
  207.                             $channel->user_limit = $limit;
  208.                         }
  209.                         if ($remove{
  210.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: removed user limit for: '.$channel->name__FILE____LINE__);
  211.                             $channel->user_limit = false;
  212.                         }
  213.                     break;
  214.                     default:
  215.                         // channel modes
  216.                         if ($mode[$i== 'b'{
  217.                             $hostmask array_shift($parameters);
  218.                             if ($add{
  219.                                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: adding ban: '.$hostmask.' for: '.$channel->name__FILE____LINE__);
  220.                                 $channel->bans[$hostmask= true;
  221.                             }
  222.                             if ($remove{
  223.                                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: removing ban: '.$hostmask.' for: '.$channel->name__FILE____LINE__);
  224.                                 unset($channel->bans[$hostmask]);
  225.                             }
  226.                         else {
  227.                             $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: storing unknown channelmode ('.$mode.') in channel->mode for: '.$channel->name__FILE____LINE__);
  228.                             if ($add{
  229.                                 $channel->mode .= $mode[$i];
  230.                             }
  231.                             if ($remove{
  232.                                 $channel->mode = str_replace($mode[$i]''$channel->mode);
  233.                             }
  234.                         }
  235.                 }
  236.             }
  237.         }
  238.     }
  239.     
  240.     function _event_topic(&$ircdata)
  241.     {
  242.         if ($this->_channelsyncing == true{
  243.             $channel &$this->_channels[strtolower($ircdata->rawmessageex[2])];
  244.             $channel->topic = $ircdata->message;
  245.         }
  246.     }
  247.     
  248.     function _event_privmsg(&$ircdata)
  249.     {
  250.         if ($ircdata->type SMARTIRC_TYPE_CTCP_REQUEST{
  251.             // substr must be 1,4 because of \001 in CTCP messages
  252.             if (substr($ircdata->message14== 'PING'{
  253.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick'PING '.substr($ircdata->message5-1));
  254.             elseif (substr($ircdata->message17== 'VERSION'{
  255.                 if (!empty($this->_ctcpversion)) {
  256.                     $versionstring $this->_ctcpversion;
  257.                 else {
  258.                     $versionstring SMARTIRC_VERSIONSTRING;
  259.                 }
  260.                 
  261.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick'VERSION '.$versionstring);
  262.             elseif (substr($ircdata->message110== 'CLIENTINFO'{
  263.                 $this->message(SMARTIRC_TYPE_CTCP_REPLY$ircdata->nick'CLIENTINFO PING VERSION CLIENTINFO');
  264.             }
  265.         }
  266.     }
  267.     
  268.     /* rpl_ */
  269.     function _event_rpl_welcome(&$ircdata)
  270.     {
  271.         $this->_loggedin = true;
  272.         $this->log(SMARTIRC_DEBUG_CONNECTION'DEBUG_CONNECTION: logged in'__FILE____LINE__);
  273.         
  274.         // updating our nickname, that we got (maybe cutted...)
  275.         $this->_nick $ircdata->rawmessageex[2];
  276.     }
  277.     
  278.     function _event_rpl_motdstart(&$ircdata)
  279.     {
  280.         $this->_motd[$ircdata->message;
  281.     }
  282.     
  283.     function _event_rpl_motd(&$ircdata)
  284.     {
  285.         $this->_motd[$ircdata->message;
  286.     }
  287.     
  288.     function _event_rpl_endofmotd(&$ircdata)
  289.     {
  290.         $this->_motd[$ircdata->message;
  291.     }
  292.     
  293.     function _event_rpl_umodeis(&$ircdata)
  294.     {
  295.         $this->_usermode $ircdata->message;
  296.     }
  297.     
  298.     function _event_rpl_channelmodeis(&$ircdata{
  299.         if ($this->_channelsyncing == true && $this->isJoined($ircdata->channel)) {
  300.             $mode $ircdata->rawmessageex[4];
  301.             $parameters array_slice($ircdata->rawmessageex5);
  302.             
  303.             $ircdata->rawmessageex = array0 => '',
  304.                                             1 => '',
  305.                                             2 => '',
  306.                                             3 => $mode);
  307.             
  308.             foreach ($parameters as $value{
  309.                 $ircdata->rawmessageex[$value;
  310.             }
  311.             
  312.             // let _mode() handle the received mode
  313.             $this->_event_mode($ircdata);
  314.         }
  315.     }
  316.     
  317.     function _event_rpl_whoreply(&$ircdata)
  318.     {
  319.         if ($this->_channelsyncing == true{
  320.             $nick $ircdata->rawmessageex[7];
  321.             if ($ircdata->channel == '*'{
  322.                 // we got who info without channel info, so we need to search the user
  323.                 // on all channels and update him
  324.                 foreach ($this->_channels as $channel{
  325.                     if ($this->isJoined($channel->name$nick)) {
  326.                         $ircdata->channel = $channel->name;
  327.                         $this->_event_rpl_whoreply($ircdata);
  328.                     }
  329.                 }
  330.             else {
  331.                 if (!$this->isJoined($ircdata->channel$nick)) {
  332.                     return;
  333.                 }
  334.                 
  335.                 $channel &$this->_channels[strtolower($ircdata->channel)];
  336.                 
  337.                 $user &new Net_SmartIRC_channeluser();
  338.                 $user->ident = $ircdata->rawmessageex[4];
  339.                 $user->host = $ircdata->rawmessageex[5];
  340.                 $user->server = $ircdata->rawmessageex[6];
  341.                 $user->nick = $ircdata->rawmessageex[7];
  342.                 
  343.                 $user->op = false;
  344.                 $user->voice = false;
  345.                 $user->ircop = false;
  346.                 
  347.                 $usermode $ircdata->rawmessageex[8];
  348.                 $usermodelength strlen($usermode);
  349.                 for ($i = 0; $i $usermodelength$i++{
  350.                     switch ($usermode[$i]{
  351.                         case 'H':
  352.                             $user->away = false;
  353.                         break;
  354.                         case 'G':
  355.                             $user->away = true;
  356.                         break;
  357.                         case '@':
  358.                             $user->op = true;
  359.                         break;
  360.                         case '+':
  361.                             $user->voice = true;
  362.                         break;
  363.                         case '*':
  364.                             $user->ircop = true;
  365.                         break;
  366.                     }
  367.                 }
  368.                  
  369.                 $user->hopcount = substr($ircdata->rawmessageex[9]1);
  370.                 $user->realname = implode(array_slice($ircdata->rawmessageex10)' ');
  371.                 
  372.                 $this->_adduser($channel$user);
  373.             }
  374.         }
  375.     }
  376.     
  377.     function _event_rpl_namreply(&$ircdata)
  378.     {
  379.         if ($this->_channelsyncing == true{
  380.             $channel &$this->_channels[strtolower($ircdata->channel)];
  381.             
  382.             $userarray explode(' 'rtrim($ircdata->message));
  383.             $userarraycount count($userarray);
  384.             for ($i = 0; $i $userarraycount$i++{
  385.                 $user &new Net_SmartIRC_channeluser();
  386.                 
  387.                 $usermode substr($userarray[$i]01);
  388.                 switch ($usermode{
  389.                     case '@':
  390.                         $user->op = true;
  391.                         $user->nick = substr($userarray[$i]1);
  392.                     break;
  393.                     case '+':
  394.                         $user->voice = true;
  395.                         $user->nick = substr($userarray[$i]1);
  396.                     break;
  397.                     // RFC violating IRC servers might break us
  398.                     case '~':
  399.                     case '&':
  400.                     case '%':
  401.                         $user->nick = substr($userarray[$i]1);
  402.                     break;
  403.                     default:
  404.                         $user->nick = $userarray[$i];
  405.                 }
  406.                 
  407.                 $this->_adduser($channel$user);
  408.             }
  409.         }
  410.     }
  411.     
  412.     function _event_rpl_banlist(&$ircdata)
  413.     {
  414.         if ($this->_channelsyncing == true && $this->isJoined($ircdata->channel)) {
  415.             $channel &$this->_channels[strtolower($ircdata->channel)];
  416.             $hostmask $ircdata->rawmessageex[4];
  417.             $channel->bans[$hostmask= true;
  418.         }
  419.     }
  420.     
  421.     function _event_rpl_endofbanlist(&$ircdata)
  422.     {
  423.         if ($this->_channelsyncing == true && $this->isJoined($ircdata->channel)) {
  424.             $channel &$this->getChannel($ircdata->channel);
  425.             if ($channel->synctime_stop == 0{
  426.                 // we received end of banlist and the stop timestamp is not set yet
  427.                 $microint $this->_microint();
  428.                 $channel->synctime_stop = $microint;
  429.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: synctime_stop for '.$ircdata->channel.' set to: '.$microint__FILE____LINE__);
  430.                 
  431.                 $channel->synctime = ((float)$channel->synctime_stop - (float)$channel->synctime_start);
  432.                 $this->log(SMARTIRC_DEBUG_CHANNELSYNCING'DEBUG_CHANNELSYNCING: synced channel '.$ircdata->channel.' in '.round($channel->synctime2).' secs'__FILE____LINE__);
  433.             }
  434.         }
  435.     }
  436.     
  437.     function _event_rpl_topic(&$ircdata)
  438.     {
  439.         if ($this->_channelsyncing == true{
  440.             $channel &$this->_channels[strtolower($ircdata->channel)];
  441.             $topic substr(implode(array_slice($ircdata->rawmessageex4)' ')1);
  442.             $channel->topic = $topic;
  443.         }
  444.     }
  445.     
  446.     /* err_ */
  447.     function _event_err_nicknameinuse(&$ircdata)
  448.     {
  449.         $this->_nicknameinuse();
  450.     }
  451. }
  452. ?>

Documentation generated on Mon, 11 Mar 2019 15:32:24 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.