summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/inspircd.h19
-rw-r--r--include/modules.h25
-rw-r--r--include/modules/whois.h116
3 files changed, 120 insertions, 40 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;
+};