From b692377ffd5176e4be4394997c149773eb9405f7 Mon Sep 17 00:00:00 2001 From: pk910 Date: Wed, 27 Jul 2011 00:30:29 +0200 Subject: [PATCH] added recv_whois --- Uplink/P10Formatter.class.php | 7 +++ Uplink/P10_ModeSets.class.php | 17 ++++++- Uplink/P10_User.class.php | 4 ++ Uplink/Uplink.class.php | 85 +++++++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 1 deletion(-) diff --git a/Uplink/P10Formatter.class.php b/Uplink/P10Formatter.class.php index b5cba3d..e4235f4 100644 --- a/Uplink/P10Formatter.class.php +++ b/Uplink/P10Formatter.class.php @@ -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 ); diff --git a/Uplink/P10_ModeSets.class.php b/Uplink/P10_ModeSets.class.php index e03521d..d5088a2 100644 --- a/Uplink/P10_ModeSets.class.php +++ b/Uplink/P10_ModeSets.class.php @@ -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 diff --git a/Uplink/P10_User.class.php b/Uplink/P10_User.class.php index ac235b1..cd3a485 100644 --- a/Uplink/P10_User.class.php +++ b/Uplink/P10_User.class.php @@ -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); } diff --git a/Uplink/Uplink.class.php b/Uplink/Uplink.class.php index 0585595..7f0e0af 100644 --- a/Uplink/Uplink.class.php +++ b/Uplink/Uplink.class.php @@ -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 * ********************************************************************************************/ -- 2.20.1