diff options
-rw-r--r-- | include/modules.h | 12 | ||||
-rw-r--r-- | include/modules/who.h | 80 | ||||
-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 |
7 files changed, 153 insertions, 50 deletions
diff --git a/include/modules.h b/include/modules.h index 8acf9089d..b4f13c6b7 100644 --- a/include/modules.h +++ b/include/modules.h @@ -226,7 +226,7 @@ enum Implementation I_OnPostOper, I_OnPostCommand, I_OnPostJoin, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass, I_OnUserMessage, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric, - I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP, + I_OnPreRehash, I_OnModuleRehash, I_OnChangeIdent, I_OnSetUserIP, I_OnServiceAdd, I_OnServiceDel, I_OnUserWrite, I_END }; @@ -916,16 +916,6 @@ class CoreExport Module : public classbase, public usecountbase virtual ModResult OnNumeric(User* user, const Numeric::Numeric& numeric); - /** Called whenever a result from /WHO is about to be returned - * @param source The user running the /WHO query - * @param params The parameters to the /WHO query - * @param user The user that this line of the query is about - * @param memb The member shown in this line, NULL if no channel is in this line - * @param numeric Numeric to send; modifiable. - * @return MOD_RES_PASSTHRU to allow the line to be displayed, MOD_RES_DENY to hide it - */ - virtual ModResult OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, Membership* memb, Numeric::Numeric& numeric); - /** Called whenever a local user's IP is set for the first time, or when a local user's IP changes due to * a module like m_cgiirc changing it. * @param user The user whose IP is being set diff --git a/include/modules/who.h b/include/modules/who.h new file mode 100644 index 000000000..4fcbe5f91 --- /dev/null +++ b/include/modules/who.h @@ -0,0 +1,80 @@ +/* + * InspIRCd -- Internet Relay Chat Daemon + * + * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com> + * + * This file is part of InspIRCd. InspIRCd is free software: you can + * redistribute it and/or modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#pragma once + +#include "event.h" + +namespace Who +{ + class EventListener; + class Request; +} + +class Who::EventListener : public Events::ModuleEventListener +{ + public: + EventListener(Module* mod) + : ModuleEventListener(mod, "event/who") + { + } + + /** Called when a result from WHO is about to be queued. + * @param request Details about the WHO request which caused this response. + * @param source The user who initiated this WHO request. + * @param user The user that this line of the WHO request is about. + * @param memb The channel membership of the user or NULL if not targeted at a channel. + * @param numeric The numeric which will be sent in response to the request. + * @return MOD_RES_ALLOW to explicitly allow the response, MOD_RES_DENY to explicitly deny the + * response, or MOD_RES_PASSTHRU to let another module handle the event. + */ + virtual ModResult OnWhoLine(const Request& request, LocalUser* source, User* user, Membership* memb, Numeric::Numeric& numeric) = 0; +}; + +class Who::Request +{ + public: + /** 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; + + protected: + Request() + : fuzzy_match(false) + , whox(false) + { + } +}; 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; } }; |