#include "inspircd.h"
#include "modules/account.h"
+#include "modules/who.h"
enum
{
RPL_WHOSPCRPL = 354
};
-struct WhoData
-{
- // The flags for matching users to include.
- std::bitset<UCHAR_MAX> flags;
-
- // Whether we are matching using a wildcard or a flag.
- bool fuzzy_match;
+static const char whox_field_order[] = "tcuihsnfdlaor";
+static const char who_field_order[] = "cuhsnf";
- // The text to match against.
- std::string matchtext;
+struct WhoData : public Who::Request
+{
+ bool GetFieldIndex(char flag, size_t& out) const CXX11_OVERRIDE
+ {
+ if (!whox)
+ {
+ const char* pos = strchr(who_field_order, flag);
+ if (pos == NULL)
+ return false;
- // The WHO/WHOX responses we will send to the source.
- std::vector<Numeric::Numeric> results;
+ out = pos - who_field_order;
+ return true;
+ }
- // Whether the source requested a WHOX response.
- bool whox;
+ if (!whox_fields[flag])
+ return false;
- // The fields to include in the WHOX response.
- std::bitset<UCHAR_MAX> whox_fields;
+ out = 0;
+ for (const char* c = whox_field_order; *c && *c != flag; ++c)
+ {
+ if (whox_fields[*c])
+ ++out;
+ }
- // A user specified label for the WHOX response.
- std::string whox_querytype;
+ return whox_field_order[out];
+ }
- WhoData(const std::vector<std::string>& parameters)
- : whox(false)
+ WhoData(const CommandBase::Params& parameters)
{
// Find the matchtext and swap the 0 for a * so we can use InspIRCd::Match on it.
matchtext = parameters.size() > 2 ? parameters[2] : parameters[0];
ChanModeReference privatemode;
UserModeReference hidechansmode;
UserModeReference invisiblemode;
+ Events::ModuleEventProvider whoevprov;
/** Determines whether a user can view the users of a channel. */
bool CanView(Channel* chan, User* user)
}
/** Determines whether WHO flags match a specific channel user. */
- static bool MatchChannel(LocalUser* source, Membership* memb, WhoData& data);
+ bool MatchChannel(LocalUser* source, Membership* memb, WhoData& data);
/** Determines whether WHO flags match a specific user. */
static bool MatchUser(LocalUser* source, User* target, WhoData& data);
, privatemode(parent, "private")
, hidechansmode(parent, "hidechans")
, invisiblemode(parent, "invisible")
+ , whoevprov(parent, "event/who")
{
allow_empty_last_param = false;
- syntax = "<server>|<nickname>|<channel>|<realname>|<host>|0 [[Aafhilmnoprstu] <server>|<nickname>|<channel>|<realname>|<host>|0]";
+ syntax = "<server>|<nick>|<channel>|<realname>|<host>|0 [[Aafhilmnoprstux][%acdfhilnorstu] <server>|<nick>|<channel>|<realname>|<host>|0]";
}
/** Sends a WHO reply to a user. */
void SendWhoLine(LocalUser* user, const std::vector<std::string>& parameters, Membership* memb, User* u, WhoData& data);
- CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser* user) CXX11_OVERRIDE;
+ CmdResult HandleLocal(LocalUser* user, const Params& parameters) CXX11_OVERRIDE;
};
template<> User* CommandWho::GetUser(UserManager::OperList::const_iterator& t) { return *t; }
long port;
while ((port = portrange.GetToken()))
{
- if (port == lu->GetServerPort())
+ if (port == lu->server_sa.port())
{
match = true;
break;
// The source wants to match against users' real names.
else if (data.flags['r'])
- match = InspIRCd::Match(user->fullname, data.matchtext, ascii_case_insensitive_map);
+ match = InspIRCd::Match(user->GetRealName(), data.matchtext, ascii_case_insensitive_map);
else if (data.flags['s'])
{
}
if (!match)
- match = InspIRCd::Match(user->fullname, data.matchtext, ascii_case_insensitive_map);
+ match = InspIRCd::Match(user->GetRealName(), data.matchtext, ascii_case_insensitive_map);
if (!match)
match = InspIRCd::Match(user->nick, data.matchtext);
// Include the user's real name.
if (data.whox_fields['r'])
- wholine.push(user->fullname);
+ wholine.push(user->GetRealName());
}
else
{
// Include the number of hops between the users and the user's real name.
wholine.push("0 ");
- wholine.GetParams().back().append(user->fullname);
+ wholine.GetParams().back().append(user->GetRealName());
}
ModResult res;
- FIRST_MOD_RESULT(OnSendWhoLine, res, (source, parameters, user, memb, wholine));
+ FIRST_MOD_RESULT_CUSTOM(whoevprov, Who::EventListener, OnWhoLine, res, (data, source, user, memb, wholine));
if (res != MOD_RES_DENY)
data.results.push_back(wholine);
}
-CmdResult CommandWho::HandleLocal(const std::vector<std::string>& parameters, LocalUser* user)
+CmdResult CommandWho::HandleLocal(LocalUser* user, const Params& parameters)
{
WhoData data(parameters);