#include "wildcard.h"
#include "commands/cmd_who.h"
-static 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())
return i->first->name;
}
- return "*";
+ return star;
}
bool CommandWho::whomatch(User* user, const char* matchtext)
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) + " " +
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:
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++)
{
}
}
- 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)
{
opt_far = true;
break;
}
-
- *iter++;
}
}
{
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;
}
}