2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2021 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2015-2016 Attila Molnar <attilamolnar@hush.com>
7 * This file is part of InspIRCd. InspIRCd is free software: you can
8 * redistribute it and/or modify it under the terms of the GNU General Public
9 * License as published by the Free Software Foundation, version 2.
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class LineEventListener;
36 RPL_WHOISOPERATOR = 313,
38 RPL_WHOISCHANNELS = 319,
48 class Whois::EventListener : public Events::ModuleEventListener
51 EventListener(Module* mod)
52 : ModuleEventListener(mod, "event/whois")
56 /** Called whenever a /WHOIS is performed by a local user.
57 * @param whois Whois context, can be used to send numerics
59 virtual void OnWhois(Context& whois) = 0;
62 class Whois::LineEventListener : public Events::ModuleEventListener
65 LineEventListener(Module* mod)
66 : ModuleEventListener(mod, "event/whoisline")
70 /** Called whenever a line of WHOIS output is sent to a user.
71 * You may change the numeric and the text of the output by changing
72 * the values numeric and text, but you cannot change the user the
74 * @param whois Whois context, can be used to send numerics
75 * @param numeric Numeric being sent
76 * @return MOD_RES_DENY to drop the line completely so that the user does not
77 * receive it, or MOD_RES_PASSTHRU to allow the line to be sent.
79 virtual ModResult OnWhoisLine(Context& whois, Numeric::Numeric& numeric) = 0;
85 /** User doing the WHOIS
87 LocalUser* const source;
89 /** User being WHOISed
94 Context(LocalUser* src, User* targ)
100 /** Returns true if the user is /WHOISing himself
101 * @return True if whois source is the same user as the whois target, false if they are different users
103 bool IsSelfWhois() const { return (source == target); }
105 /** Returns the LocalUser who has done the /WHOIS
106 * @return LocalUser doing the /WHOIS
108 LocalUser* GetSource() const { return source; }
110 /** Returns the target of the /WHOIS
111 * @return User who was /WHOIS'd
113 User* GetTarget() const { return target; }
115 /** Send a line of WHOIS data to the source of the WHOIS
117 template <typename T1>
118 void SendLine(unsigned int numeric, T1 p1)
120 Numeric::Numeric n(numeric);
121 n.push(target->nick);
126 template <typename T1, typename T2>
127 void SendLine(unsigned int numeric, T1 p1, T2 p2)
129 Numeric::Numeric n(numeric);
130 n.push(target->nick);
136 template <typename T1, typename T2, typename T3>
137 void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3)
139 Numeric::Numeric n(numeric);
140 n.push(target->nick);
147 template <typename T1, typename T2, typename T3, typename T4>
148 void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
150 Numeric::Numeric n(numeric);
151 n.push(target->nick);
159 /** Send a line of WHOIS data to the source of the WHOIS
160 * @param numeric Numeric to send
162 virtual void SendLine(Numeric::Numeric& numeric) = 0;