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

Documentation generated on Mon, 11 Mar 2019 14:19:45 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.