]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/whois.h
Move OnWhois* events to core_whois, add Whois::Context
[user/henk/code/inspircd.git] / include / modules / whois.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015 Attila Molnar <attilamolnar@hush.com>
5  *
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.
9  *
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
13  * details.
14  *
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/>.
17  */
18
19
20 #pragma once
21
22 #include "event.h"
23
24 namespace Whois
25 {
26         class EventListener;
27         class LineEventListener;
28         class Context;
29 }
30
31 class Whois::EventListener : public Events::ModuleEventListener
32 {
33  public:
34         EventListener(Module* mod)
35                 : ModuleEventListener(mod, "event/whois")
36         {
37         }
38
39         /** Called whenever a /WHOIS is performed by a local user.
40          * @param whois Whois context, can be used to send numerics
41          */
42         virtual void OnWhois(Context& whois) = 0;
43 };
44
45 class Whois::LineEventListener : public Events::ModuleEventListener
46 {
47  public:
48         LineEventListener(Module* mod)
49                 : ModuleEventListener(mod, "event/whoisline")
50         {
51         }
52
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
56          * numeric is sent to.
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.
62          */
63         virtual ModResult OnWhoisLine(Context& whois, unsigned int& numeric, std::string& text) = 0;
64 };
65
66 class Whois::Context
67 {
68  protected:
69         /** User doing the WHOIS
70          */
71         LocalUser* const source;
72
73         /** User being WHOISed
74          */
75         User* const target;
76
77  public:
78         Context(LocalUser* src, User* targ)
79                 : source(src)
80                 , target(targ)
81         {
82         }
83
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
86          */
87         bool IsSelfWhois() const { return (source == target); }
88
89         /** Returns the LocalUser who has done the /WHOIS
90          * @return LocalUser doing the /WHOIS
91          */
92         LocalUser* GetSource() const { return source; }
93
94         /** Returns the target of the /WHOIS
95          * @return User who was /WHOIS'd
96          */
97         User* GetTarget() const { return target; }
98
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
103          */
104         void SendLine(unsigned int numeric, const char* format, ...) CUSTOM_PRINTF(3, 4)
105         {
106                 std::string textbuffer;
107                 VAFORMAT(textbuffer, format, format)
108                 SendLine(numeric, textbuffer);
109         }
110
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
114          */
115         virtual void SendLine(unsigned int numeric, const std::string& text) = 0;
116 };