added recv_whois
authorpk910 <philipp@zoelle1.de>
Tue, 26 Jul 2011 22:30:29 +0000 (00:30 +0200)
committerpk910 <philipp@zoelle1.de>
Tue, 26 Jul 2011 22:30:29 +0000 (00:30 +0200)
Uplink/P10Formatter.class.php
Uplink/P10_ModeSets.class.php
Uplink/P10_User.class.php
Uplink/Uplink.class.php

index b5cba3d7689636decb9ffeb906c0c3f4b628aff8..e4235f458a3705901e858b8a7308142068a7a71b 100644 (file)
@@ -52,6 +52,13 @@ class P10Formatter {
                "M"      => "%s M %s %s",
                "SM"     => "%s SM %s %s",
                "OM"     => "%s OM %s %s",
+               "311"    => "{num} 311 %s %s %s %s * :%s",
+               "319"    => "{num} 319 %s %s :%s",
+               "312"    => "{num} 312 %s %s %s :%s",
+               "313"    => "{num} 313 %s %s :%s",
+               "330"    => "{num} 330 %s %s %s :is logged in as",
+               "318"    => "{num} 318 %s %s :End of /WHOIS list.",
+               "401"    => "{num} 401 %s %s :No such nick",
                null     => null
        );
        
index e03521d24ab83fb25a426ed87a22ec36d2e6ce88..d5088a29fe53aad2fd7dc08853d17e1ba90aa4d4 100644 (file)
@@ -224,7 +224,10 @@ class P10_ChannelModeSet {
                        continue;
                }
                $flag = self::$modevalues[$mode];
-               return ($this->modeflags & $flag);
+               if(self::$modevalues[$mode] == self::MODE_TYPE_B || self::$modevalues[$mode] == self::MODE_TYPE_C) {
+                       return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false);
+               } else
+                       return ($this->modeflags & $flag);
        }
        
 }
@@ -354,6 +357,18 @@ class P10_UserModeSet {
                return $modestr.$paramstr;
        }
        
+       public function hasMode($mode) {
+               if(!array_key_exists($mode, self::$modevalues)) {
+                       trigger_error("unknown mode (".$mode.") on setModes (".$modes.").", E_USER_WARNING);
+                       continue;
+               }
+               $flag = self::$modevalues[$mode];
+               if(self::$modevalues[$mode] == self::MODE_WITH_PARAMETER) {
+                       return (($this->modeflags & $flag) ? $this->modeparams[$mode] : false);
+               } else
+                       return ($this->modeflags & $flag);
+       }
+       
 }
 
 ?>
\ No newline at end of file
index ac235b140800c4d37c0a4d5177dfa1f3a24df966..cd3a485d51a0426da735778705c985cd46bdb9c0 100644 (file)
@@ -144,6 +144,10 @@ class P10_User {
                }
        }
        
+       public function getChannels() {
+               return $this->channels;
+       }
+       
        public function isOnChannel($channel) {
                return array_key_exists(strtolower($channel->getName()),$this->channels);
        }
index 0585595fdce6a576cfff90eb9370b0c6131581ac..7f0e0af661225ec233468b11bf35f8b4f0c0e0cd 100644 (file)
@@ -47,6 +47,9 @@
  * void setValidateServer(String $name, String $password)
  *     sets additional security relevant information about the remote server.
  *
+ * void setHISOptions(String $serverName, String $serverDescription String $usermask)
+ *     sets the default Account fakehost
+ *
  * void setEventHandler(EventHandler $event_handler)
  *     sets the EventHandlder
  */
