]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands/cmd_who.cpp
match() is no longer a function+no header, now a static method of InspIRCd class...
[user/henk/code/inspircd.git] / src / commands / cmd_who.cpp
index a54623672f834269c4c4ed24278b5d020ac1ffea..845670acf7f67cd1dc9693619569a3e9f3c839dd 100644 (file)
  */
 
 #include "inspircd.h"
-#include "wildcard.h"
 #include "commands/cmd_who.h"
 
-static const char *get_first_visible_channel(User *u)
+static const std::string star = "*";
+
+static const std::string& get_first_visible_channel(User *u)
 {
        UCListIter i = u->chans.begin();
        if (i != u->chans.end())
@@ -24,7 +25,7 @@ static const char *get_first_visible_channel(User *u)
                        return i->first->name;
        }
 
-       return "*";
+       return star;
 }
 
 bool CommandWho::whomatch(User* user, const char* matchtext)
@@ -73,15 +74,15 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
                else
                {
                        if (opt_realname)
-                               realname = match(user->fullname, matchtext);
+                               realname = InspIRCd::Match(user->fullname, matchtext, lowermap);
                        else
                        {
                                if (opt_showrealhost)
-                                       realhost = match(user->host, matchtext);
+                                       realhost = InspIRCd::Match(user->host, matchtext, lowermap);
                                else
                                {
                                        if (opt_ident)
-                                               ident = match(user->ident, matchtext);
+                                               ident = InspIRCd::Match(user->ident, matchtext, lowermap);
                                        else
                                        {
                                                if (opt_port)
@@ -95,13 +96,13 @@ bool CommandWho::whomatch(User* user, const char* matchtext)
                                                else
                                                {
                                                        if (opt_away)
-                                                               away = match(user->awaymsg, matchtext);
+                                                               away = InspIRCd::Match(user->awaymsg, matchtext, lowermap);
                                                }
                                        }
                                }
                        }
                }
-               return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (match(user->dhost, matchtext)) || (match(user->nick, matchtext)) || (match(user->server, matchtext)));
+               return ((port) || (away) || (ident) || (metadata) || (realname) || (realhost) || (InspIRCd::Match(user->dhost, matchtext, lowermap)) || (InspIRCd::Match(user->nick, matchtext, lowermap)) || (InspIRCd::Match(user->server, matchtext, lowermap)));
        }
 }
 
@@ -138,7 +139,7 @@ void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch
        if (u->Visibility && !u->Visibility->VisibleTo(user))
                return;
 
-       std::string lcn = get_first_visible_channel(u);
+       const std::string& lcn = get_first_visible_channel(u);
        Channel* chlast = ServerInstance->FindChan(lcn);
 
        std::string wholine =   initial + (ch ? ch->name : lcn) + " " + u->ident + " " + (opt_showrealhost ? u->host : u->dhost) + " " +
@@ -165,7 +166,7 @@ void CommandWho::SendWhoLine(User* user, const std::string &initial, Channel* ch
        whoresults.push_back(wholine);
 }
 
-CmdResult CommandWho::Handle (const char** parameters, int pcnt, User *user)
+CmdResult CommandWho::Handle (const std::vector<std::string>& parameters, User *user)
 {
        /*
         * XXX - RFC says:
@@ -191,13 +192,14 @@ CmdResult CommandWho::Handle (const char** parameters, int pcnt, User *user)
        std::vector<std::string> whoresults;
        std::string initial = "352 " + std::string(user->nick) + " ";
 
-       const char* matchtext = NULL;
+       char matchtext[MAXBUF];
        bool usingwildcards = false;
 
        /* Change '0' into '*' so the wildcard matcher can grok it */
-       matchtext = parameters[0];
-       if (!strcmp(matchtext,"0"))
-               matchtext = "*";
+       if (parameters[0] == "0")
+               strlcpy(matchtext, "*", MAXBUF);
+       else
+               strlcpy(matchtext, parameters[0].c_str(), MAXBUF);
 
        for (const char* check = matchtext; *check; check++)
        {
@@ -208,15 +210,15 @@ CmdResult CommandWho::Handle (const char** parameters, int pcnt, User *user)
                }
        }
 
-       if (pcnt > 1)
-       {
-               /* parse flags */
-               const char *iter = parameters[1];
+       if (ServerInstance->FindServerName(matchtext))
+               usingwildcards = true;
 
+       if (parameters.size() > 1)
+       {
                /* Fix for bug #444, WHO flags count as a wildcard */
                usingwildcards = true;
 
-               while (*iter)
+               for (std::string::const_iterator iter = parameters[1].begin(); iter != parameters[1].end(); ++iter)
                {
                        switch (*iter)
                        {
@@ -256,8 +258,6 @@ CmdResult CommandWho::Handle (const char** parameters, int pcnt, User *user)
                                        opt_far = true;
                                break;
                        }
-
-                       *iter++;
                }
        }
 
@@ -336,13 +336,13 @@ CmdResult CommandWho::Handle (const char** parameters, int pcnt, User *user)
        {
                for (std::vector<std::string>::const_iterator n = whoresults.begin(); n != whoresults.end(); n++)
                        user->WriteServ(*n);
-               user->WriteServ("315 %s %s :End of /WHO list.",user->nick, *parameters[0] ? parameters[0] : "*");
+               user->WriteNumeric(315, "%s %s :End of /WHO list.",user->nick.c_str(), *parameters[0].c_str() ? parameters[0].c_str() : "*");
                return CMD_SUCCESS;
        }
        else
        {
                /* BZZT! Too many results. */
-               user->WriteServ("315 %s %s :Too many results",user->nick, parameters[0]);
+               user->WriteNumeric(315, "%s %s :Too many results",user->nick.c_str(), parameters[0].c_str());
                return CMD_FAILURE;
        }
 }