]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/coremods/core_who.cpp
Use an oper priv instead of a config flag for overriding nonicks.
[user/henk/code/inspircd.git] / src / coremods / core_who.cpp
index 6cccb3634c463e8bfd6601318edb12cf5fdfd473..29feefc2ba8c095173968ba004c99b9138b11f22 100644 (file)
@@ -38,14 +38,18 @@ class CommandWho : public Command
        bool opt_time;
        ChanModeReference secretmode;
        ChanModeReference privatemode;
+       UserModeReference hidechansmode;
        UserModeReference invisiblemode;
 
-       Membership* get_first_visible_channel(User* u)
+       Membership* get_first_visible_channel(User* source, User* u)
        {
                for (User::ChanList::iterator i = u->chans.begin(); i != u->chans.end(); ++i)
                {
                        Membership* memb = *i;
-                       if (!memb->chan->IsModeSet(secretmode))
+
+                       /* XXX move the +I check into m_hidechans */
+                       bool has_modes = memb->chan->IsModeSet(secretmode) || memb->chan->IsModeSet(privatemode) || u->IsModeSet(hidechansmode);
+                       if (source == u || !has_modes || memb->chan->HasUser(source))
                                return memb;
                }
                return NULL;
@@ -58,18 +62,19 @@ class CommandWho : public Command
                : Command(parent, "WHO", 1)
                , secretmode(parent, "secret")
                , privatemode(parent, "private")
+               , hidechansmode(parent, "hidechans")
                , invisiblemode(parent, "invisible")
        {
                syntax = "<server>|<nickname>|<channel>|<realname>|<host>|0 [ohurmMiaplf]";
        }
 
-       void SendWhoLine(User* user, const std::vector<std::string>& parms, const std::string& initial, Membership* memb, User* u, std::vector<std::string>& whoresults);
+       void SendWhoLine(User* user, const std::vector<std::string>& parms, Membership* memb, User* u, std::vector<Numeric::Numeric>& whoresults);
        /** Handle command.
         * @param parameters The parameters to the command
         * @param user The user issuing the command
         * @return A value from CmdResult to indicate command success or failure.
         */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
+       CmdResult Handle(const std::vector<std::string>& parameters, User* user) CXX11_OVERRIDE;
        bool whomatch(User* cuser, User* user, const char* matchtext);
 };
 
@@ -123,7 +128,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
                else if (opt_realname)
                        match = InspIRCd::Match(user->fullname, matchtext);
                else if (opt_showrealhost)
-                       match = InspIRCd::Match(user->host, matchtext, ascii_case_insensitive_map);
+                       match = InspIRCd::Match(user->GetRealHost(), matchtext, ascii_case_insensitive_map);
                else if (opt_ident)
                        match = InspIRCd::Match(user->ident, matchtext, ascii_case_insensitive_map);
                else if (opt_port)
@@ -141,10 +146,10 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
                        match = InspIRCd::Match(user->awaymsg, matchtext);
                else if (opt_time)
                {
-                       long seconds = InspIRCd::Duration(matchtext);
+                       time_t seconds = ServerInstance->Time() - InspIRCd::Duration(matchtext);
 
                        // Okay, so time matching, we want all users connected `seconds' ago
-                       if (user->signon >= ServerInstance->Time() - seconds)
+                       if (user->signon >= seconds)
                                match = true;
                }
 
@@ -156,13 +161,13 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext)
                 * -- w00t
                 */
                if (!match)
-                       match = InspIRCd::Match(user->dhost, matchtext, ascii_case_insensitive_map);
+                       match = InspIRCd::Match(user->GetDisplayedHost(), matchtext, ascii_case_insensitive_map);
 
                if (!match)
                        match = InspIRCd::Match(user->nick, matchtext);
 
-               /* Don't allow server name matches if HideWhoisServer is enabled, unless the command user has the priv */
-               if (!match && (ServerInstance->Config->HideWhoisServer.empty() || cuser->HasPrivPermission("users/auspex")))
+               /* Don't allow server name matches if HideServer is enabled, unless the command user has the priv */
+               if (!match && (ServerInstance->Config->HideServer.empty() || cuser->HasPrivPermission("users/auspex")))
                        match = InspIRCd::Match(user->server->GetName(), matchtext);
 
                return match;