@@ -84,6 +87,7 @@ class Uplink {
        public function __construct() {
                $this->client = new Client();
                $this->setSetting("recv_timeout", 1000);
+               $this->setSetting("his_usermask", "user.NoMask");
        }
        
        public function initialize() {
@@ -161,6 +165,12 @@ class Uplink {
                $this->setSetting("their_password", $password);
        }
        
+       public function setHISOptions($servername, $serverdesc, $usermask) {
+               $this->setSetting("his_name", $servername);
+               $this->setSetting("his_desc", $serverdesc);
+               $this->setSetting("his_usermask", $usermask);
+       }
+       
        public function setEventHandler($event_handler) {
                if(!is_a($event_handler, "EventHandler")) {
                        trigger_error((is_object($event_handler) ? get_class($event_handler) : gettype($event_handler))." is NOT a valid EventHandler.", E_USER_ERROR);
@@ -254,6 +264,9 @@ class Uplink {
                        case "O":
                                $this->recv_notice($from, $arguments);
                                break;
+                       case "W":
+                               $this->recv_whois($from, $arguments);
+                               break;
                //default
                        default:
                                //unknown cmd
@@ -559,6 +572,78 @@ class Uplink {
                }
        }
        
+       private function recv_whois($from, $args) {
+               /* [get] ACAAF W AX :NetworkServ */
+               $fromUser = P10_User::getUserByNum($from);
+               if($fromUser == null) {
+                       trigger_error("Server tries to send a whois from an user that does not exist or was not found on recv_whois.", E_USER_ERROR);
+                       return;
+               }
+               $users=explode(",",$args[1]);
+               foreach($users as $nick) {
+                       $user = P10_User::getUserByNick($nick);
+                       if(!$user) {
+                               $this->send("401", $from, $nick);
+                               continue;
+                       }
+                       $nick = $user->getNick();
+                       $ident = $user->getIdent();
+                       $hostmask = $user->getHost();
+                       $modes = $user->getModes();
+                       if($modes->hasMode('x')) {
+                               if(($fakehost = $modes->hasMode('f'))) {
+                                       $hostmask = $fakehost;
+                               } elseif(($account = $modes->hasMode('r'))) {
+                                       $hostmask = $account.".".$this->getSetting("his_usermask");
+                               }
+                       }
+                       $realname = $user->getRealname();
+                       $this->send("311", $from , $nick, $ident, $hostmask, $realname);
+                       if(((!$modes->hasMode('n') && !$modes->hasMode('k')) || $from == $user->getNumeric()) && count($user->getChannels()) != 0) {
+                               $channels = "";
+                               foreach($user->getChannels() as $channel) {
+                                       $cmodes = $channel->getModes();
+                                       $privs = $channel->getUserPrivs($user);
+                                       if($cmodes->hasMode("s") && !$fromUser->isOnChannel($channel) && $from != $user->getNumeric()) continue;
+                                       if($cmodes->hasMode("u") && ($privs & (P10_Channel::USERPRIV_OPPED | P10_Channel::USERPRIV_VOICE)) == 0 && $from != $user->getNumeric()) continue;
+                                       $chanstr = ($channels == "" ? "" : " ");
+                                       $prefix = "";
+                                       if(($privs & P10_Channel::USERPRIV_OPPED)) {
+                                               $prefix = "@";
+                                       } else if(($privs & P10_Channel::USERPRIV_VOICE)) {
+                                               $prefix = "+";
+                                       }
+                                       $chanstr .= $prefix.$channel->getName();
+                                       if(strlen($channels) + strlen($chanstr) > 450) {
+                                               $this->send("319", $from, $nick, $channels);
+                                               $channels = $prefix.$channel->getName();
+                                       }
+                               }
+                               if($channels != "") {
+                                       $this->send("319", $from, $nick, $channels);
+                               }
+                               if($fromUser->getModes()->hasMode("o") || $from == $user->getNumeric() || !$this->getSetting("his_name")) {
+                                       $this->send("312", $from, $nick, $user->getServer()->getName(), $user->getServer()->getDescription());
+                               } else {
+                                       $this->send("312", $from, $nick, $this->getSetting("his_name"), $this->getSetting("his_desc"));
+                               }
+                               if($modes->hasMode("o") && (!$modes->hasMode("H") || $fromUser->getModes()->hasMode("o"))) {
+                                       if($modes->hasMode("S")) {
+                                               if($modes->hasMode("D"))
+                                                       $this->send("313", $from, $nick, "is a Network Service");
+                                               else
+                                                       $this->send("313", $from, $nick, "is an illegal Network Service - HACKER!");
+                                       } else
+                                               $this->send("313", $from, $nick, "is an IRC Operator");
+                               }
+                               if(($auth = $modes->hasMode("r"))) {
+                                       $this->send("330", $from, $nick, $auth);
+                               }
+                       }
+               }
+               $this->send("318", $from, $args[1]);
+       }
+       
        /********************************************************************************************
         *                                     SERVER FUNCTIONS                                     *
         ********************************************************************************************/