]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/whois.h
Remove the Kiwi links from the readme.
[user/henk/code/inspircd.git] / include / modules / whois.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2021 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2015-2016 Attila Molnar <attilamolnar@hush.com>
6  *
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.
10  *
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
14  * details.
15  *
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/>.
18  */
19
20
21 #pragma once
22
23 #include "event.h"
24
25 namespace Whois
26 {
27         class EventListener;
28         class LineEventListener;
29         class Context;
30 }
31
32 enum
33 {
34         // From RFC 1459.
35         RPL_WHOISUSER = 311,
36         RPL_WHOISOPERATOR = 313,
37         RPL_WHOISIDLE = 317,
38         RPL_WHOISCHANNELS = 319,
39
40         // From UnrealIRCd.
41         RPL_WHOISHOST = 378,
42         RPL_WHOISMODES = 379,
43
44         // InspIRCd-specific.
45         RPL_CHANNELSMSG = 651
46 };
47
48 class Whois::EventListener : public Events::ModuleEventListener
49 {
50  public:
51         EventListener(Module* mod)
52                 : ModuleEventListener(mod, "event/whois")
53         {
54         }
55
56         /** Called whenever a /WHOIS is performed by a local user.
57          * @param whois Whois context, can be used to send numerics
58          */
59         virtual void OnWhois(Context& whois) = 0;
60 };
61
62 class Whois::LineEventListener : public Events::ModuleEventListener
63 {
64  public:
65         LineEventListener(Module* mod)
66                 : ModuleEventListener(mod, "event/whoisline")
67         {
68         }
69
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
73          * numeric is sent to.
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.
78          */
79         virtual ModResult OnWhoisLine(Context& whois, Numeric::Numeric& numeric) = 0;
80 };
81
82 class Whois::Context
83 {
84  protected:
85         /** User doing the WHOIS
86          */
87         LocalUser* const source;
88
89         /** User being WHOISed
90          */
91         User* const target;
92
93  public:
94         Context(LocalUser* src, User* targ)
95                 : source(src)
96                 , target(targ)
97         {
98         }
99
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
102          */
103         bool IsSelfWhois() const { return (source == target); }
104
105         /** Returns the LocalUser who has done the /WHOIS
106          * @return LocalUser doing the /WHOIS
107          */
108         LocalUser* GetSource() const { return source; }
109
110         /** Returns the target of the /WHOIS
111          * @return User who was /WHOIS'd
112          */
113         User* GetTarget() const { return target; }
114
115         /** Send a line of WHOIS data to the source of the WHOIS
116          */
117         template <typename T1>
118         void SendLine(unsigned int numeric, T1 p1)
119         {
120                 Numeric::Numeric n(numeric);
121                 n.push(target->nick);
122                 n.push(p1);
123                 SendLine(n);
124         }
125
126         template <typename T1, typename T2>
127         void SendLine(unsigned int numeric, T1 p1, T2 p2)
128         {
129                 Numeric::Numeric n(numeric);
130                 n.push(target->nick);
131                 n.push(p1);
132                 n.push(p2);
133                 SendLine(n);
134         }
135
136         template <typename T1, typename T2, typename T3>
137         void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3)
138         {
139                 Numeric::Numeric n(numeric);
140                 n.push(target->nick);
141                 n.push(p1);
142                 n.push(p2);
143                 n.push(p3);
144                 SendLine(n);
145         }
146
147         template <typename T1, typename T2, typename T3, typename T4>
148         void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
149         {
150                 Numeric::Numeric n(numeric);
151                 n.push(target->nick);
152                 n.push(p1);
153                 n.push(p2);
154                 n.push(p3);
155                 n.push(p4);
156                 SendLine(n);
157         }
158
159         /** Send a line of WHOIS data to the source of the WHOIS
160          * @param numeric Numeric to send
161          */
162         virtual void SendLine(Numeric::Numeric& numeric) = 0;
163 };