@@ -186,44 +191,48 @@ bool CommandWho::CanView(Channel* chan, User* user)
        return false;
 }
 
-void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms, const std::string& initial, Membership* memb, User* u, std::vector<std::string>& whoresults)
+void CommandWho::SendWhoLine(User* user, const std::vector<std::string>& parms, Membership* memb, User* u, std::vector<Numeric::Numeric>& whoresults)
 {
        if (!memb)
-               memb = get_first_visible_channel(u);
+               memb = get_first_visible_channel(user, u);
 
-       std::string wholine = initial + (memb ? memb->chan->name : "*") + " " + u->ident + " " +
-               (opt_showrealhost ? u->host : u->dhost) + " ";
-       if (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
-               wholine.append(ServerInstance->Config->HideWhoisServer);
+       Numeric::Numeric wholine(RPL_WHOREPLY);
+       wholine.push(memb ? memb->chan->name : "*").push(u->ident);
+       wholine.push(u->GetHost(opt_showrealhost));
+       if (!ServerInstance->Config->HideServer.empty() && !user->HasPrivPermission("servers/auspex"))
+               wholine.push(ServerInstance->Config->HideServer);
        else
-               wholine.append(u->server->GetName());
+               wholine.push(u->server->GetName());
 
-       wholine.append(" " + u->nick + " ");
+       wholine.push(u->nick);
 
+       std::string param;
        /* away? */
        if (u->IsAway())
        {
-               wholine.append("G");
+               param.push_back('G');
        }
        else
        {
-               wholine.append("H");
+               param.push_back('H');
        }
 
        /* oper? */
        if (u->IsOper())
        {
-               wholine.push_back('*');
+               param.push_back('*');
        }
 
        if (memb)
        {
                char prefix = memb->GetPrefixChar();
                if (prefix)
-                       wholine.push_back(prefix);
+                       param.push_back(prefix);
        }
 
-       wholine.append(" :0 " + u->fullname);
+       wholine.push(param);
+       wholine.push("0 ");
+       wholine.GetParams().back().append(u->fullname);
 
        ModResult res;
        FIRST_MOD_RESULT(OnSendWhoLine, res, (user, parms, u, memb, wholine));
@@ -253,8 +262,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
        opt_far = false;
        opt_time = false;
 
-       std::vector<std::string> whoresults;
-       std::string initial = "352 " + user->nick + " ";
+       std::vector<Numeric::Numeric> whoresults;
 
        /* Change '0' into '*' so the wildcard matcher can grok it */
        std::string matchtext = ((parameters[0] == "0") ? "*" : parameters[0]);
@@ -297,11 +305,11 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                        opt_away = true;
                                        break;
                                case 'l':
-                                       if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideWhoisServer.empty())
+                                       if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideServer.empty())
                                                opt_local = true;
                                        break;
                                case 'f':
-                                       if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideWhoisServer.empty())
+                                       if (user->HasPrivPermission("users/auspex") || ServerInstance->Config->HideServer.empty())
                                                opt_far = true;
                                        break;
                                case 't':
@@ -337,7 +345,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                continue;
                                }
 
-                               SendWhoLine(user, parameters, initial, i->second, i->first, whoresults);
+                               SendWhoLine(user, parameters, i->second, i->first, whoresults);
                        }
                }
        }
@@ -360,7 +368,7 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                        continue;
                                        }
 
-                                       SendWhoLine(user, parameters, initial, NULL, oper, whoresults);
+                                       SendWhoLine(user, parameters, NULL, oper, whoresults);
                                }
                        }
                }
@@ -377,14 +385,14 @@ CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *
                                                        continue;
                                        }
 
-                                       SendWhoLine(user, parameters, initial, NULL, i->second, whoresults);
+                                       SendWhoLine(user, parameters, NULL, i->second, whoresults);
                                }
                        }
                }
        }
        /* Send the results out */
-       for (std::vector<std::string>::const_iterator n = whoresults.begin(); n != whoresults.end(); n++)
-               user->WriteServ(*n);
+       for (std::vector<Numeric::Numeric>::const_iterator n = whoresults.begin(); n != whoresults.end(); ++n)
+               user->WriteNumeric(*n);
        user->WriteNumeric(RPL_ENDOFWHO, (*parameters[0].c_str() ? parameters[0] : "*"), "End of /WHO list.");
 
        // Penalize the user a bit for large queries