/**
  * Process an incoming message
  *
  * @param string Raw line from the server
  */
 private function processIncoming($message)
 {
     $this->lastping = time();
     $parts = explode(' ', trim($message, ": \r\n")) + array('', '');
     switch ($parts[0]) {
         case 'NOTICE':
             if (!$this->authenticated && $parts[1] == 'AUTH') {
                 $this->send_line("NICK {$this->nick}");
                 $this->send_line("USER {$this->nick} localhost {$this->server} :{$this->nick}");
                 $this->authenticated = TRUE;
             }
             break;
         case 'PING':
             $this->send_line('PONG ' . $parts[1]);
     }
     switch ($parts[1]) {
         case 'PRIVMSG':
             $content = trim(implode(' ', array_slice($parts, 3)), ": ");
             if (substr($content, 0, 1) == "") {
                 $ctcp = true;
                 $content = trim($content, "");
             }
             if ($content == 'VERSION' && $ctcp) {
                 $this->sendCTCP(IRCServerUser::getByHostmask($parts[0])->nick, 'VERSION V7IRC');
             } else {
                 if ($parts[2] != $this->nick) {
                     // Process channel text
                     $user = IRCServerUser::getByHostmask($parts[0]);
                     $chan = IRCServerChannel::getChannel($parts[2]);
                     $chan->event_msg($user, $content);
                 } else {
                     // Process private message
                 }
             }
             break;
         case 'KICK':
             $content = trim(implode(' ', array_slice($parts, 4)), ": ");
             if ($parts[3] == $this->nick) {
                 $user = IRCServerUser::getByHostmask($parts[0]);
                 $chan = IRCServerChannel::getChannel($parts[2]);
                 $chan->online = FALSE;
                 $chan->event_kicked($user, $content);
             } else {
                 $user = IRCServerUser::getByHostmask($parts[0]);
                 $victim = IRCServerUser::getUser($parts[3]);
                 $chan = IRCServerChannel::getChannel($parts[2]);
                 unset($victim->channels[$chan->channel]);
                 $chan->event_kick($user, $content, $victim);
             }
             break;
         case 'NICK':
             $user = IRCServerUser::getByHostmask($parts[0]);
             foreach (IRCServerChannel::$channels as $name => $chan) {
                 $chan->event_nick($user, trim($parts[2], ':'));
             }
             break;
         case 'JOIN':
             $chan = IRCServerChannel::getChannel(trim($parts[2], ':'));
             $user = IRCServerUser::getByHostmask($parts[0], $chan->channel);
             $chan->event_join($user);
             break;
         case 'PART':
             $user = IRCServerUser::getByHostmask($parts[0]);
             $chan = IRCServerChannel::getChannel($parts[2]);
             unset($user->channels[$chan->channel]);
             $chan->event_part($user);
             break;
         case 'QUIT':
             $content = trim(implode(' ', array_slice($parts, 3)), ": ");
             $user = IRCServerUser::getByHostmask($parts[0]);
             foreach (IRCServerChannel::$channels as $chan) {
                 foreach ($chan->users as $chanuser) {
                     if ($chanuser == $user) {
                         unset($user->channels[$chan->channel]);
                         $chan->event_quit($user, $content);
                     }
                 }
             }
             break;
         case 'NOTICE':
             if (in_array($parts[2], array('AUTH', '*', '***'))) {
                 if (!$this->authenticated) {
                     $this->send_line("NICK {$this->nick}");
                     $this->send_line("USER {$this->nick} localhost {$this->server} :{$this->nick}");
                     $this->authenticated = TRUE;
                 }
                 break;
             }
             $content = trim(implode(' ', array_slice($parts, 3)), ": ");
             $user = IRCServerUser::getByHostmask($parts[0]);
             if ($parts[2] != $this->nick) {
                 $chan = IRCServerChannel::getChannel($parts[2]);
                 $chan->event_notice($user, $content);
             }
             break;
         case 'MODE':
             $content = trim(implode(' ', array_slice($parts, 3)), ": ");
             $user = IRCServerUser::getByHostmask($parts[0]);
             if ($parts[2] != $this->nick) {
                 $chan = IRCServerChannel::getChannel($parts[2]);
                 $chan->event_mode($user, $content);
                 $chan->add_modes($content);
             }
             break;
         case '005':
             $this->online = TRUE;
             break;
         case '332':
             $content = trim(implode(' ', array_slice($parts, 4)), ": ");
             $chan = IRCServerChannel::getChannel($parts[3]);
             $chan->topic = $content;
             break;
         case '353':
             $channel_obj = IRCServerChannel::getChannel(strtolower($parts[4]));
             $channel_obj->event_names(trim(implode(' ', array_slice($parts, 5)), ": "));
             break;
         case '366':
             $channel_obj = IRCServerChannel::getChannel(strtolower($parts[3]));
             $channel_obj->event_names_end();
             break;
     }
 }
Ejemplo n.º 2
0
 /**
  * System Event raised when joining a channel
  * Processes the user list into user objects
  *
  * @access private
  */
 public function event_names_end()
 {
     $this->online = TRUE;
     foreach ($this->names as $nick) {
         $this->users[$nick] = IRCServerUser::getUser($nick, $this->channel);
     }
     $this->names = array();
     $this->event_joined();
 }