summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2015-05-04 13:24:48 +0200
committerAttila Molnar <attilamolnar@hush.com>2015-05-04 13:24:48 +0200
commit4711113dff7fc33c96f95f417f2813f28c690e01 (patch)
tree7ccecb9e52f6c13c233a3efe312410a1c8e526a0
parent8aa03e455e14ea85cdee65527565975ddf558b88 (diff)
parent68bb6a67459298ca08eb18b60794619ddf782c77 (diff)
Merge branch 'master+whoiscontext'
-rw-r--r--include/inspircd.h19
-rw-r--r--include/modules.h25
-rw-r--r--include/modules/whois.h116
-rw-r--r--src/coremods/core_whois.cpp107
-rw-r--r--src/helperfuncs.cpp18
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/m_botmode.cpp11
-rw-r--r--src/modules/m_customtitle.cpp12
-rw-r--r--src/modules/m_helpop.cpp12
-rw-r--r--src/modules/m_services_account.cpp10
-rw-r--r--src/modules/m_servprotect.cpp13
-rw-r--r--src/modules/m_showwhois.cpp12
-rw-r--r--src/modules/m_sslinfo.cpp17
-rw-r--r--src/modules/m_swhois.cpp12
14 files changed, 250 insertions, 136 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index ef19c6d26..b90c0c797 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -604,23 +604,6 @@ class CoreExport InspIRCd
*/
InspIRCd(int argc, char** argv);
- /** Send a line of WHOIS data to a user.
- * @param user user to send the line to
- * @param dest user being WHOISed
- * @param numeric Numeric to send
- * @param text Text of the numeric
- */
- void SendWhoisLine(User* user, User* dest, int numeric, const std::string &text);
-
- /** Send a line of WHOIS data to a user.
- * @param user user to send the line to
- * @param dest user being WHOISed
- * @param numeric Numeric to send
- * @param format Format string for the numeric
- * @param ... Parameters for the format string
- */
- void SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...) CUSTOM_PRINTF(5, 6);
-
/** Called to check whether a channel restriction mode applies to a user
* @param User that is attempting some action
* @param Channel that the action is being performed on
@@ -685,3 +668,5 @@ inline void stdalgo::culldeleter::operator()(classbase* item)
if (item)
ServerInstance->GlobalCulls.AddItem(item);
}
+
+#include "modules/whois.h"
diff --git a/include/modules.h b/include/modules.h
index fc2aa6324..1fd1c7e00 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -222,7 +222,7 @@ enum Priority { PRIORITY_FIRST, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }
enum Implementation
{
I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart,
- I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois,
+ I_OnSendSnotice, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo,
I_OnUserPreInvite, I_OnUserInvite, I_OnUserPreMessage, I_OnUserPreNick,
I_OnUserMessage, I_OnMode, I_OnSyncUser,
I_OnSyncChannel, I_OnDecodeMetaData, I_OnAcceptConnection, I_OnUserInit,
@@ -234,7 +234,7 @@ enum Implementation
I_OnPostTopicChange, I_OnPostConnect,
I_OnChangeLocalUserGECOS, I_OnUserRegister, I_OnChannelPreDelete, I_OnChannelDelete,
I_OnPostOper, I_OnSyncNetwork, I_OnSetAway, I_OnPostCommand, I_OnPostJoin,
- I_OnWhoisLine, I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass,
+ I_OnBuildNeighborList, I_OnGarbageCollect, I_OnSetConnectClass,
I_OnText, I_OnPassCompare, I_OnNamesListItem, I_OnNumeric,
I_OnPreRehash, I_OnModuleRehash, I_OnSendWhoLine, I_OnChangeIdent, I_OnSetUserIP,
I_END
@@ -469,14 +469,6 @@ class CoreExport Module : public classbase, public usecountbase
*/
virtual void OnInfo(User* user);
- /** Called whenever a /WHOIS is performed on a local user.
- * The source parameter contains the details of the user who issued the WHOIS command, and
- * the dest parameter contains the information of the user they are whoising.
- * @param source The user issuing the WHOIS command
- * @param dest The user who is being WHOISed
- */
- virtual void OnWhois(User* source, User* dest);
-
/** Called whenever a user is about to invite another user into a channel, before any processing is done.
* Returning 1 from this function stops the process immediately, causing no
* output to be sent to the user by the core. If you do this you must produce your own numerics,
@@ -962,19 +954,6 @@ class CoreExport Module : public classbase, public usecountbase
*/
virtual ModResult OnSetAway(User* user, const std::string &awaymsg);
- /** Called whenever a line of WHOIS output is sent to a user.
- * You may change the numeric and the text of the output by changing
- * the values numeric and text, but you cannot change the user the
- * numeric is sent to. You may however change the user's User values.
- * @param user The user the numeric is being sent to
- * @param dest The user being WHOISed
- * @param numeric The numeric of the line being sent
- * @param text The text of the numeric, including any parameters
- * @return nonzero to drop the line completely so that the user does not
- * receive it, or zero to allow the line to be sent.
- */
- virtual ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text);
-
/** Called at intervals for modules to garbage-collect any hashes etc.
* Certain data types such as hash_map 'leak' buckets, which must be
* tidied up and freed by copying into a new item every so often. This
diff --git a/include/modules/whois.h b/include/modules/whois.h
new file mode 100644
index 000000000..b64d46410
--- /dev/null
+++ b/include/modules/whois.h
@@ -0,0 +1,116 @@
+/*
+ * 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 Whois
+{
+ class EventListener;
+ class LineEventListener;
+ class Context;
+}
+
+class Whois::EventListener : public Events::ModuleEventListener
+{
+ public:
+ EventListener(Module* mod)
+ : ModuleEventListener(mod, "event/whois")
+ {
+ }
+
+ /** Called whenever a /WHOIS is performed by a local user.
+ * @param whois Whois context, can be used to send numerics
+ */
+ virtual void OnWhois(Context& whois) = 0;
+};
+
+class Whois::LineEventListener : public Events::ModuleEventListener
+{
+ public:
+ LineEventListener(Module* mod)
+ : ModuleEventListener(mod, "event/whoisline")
+ {
+ }
+
+ /** Called whenever a line of WHOIS output is sent to a user.
+ * You may change the numeric and the text of the output by changing
+ * the values numeric and text, but you cannot change the user the
+ * numeric is sent to.
+ * @param whois Whois context, can be used to send numerics
+ * @param numeric The numeric of the line being sent
+ * @param text The text of the numeric, including any parameters
+ * @return MOD_RES_DENY to drop the line completely so that the user does not
+ * receive it, or MOD_RES_PASSTHRU to allow the line to be sent.
+ */
+ virtual ModResult OnWhoisLine(Context& whois, unsigned int& numeric, std::string& text) = 0;
+};
+
+class Whois::Context
+{
+ protected:
+ /** User doing the WHOIS
+ */
+ LocalUser* const source;
+
+ /** User being WHOISed
+ */
+ User* const target;
+
+ public:
+ Context(LocalUser* src, User* targ)
+ : source(src)
+ , target(targ)
+ {
+ }
+
+ /** Returns true if the user is /WHOISing himself
+ * @return True if whois source is the same user as the whois target, false if they are different users
+ */
+ bool IsSelfWhois() const { return (source == target); }
+
+ /** Returns the LocalUser who has done the /WHOIS
+ * @return LocalUser doing the /WHOIS
+ */
+ LocalUser* GetSource() const { return source; }
+
+ /** Returns the target of the /WHOIS
+ * @return User who was /WHOIS'd
+ */
+ User* GetTarget() const { return target; }
+
+ /** Send a line of WHOIS data to the source of the WHOIS
+ * @param numeric Numeric to send
+ * @param format Format string for the numeric
+ * @param ... Parameters for the format string
+ */
+ void SendLine(unsigned int numeric, const char* format, ...) CUSTOM_PRINTF(3, 4)
+ {
+ std::string textbuffer;
+ VAFORMAT(textbuffer, format, format)
+ SendLine(numeric, textbuffer);
+ }
+
+ /** Send a line of WHOIS data to the source of the WHOIS
+ * @param numeric Numeric to send
+ * @param text Text of the numeric
+ */
+ virtual void SendLine(unsigned int numeric, const std::string& text) = 0;
+};
diff --git a/src/coremods/core_whois.cpp b/src/coremods/core_whois.cpp
index 7464e0527..1cd622092 100644
--- a/src/coremods/core_whois.cpp
+++ b/src/coremods/core_whois.cpp
@@ -21,6 +21,34 @@
#include "inspircd.h"
+class WhoisContextImpl : public Whois::Context
+{
+ Events::ModuleEventProvider& lineevprov;
+
+ public:
+ WhoisContextImpl(LocalUser* src, User* targ, Events::ModuleEventProvider& evprov)
+ : Whois::Context(src, targ)
+ , lineevprov(evprov)
+ {
+ }
+
+ using Whois::Context::SendLine;
+ void SendLine(unsigned int numeric, const std::string& text) CXX11_OVERRIDE;
+};
+
+void WhoisContextImpl::SendLine(unsigned int numeric, const std::string& text)
+{
+ std::string copy_text = target->nick;
+ copy_text.push_back(' ');
+ copy_text.append(text);
+
+ ModResult MOD_RESULT;
+ FIRST_MOD_RESULT_CUSTOM(lineevprov, Whois::LineEventListener, OnWhoisLine, MOD_RESULT, (*this, numeric, copy_text));
+
+ if (MOD_RESULT != MOD_RES_DENY)
+ source->WriteNumeric(numeric, copy_text);
+}
+
/** Handle /WHOIS.
*/
class CommandWhois : public SplitCommand
@@ -28,9 +56,11 @@ class CommandWhois : public SplitCommand
ChanModeReference secretmode;
ChanModeReference privatemode;
UserModeReference snomaskmode;
+ Events::ModuleEventProvider evprov;
+ Events::ModuleEventProvider lineevprov;
- void SplitChanList(User* source, User* dest, const std::string& cl);
- void DoWhois(User* user, User* dest, unsigned long signon, unsigned long idle);
+ void SplitChanList(WhoisContextImpl& whois, const std::string& cl);
+ void DoWhois(LocalUser* user, User* dest, unsigned long signon, unsigned long idle);
std::string ChannelList(User* source, User* dest, bool spy);
public:
@@ -41,6 +71,8 @@ class CommandWhois : public SplitCommand
, secretmode(parent, "secret")
, privatemode(parent, "private")
, snomaskmode(parent, "snomask")
+ , evprov(parent, "event/whois")
+ , lineevprov(parent, "event/whoisline")
{
Penalty = 2;
syntax = "<nick>{,<nick>}";
@@ -78,39 +110,43 @@ std::string CommandWhois::ChannelList(User* source, User* dest, bool spy)
return list;
}
-void CommandWhois::SplitChanList(User* source, User* dest, const std::string& cl)
+void CommandWhois::SplitChanList(WhoisContextImpl& whois, const std::string& cl)
{
- std::string line;
- std::ostringstream prefix;
+ std::string line(1, ':');
std::string::size_type start, pos;
- prefix << dest->nick << " :";
- line = prefix.str();
- int namelen = ServerInstance->Config->ServerName.length() + 6;
+ // ":server.name 319 source target " ... "\r\n"
+ const std::string::size_type maxlen = ServerInstance->Config->Limits.MaxLine - 10 - ServerInstance->Config->ServerName.length() - whois.GetTarget()->nick.length() - whois.GetSource()->nick.length();
for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
{
- if (line.length() + namelen + pos - start > 510)
+ if (line.length() + pos - start > maxlen)
{
- ServerInstance->SendWhoisLine(source, dest, 319, line);
- line = prefix.str();
+ // Erase last ' ' and send
+ line.erase(line.length()-1);
+ whois.SendLine(319, line);
+ line.erase(1);
}
line.append(cl, start, pos - start + 1);
}
- if (line.length() != prefix.str().length())
+ if (line.length() > 1)
{
- ServerInstance->SendWhoisLine(source, dest, 319, line);
+ // Erase last ' ' and send
+ line.erase(line.length()-1);
+ whois.SendLine(319, line);
}
}
-void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigned long idle)
+void CommandWhois::DoWhois(LocalUser* user, User* dest, unsigned long signon, unsigned long idle)
{
- ServerInstance->SendWhoisLine(user, dest, 311, "%s %s %s * :%s", dest->nick.c_str(), dest->ident.c_str(), dest->dhost.c_str(), dest->fullname.c_str());
- if (user == dest || user->HasPrivPermission("users/auspex"))
+ WhoisContextImpl whois(user, dest, lineevprov);
+
+ whois.SendLine(311, "%s %s * :%s", dest->ident.c_str(), dest->dhost.c_str(), dest->fullname.c_str());
+ if (whois.IsSelfWhois() || user->HasPrivPermission("users/auspex"))
{
- ServerInstance->SendWhoisLine(user, dest, 378, "%s :is connecting from %s@%s %s", dest->nick.c_str(), dest->ident.c_str(), dest->host.c_str(), dest->GetIPString().c_str());
+ whois.SendLine(378, ":is connecting from %s@%s %s", dest->ident.c_str(), dest->host.c_str(), dest->GetIPString().c_str());
}
std::string cl = ChannelList(user, dest, false);
@@ -119,52 +155,52 @@ void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigne
if (state == ServerConfig::SPYWHOIS_SINGLEMSG)
cl.append(ChannelList(user, dest, true));
- SplitChanList(user, dest, cl);
+ SplitChanList(whois, cl);
if (state == ServerConfig::SPYWHOIS_SPLITMSG)
{
std::string scl = ChannelList(user, dest, true);
if (scl.length())
{
- ServerInstance->SendWhoisLine(user, dest, 336, "%s :is on private/secret channels:", dest->nick.c_str());
- SplitChanList(user, dest, scl);
+ whois.SendLine(336, ":is on private/secret channels:");
+ SplitChanList(whois, scl);
}
}
- if (user != dest && !ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
+ if (!whois.IsSelfWhois() && !ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex"))
{
- ServerInstance->SendWhoisLine(user, dest, 312, "%s %s :%s", dest->nick.c_str(), ServerInstance->Config->HideWhoisServer.c_str(), ServerInstance->Config->Network.c_str());
+ whois.SendLine(312, "%s :%s", ServerInstance->Config->HideWhoisServer.c_str(), ServerInstance->Config->Network.c_str());
}
else
{
- ServerInstance->SendWhoisLine(user, dest, 312, "%s %s :%s", dest->nick.c_str(), dest->server->GetName().c_str(), dest->server->GetDesc().c_str());
+ whois.SendLine(312, "%s :%s", dest->server->GetName().c_str(), dest->server->GetDesc().c_str());
}
if (dest->IsAway())
{
- ServerInstance->SendWhoisLine(user, dest, 301, "%s :%s", dest->nick.c_str(), dest->awaymsg.c_str());
+ whois.SendLine(301, ":%s", dest->awaymsg.c_str());
}
if (dest->IsOper())
{
if (ServerInstance->Config->GenericOper)
- ServerInstance->SendWhoisLine(user, dest, 313, "%s :is an IRC operator", dest->nick.c_str());
+ whois.SendLine(313, ":is an IRC operator");
else
- ServerInstance->SendWhoisLine(user, dest, 313, "%s :is %s %s on %s", dest->nick.c_str(), (strchr("AEIOUaeiou",dest->oper->name[0]) ? "an" : "a"),dest->oper->name.c_str(), ServerInstance->Config->Network.c_str());
+ whois.SendLine(313, ":is %s %s on %s", (strchr("AEIOUaeiou",dest->oper->name[0]) ? "an" : "a"),dest->oper->name.c_str(), ServerInstance->Config->Network.c_str());
}
- if (user == dest || user->HasPrivPermission("users/auspex"))
+ if (whois.IsSelfWhois() || user->HasPrivPermission("users/auspex"))
{
if (dest->IsModeSet(snomaskmode))
{
- ServerInstance->SendWhoisLine(user, dest, 379, "%s :is using modes +%s %s", dest->nick.c_str(), dest->FormatModes(), snomaskmode->GetUserParameter(dest).c_str());
+ whois.SendLine(379, ":is using modes +%s %s", dest->FormatModes(), snomaskmode->GetUserParameter(dest).c_str());
}
else
{
- ServerInstance->SendWhoisLine(user, dest, 379, "%s :is using modes +%s", dest->nick.c_str(), dest->FormatModes());
+ whois.SendLine(379, ":is using modes +%s", dest->FormatModes());
}
}
- FOREACH_MOD(OnWhois, (user,dest));
+ FOREACH_MOD_CUSTOM(evprov, Whois::EventListener, OnWhois, (whois));
/*
* We only send these if we've been provided them. That is, if hidewhois is turned off, and user is local, or
@@ -172,10 +208,10 @@ void CommandWhois::DoWhois(User* user, User* dest, unsigned long signon, unsigne
*/
if ((idle) || (signon))
{
- ServerInstance->SendWhoisLine(user, dest, 317, "%s %lu %lu :seconds idle, signon time", dest->nick.c_str(), idle, signon);
+ whois.SendLine(317, "%lu %lu :seconds idle, signon time", idle, signon);
}
- ServerInstance->SendWhoisLine(user, dest, 318, "%s :End of /WHOIS list.", dest->nick.c_str());
+ whois.SendLine(318, ":End of /WHOIS list.");
}
CmdResult CommandWhois::HandleRemote(const std::vector<std::string>& parameters, RemoteUser* target)
@@ -187,8 +223,13 @@ CmdResult CommandWhois::HandleRemote(const std::vector<std::string>& parameters,
if (!user)
return CMD_FAILURE;
+ // User doing the whois must be on this server
+ LocalUser* localuser = IS_LOCAL(user);
+ if (!localuser)
+ return CMD_FAILURE;
+
unsigned long idle = ConvToInt(parameters.back());
- DoWhois(user, target, target->signon, idle);
+ DoWhois(localuser, target, target->signon, idle);
return CMD_SUCCESS;
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 7b2a29f77..5cde46246 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -313,24 +313,6 @@ void InspIRCd::CheckRoot()
#endif
}
-void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const std::string &text)
-{
- std::string copy_text = text;
-
- ModResult MOD_RESULT;
- FIRST_MOD_RESULT(OnWhoisLine, MOD_RESULT, (user, dest, numeric, copy_text));
-
- if (MOD_RESULT != MOD_RES_DENY)
- user->WriteNumeric(numeric, copy_text);
-}
-
-void InspIRCd::SendWhoisLine(User* user, User* dest, int numeric, const char* format, ...)
-{
- std::string textbuffer;
- VAFORMAT(textbuffer, format, format)
- this->SendWhoisLine(user, dest, numeric, textbuffer);
-}
-
/** Refactored by Brain, Jun 2009. Much faster with some clever O(1) array
* lookups and pointer maths.
*/
diff --git a/src/modules.cpp b/src/modules.cpp
index e1fb605c0..a7acb24d0 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -83,7 +83,6 @@ void Module::OnMode(User*, User*, Channel*, const Modes::ChangeList&, ModeParse
void Module::OnOper(User*, const std::string&) { DetachEvent(I_OnOper); }
void Module::OnPostOper(User*, const std::string&, const std::string &) { DetachEvent(I_OnPostOper); }
void Module::OnInfo(User*) { DetachEvent(I_OnInfo); }
-void Module::OnWhois(User*, User*) { DetachEvent(I_OnWhois); }
ModResult Module::OnUserPreInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserPreInvite); return MOD_RES_PASSTHRU; }
ModResult Module::OnUserPreMessage(User*, void*, int, std::string&, char, CUList&, MessageType) { DetachEvent(I_OnUserPreMessage); return MOD_RES_PASSTHRU; }
ModResult Module::OnUserPreNick(LocalUser*, const std::string&) { DetachEvent(I_OnUserPreNick); return MOD_RES_PASSTHRU; }
@@ -131,7 +130,6 @@ void Module::OnCleanup(int, void*) { }
ModResult Module::OnChannelPreDelete(Channel*) { DetachEvent(I_OnChannelPreDelete); return MOD_RES_PASSTHRU; }
void Module::OnChannelDelete(Channel*) { DetachEvent(I_OnChannelDelete); }
ModResult Module::OnSetAway(User*, const std::string &) { DetachEvent(I_OnSetAway); return MOD_RES_PASSTHRU; }
-ModResult Module::OnWhoisLine(User*, User*, int&, std::string&) { DetachEvent(I_OnWhoisLine); return MOD_RES_PASSTHRU; }
void Module::OnBuildNeighborList(User*, IncludeChanList&, std::map<User*,bool>&) { DetachEvent(I_OnBuildNeighborList); }
void Module::OnGarbageCollect() { DetachEvent(I_OnGarbageCollect); }
ModResult Module::OnSetConnectClass(LocalUser* user, ConnectClass* myclass) { DetachEvent(I_OnSetConnectClass); return MOD_RES_PASSTHRU; }
diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp
index 67f692b86..419af0153 100644
--- a/src/modules/m_botmode.cpp
+++ b/src/modules/m_botmode.cpp
@@ -29,12 +29,13 @@ class BotMode : public SimpleUserModeHandler
BotMode(Module* Creator) : SimpleUserModeHandler(Creator, "bot", 'B') { }
};
-class ModuleBotMode : public Module
+class ModuleBotMode : public Module, public Whois::EventListener
{
BotMode bm;
public:
ModuleBotMode()
- : bm(this)
+ : Whois::EventListener(this)
+ , bm(this)
{
}
@@ -43,11 +44,11 @@ class ModuleBotMode : public Module
return Version("Provides user mode +B to mark the user as a bot",VF_VENDOR);
}
- void OnWhois(User* src, User* dst) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- if (dst->IsModeSet(bm))
+ if (whois.GetTarget()->IsModeSet(bm))
{
- ServerInstance->SendWhoisLine(src, dst, 335, dst->nick+" :is a bot on "+ServerInstance->Config->Network);
+ whois.SendLine(335, ":is a bot on " + ServerInstance->Config->Network);
}
}
};
diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp
index 67eca6dda..b86bf1809 100644
--- a/src/modules/m_customtitle.cpp
+++ b/src/modules/m_customtitle.cpp
@@ -70,26 +70,28 @@ class CommandTitle : public Command
};
-class ModuleCustomTitle : public Module
+class ModuleCustomTitle : public Module, public Whois::LineEventListener
{
CommandTitle cmd;
public:
- ModuleCustomTitle() : cmd(this)
+ ModuleCustomTitle()
+ : Whois::LineEventListener(this)
+ , cmd(this)
{
}
// :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
- ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
+ ModResult OnWhoisLine(Whois::Context& whois, unsigned int& numeric, std::string& text) CXX11_OVERRIDE
{
/* We use this and not OnWhois because this triggers for remote, too */
if (numeric == 312)
{
/* Insert our numeric before 312 */
- const std::string* ctitle = cmd.ctitle.get(dest);
+ const std::string* ctitle = cmd.ctitle.get(whois.GetTarget());
if (ctitle)
{
- ServerInstance->SendWhoisLine(user, dest, 320, "%s :%s", dest->nick.c_str(), ctitle->c_str());
+ whois.SendLine(320, ":%s", ctitle->c_str());
}
}
/* Don't block anything */
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 2fe958a71..ef9ae5e22 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -94,14 +94,16 @@ class CommandHelpop : public Command
}
};
-class ModuleHelpop : public Module
+class ModuleHelpop : public Module, public Whois::EventListener
{
CommandHelpop cmd;
Helpop ho;
public:
ModuleHelpop()
- : cmd(this), ho(this)
+ : Whois::EventListener(this)
+ , cmd(this)
+ , ho(this)
{
}
@@ -139,11 +141,11 @@ class ModuleHelpop : public Module
helpop_map.swap(help);
}
- void OnWhois(User* src, User* dst) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- if (dst->IsModeSet(ho))
+ if (whois.GetTarget()->IsModeSet(ho))
{
- ServerInstance->SendWhoisLine(src, dst, 310, dst->nick+" :is available for help.");
+ whois.SendLine(310, ":is available for help.");
}
}
diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp
index 26a53b4d7..4ad339fcb 100644
--- a/src/modules/m_services_account.cpp
+++ b/src/modules/m_services_account.cpp
@@ -156,19 +156,19 @@ class ModuleServicesAccount : public Module
}
/* <- :twisted.oscnet.org 330 w00t2 w00t2 w00t :is logged in as */
- void OnWhois(User* source, User* dest) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- std::string *account = accountname.get(dest);
+ std::string* account = accountname.get(whois.GetTarget());
if (account)
{
- ServerInstance->SendWhoisLine(source, dest, 330, "%s %s :is logged in as", dest->nick.c_str(), account->c_str());
+ whois.SendLine(330, "%s :is logged in as", account->c_str());
}
- if (dest->IsModeSet(m5))
+ if (whois.GetTarget()->IsModeSet(m5))
{
/* user is registered */
- ServerInstance->SendWhoisLine(source, dest, 307, "%s :is a registered nick", dest->nick.c_str());
+ whois.SendLine(307, ":is a registered nick");
}
}
diff --git a/src/modules/m_servprotect.cpp b/src/modules/m_servprotect.cpp
index 26453020f..2ed37b9e4 100644
--- a/src/modules/m_servprotect.cpp
+++ b/src/modules/m_servprotect.cpp
@@ -42,12 +42,13 @@ class ServProtectMode : public ModeHandler
}
};
-class ModuleServProtectMode : public Module
+class ModuleServProtectMode : public Module, public Whois::EventListener
{
ServProtectMode bm;
public:
ModuleServProtectMode()
- : bm(this)
+ : Whois::EventListener(this)
+ , bm(this)
{
}
@@ -56,11 +57,11 @@ class ModuleServProtectMode : public Module
return Version("Provides usermode +k to protect services from kicks, kills, and mode changes.", VF_VENDOR);
}
- void OnWhois(User* user, User* dest) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- if (dest->IsModeSet(bm))
+ if (whois.GetTarget()->IsModeSet(bm))
{
- ServerInstance->SendWhoisLine(user, dest, 310, dest->nick+" :is a Network Service on "+ServerInstance->Config->Network);
+ whois.SendLine(310, ":is a Network Service on " + ServerInstance->Config->Network);
}
}
@@ -121,7 +122,7 @@ class ModuleServProtectMode : public Module
ModResult OnWhoisLine(User* src, User* dst, int &numeric, std::string &text) CXX11_OVERRIDE
{
- return ((src != dst) && (numeric == 319) && dst->IsModeSet(bm)) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
+ return ((numeric == 319) && dst->IsModeSet(bm)) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
}
};
diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp
index ba17942cb..3cb85f3fb 100644
--- a/src/modules/m_showwhois.cpp
+++ b/src/modules/m_showwhois.cpp
@@ -69,7 +69,7 @@ class WhoisNoticeCmd : public Command
}
};
-class ModuleShowwhois : public Module
+class ModuleShowwhois : public Module, public Whois::EventListener
{
bool ShowWhoisFromOpers;
SeeWhois sw;
@@ -78,7 +78,9 @@ class ModuleShowwhois : public Module
public:
ModuleShowwhois()
- : sw(this), cmd(this)
+ : Whois::EventListener(this)
+ , sw(this)
+ , cmd(this)
{
}
@@ -95,9 +97,11 @@ class ModuleShowwhois : public Module
return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
}
- void OnWhois(User* source, User* dest) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- if (!dest->IsModeSet(sw) || source == dest)
+ User* const source = whois.GetSource();
+ User* const dest = whois.GetTarget();
+ if (!dest->IsModeSet(sw) || whois.IsSelfWhois())
return;
if (!ShowWhoisFromOpers && source->IsOper())
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index f861f1236..523d52abb 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -139,14 +139,16 @@ class UserCertificateAPIImpl : public UserCertificateAPIBase
}
};
-class ModuleSSLInfo : public Module
+class ModuleSSLInfo : public Module, public Whois::EventListener
{
CommandSSLInfo cmd;
UserCertificateAPIImpl APIImpl;
public:
ModuleSSLInfo()
- : cmd(this), APIImpl(this, cmd.CertExt)
+ : Whois::EventListener(this)
+ , cmd(this)
+ , APIImpl(this, cmd.CertExt)
{
}
@@ -155,16 +157,15 @@ class ModuleSSLInfo : public Module
return Version("SSL Certificate Utilities", VF_VENDOR);
}
- void OnWhois(User* source, User* dest) CXX11_OVERRIDE
+ void OnWhois(Whois::Context& whois) CXX11_OVERRIDE
{
- ssl_cert* cert = cmd.CertExt.get(dest);
+ ssl_cert* cert = cmd.CertExt.get(whois.GetTarget());
if (cert)
{
- ServerInstance->SendWhoisLine(source, dest, 671, "%s :is using a secure connection", dest->nick.c_str());
+ whois.SendLine(671, ":is using a secure connection");
bool operonlyfp = ServerInstance->Config->ConfValue("sslinfo")->getBool("operonly");
- if ((!operonlyfp || source == dest || source->IsOper()) && !cert->fingerprint.empty())
- ServerInstance->SendWhoisLine(source, dest, 276, "%s :has client certificate fingerprint %s",
- dest->nick.c_str(), cert->fingerprint.c_str());
+ if ((!operonlyfp || whois.IsSelfWhois() || whois.GetSource()->IsOper()) && !cert->fingerprint.empty())
+ whois.SendLine(276, ":has client certificate fingerprint %s", cert->fingerprint.c_str());
}
}
diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp
index 81abde6f7..e75921a80 100644
--- a/src/modules/m_swhois.cpp
+++ b/src/modules/m_swhois.cpp
@@ -81,26 +81,28 @@ class CommandSwhois : public Command
};
-class ModuleSWhois : public Module
+class ModuleSWhois : public Module, public Whois::LineEventListener
{
CommandSwhois cmd;
public:
- ModuleSWhois() : cmd(this)
+ ModuleSWhois()
+ : Whois::LineEventListener(this)
+ , cmd(this)
{
}
// :kenny.chatspike.net 320 Brain Azhrarn :is getting paid to play games.
- ModResult OnWhoisLine(User* user, User* dest, int &numeric, std::string &text) CXX11_OVERRIDE
+ ModResult OnWhoisLine(Whois::Context& whois, unsigned int& numeric, std::string& text) CXX11_OVERRIDE
{
/* We use this and not OnWhois because this triggers for remote, too */
if (numeric == 312)
{
/* Insert our numeric before 312 */
- std::string* swhois = cmd.swhois.get(dest);
+ std::string* swhois = cmd.swhois.get(whois.GetTarget());
if (swhois)
{
- ServerInstance->SendWhoisLine(user, dest, 320, "%s :%s", dest->nick.c_str(), swhois->c_str());
+ whois.SendLine(320, ":%s", swhois->c_str());
}
}