diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/coremods/core_who.cpp | 31 | ||||
-rw-r--r-- | src/modules.cpp | 1 | ||||
-rw-r--r-- | src/modules/m_auditorium.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_hideoper.cpp | 35 | ||||
-rw-r--r-- | src/modules/m_namesx.cpp | 34 |
5 files changed, 72 insertions, 39 deletions
diff --git a/src/coremods/core_who.cpp b/src/coremods/core_who.cpp index d2d97dc18..132f8bc1e 100644 --- a/src/coremods/core_who.cpp +++ b/src/coremods/core_who.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "modules/account.h" +#include "modules/who.h" enum { @@ -33,31 +34,9 @@ enum RPL_WHOSPCRPL = 354 }; -struct WhoData +struct WhoData : public Who::Request { - // 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; - - // The text to match against. - std::string matchtext; - - // The WHO/WHOX responses we will send to the source. - std::vector<Numeric::Numeric> results; - - // Whether the source requested a WHOX response. - bool whox; - - // The fields to include in the WHOX response. - std::bitset<UCHAR_MAX> whox_fields; - - // A user specified label for the WHOX response. - std::string whox_querytype; - WhoData(const CommandBase::Params& parameters) - : whox(false) { // 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]; @@ -105,6 +84,7 @@ class CommandWho : public SplitCommand 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) @@ -137,7 +117,7 @@ class CommandWho : public SplitCommand } /** 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); @@ -160,6 +140,7 @@ class CommandWho : public SplitCommand , 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 [[Aafhilmnoprstux][%acdfhilnorstu] <server>|<nickname>|<channel>|<realname>|<host>|0]"; @@ -534,7 +515,7 @@ void CommandWho::SendWhoLine(LocalUser* source, const std::vector<std::string>& } 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); } diff --git a/src/modules.cpp b/src/modules.cpp index 3062aad43..c2233a893 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -133,7 +133,6 @@ void Module::OnUserMessage(User*, const MessageTarget&, const MessageDetails&) ModResult Module::OnNamesListItem(User*, Membership*, std::string&, std::string&) { DetachEvent(I_OnNamesListItem); return MOD_RES_PASSTHRU; } ModResult Module::OnNumeric(User*, const Numeric::Numeric&) { DetachEvent(I_OnNumeric); return MOD_RES_PASSTHRU; } ModResult Module::OnAcceptConnection(int, ListenSocket*, irc::sockets::sockaddrs*, irc::sockets::sockaddrs*) { DetachEvent(I_OnAcceptConnection); return MOD_RES_PASSTHRU; } -ModResult Module::OnSendWhoLine(User*, const std::vector<std::string>&, User*, Membership*, Numeric::Numeric&) { DetachEvent(I_OnSendWhoLine); return MOD_RES_PASSTHRU; } void Module::OnSetUserIP(LocalUser*) { DetachEvent(I_OnSetUserIP); } void Module::OnServiceAdd(ServiceProvider&) { DetachEvent(I_OnServiceAdd); } void Module::OnServiceDel(ServiceProvider&) { DetachEvent(I_OnServiceDel); } diff --git a/src/modules/m_auditorium.cpp b/src/modules/m_auditorium.cpp index 8485f1d7a..818242795 100644 --- a/src/modules/m_auditorium.cpp +++ b/src/modules/m_auditorium.cpp @@ -22,6 +22,7 @@ #include "inspircd.h" #include "modules/exemption.h" +#include "modules/who.h" class AuditoriumMode : public SimpleChannelModeHandler { @@ -55,7 +56,9 @@ class JoinHook : public ClientProtocol::EventHook } -class ModuleAuditorium : public Module +class ModuleAuditorium + : public Module + , public Who::EventListener { CheckExemption::EventProvider exemptionprov; AuditoriumMode aum; @@ -66,7 +69,8 @@ class ModuleAuditorium : public Module public: ModuleAuditorium() - : exemptionprov(this) + : Who::EventListener(this) + , exemptionprov(this) , aum(this) , joinhook(this) { @@ -173,7 +177,7 @@ class ModuleAuditorium : public Module } } - ModResult OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE + ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE { if (!memb) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp index 2bca0a156..f04d88809 100644 --- a/src/modules/m_hideoper.cpp +++ b/src/modules/m_hideoper.cpp @@ -21,6 +21,7 @@ #include "inspircd.h" #include "modules/stats.h" +#include "modules/who.h" #include "modules/whois.h" /** Handles user mode +H @@ -50,13 +51,20 @@ class HideOper : public SimpleUserModeHandler } }; -class ModuleHideOper : public Module, public Stats::EventListener, public Whois::LineEventListener +class ModuleHideOper + : public Module + , public Stats::EventListener + , public Who::EventListener + , public Whois::LineEventListener { + private: HideOper hm; bool active; + public: ModuleHideOper() : Stats::EventListener(this) + , Who::EventListener(this) , Whois::LineEventListener(this) , hm(this) , active(false) @@ -107,20 +115,37 @@ class ModuleHideOper : public Module, public Stats::EventListener, public Whois: return MOD_RES_PASSTHRU; } - ModResult OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE + ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE { if (user->IsModeSet(hm) && !source->HasPrivPermission("users/auspex")) { // Hide the line completely if doing a "/who * o" query - if ((params.size() > 1) && (params[1].find('o') != std::string::npos)) + if (request.flags['o']) return MOD_RES_DENY; + size_t flag_index = 5; + if (request.whox) + { + // We only need to fiddle with the flags if they are present. + if (!request.whox_fields['f']) + return MOD_RES_PASSTHRU; + + // WHOX makes this a bit tricky as we need to work out the parameter which the flags are in. + flag_index = 0; + static const char* flags = "tcuihsn"; + for (size_t i = 0; i < strlen(flags); ++i) + { + if (request.whox_fields[flags[i]]) + flag_index += 1; + } + } + // hide the "*" that marks the user as an oper from the /WHO line // #chan ident localhost insp22.test nick H@ :0 Attila - if (numeric.GetParams().size() < 6) + if (numeric.GetParams().size() <= flag_index) return MOD_RES_PASSTHRU; - std::string& param = numeric.GetParams()[5]; + std::string& param = numeric.GetParams()[flag_index]; const std::string::size_type pos = param.find('*'); if (pos != std::string::npos) param.erase(pos, 1); diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp index 708b98e56..defb66b78 100644 --- a/src/modules/m_namesx.cpp +++ b/src/modules/m_namesx.cpp @@ -22,12 +22,19 @@ #include "inspircd.h" #include "modules/cap.h" +#include "modules/who.h" -class ModuleNamesX : public Module +class ModuleNamesX + : public Module + , public Who::EventListener { + private: Cap::Capability cap; + public: - ModuleNamesX() : cap(this, "multi-prefix") + ModuleNamesX() + : Who::EventListener(this) + , cap(this, "multi-prefix") { } @@ -67,7 +74,7 @@ class ModuleNamesX : public Module return MOD_RES_PASSTHRU; } - ModResult OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE + ModResult OnWhoLine(const Who::Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) CXX11_OVERRIDE { if ((!memb) || (!cap.get(source))) return MOD_RES_PASSTHRU; @@ -77,11 +84,28 @@ class ModuleNamesX : public Module if (prefixes.length() <= 1) return MOD_RES_PASSTHRU; + size_t flag_index = 5; + if (request.whox) + { + // We only need to fiddle with the flags if they are present. + if (!request.whox_fields['f']) + return MOD_RES_PASSTHRU; + + // WHOX makes this a bit tricky as we need to work out the parameter which the flags are in. + flag_index = 0; + static const char* flags = "tcuihsn"; + for (size_t i = 0; i < strlen(flags); ++i) + { + if (request.whox_fields[flags[i]]) + flag_index += 1; + } + } + // #chan ident localhost insp22.test nick H@ :0 Attila - if (numeric.GetParams().size() < 6) + if (numeric.GetParams().size() <= flag_index) return MOD_RES_PASSTHRU; - numeric.GetParams()[5].append(prefixes, 1, std::string::npos); + numeric.GetParams()[flag_index].append(prefixes, 1, std::string::npos); return MOD_RES_PASSTHRU; } }; |