2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
6 * This file is part of InspIRCd. InspIRCd is free software: you can
7 * redistribute it and/or modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 class LineEventListener;
31 class Whois::EventListener : public Events::ModuleEventListener
34 EventListener(Module* mod)
35 : ModuleEventListener(mod, "event/whois")
39 /** Called whenever a /WHOIS is performed by a local user.
40 * @param whois Whois context, can be used to send numerics
42 virtual void OnWhois(Context& whois) = 0;
45 class Whois::LineEventListener : public Events::ModuleEventListener
48 LineEventListener(Module* mod)
49 : ModuleEventListener(mod, "event/whoisline")
53 /** Called whenever a line of WHOIS output is sent to a user.
54 * You may change the numeric and the text of the output by changing
55 * the values numeric and text, but you cannot change the user the
57 * @param whois Whois context, can be used to send numerics
58 * @param numeric The numeric of the line being sent
59 * @param text The text of the numeric, including any parameters
60 * @return MOD_RES_DENY to drop the line completely so that the user does not
61 * receive it, or MOD_RES_PASSTHRU to allow the line to be sent.
63 virtual ModResult OnWhoisLine(Context& whois, unsigned int& numeric, std::string& text) = 0;
69 /** User doing the WHOIS
71 LocalUser* const source;
73 /** User being WHOISed
78 Context(LocalUser* src, User* targ)
84 /** Returns true if the user is /WHOISing himself
85 * @return True if whois source is the same user as the whois target, false if they are different users
87 bool IsSelfWhois() const { return (source == target); }
89 /** Returns the LocalUser who has done the /WHOIS
90 * @return LocalUser doing the /WHOIS
92 LocalUser* GetSource() const { return source; }
94 /** Returns the target of the /WHOIS
95 * @return User who was /WHOIS'd
97 User* GetTarget() const { return target; }
99 /** Send a line of WHOIS data to the source of the WHOIS
100 * @param numeric Numeric to send
101 * @param format Format string for the numeric
102 * @param ... Parameters for the format string
104 void SendLine(unsigned int numeric, const char* format, ...) CUSTOM_PRINTF(3, 4)
106 std::string textbuffer;
107 VAFORMAT(textbuffer, format, format)
108 SendLine(numeric, textbuffer);
111 /** Send a line of WHOIS data to the source of the WHOIS
112 * @param numeric Numeric to send
113 * @param text Text of the numeric
115 virtual void SendLine(unsigned int numeric, const std::string& text) = 0;