]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/modules/whois.h
f158f82cc7f0b769ffe9a637b302df6f6480ac21
[user/henk/code/inspircd.git] / include / modules / whois.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2015-2016 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 Numeric being sent
59          * @return MOD_RES_DENY to drop the line completely so that the user does not
60          * receive it, or MOD_RES_PASSTHRU to allow the line to be sent.
61          */
62         virtual ModResult OnWhoisLine(Context& whois, Numeric::Numeric& numeric) = 0;
63 };
64
65 class Whois::Context
66 {
67  protected:
68         /** User doing the WHOIS
69          */
70         LocalUser* const source;
71
72         /** User being WHOISed
73          */
74         User* const target;
75
76  public:
77         Context(LocalUser* src, User* targ)
78                 : source(src)
79                 , target(targ)
80         {
81         }
82
83         /** Returns true if the user is /WHOISing himself
84          * @return True if whois source is the same user as the whois target, false if they are different users
85          */
86         bool IsSelfWhois() const { return (source == target); }
87
88         /** Returns the LocalUser who has done the /WHOIS
89          * @return LocalUser doing the /WHOIS
90          */
91         LocalUser* GetSource() const { return source; }
92
93         /** Returns the target of the /WHOIS
94          * @return User who was /WHOIS'd
95          */
96         User* GetTarget() const { return target; }
97
98         /** Send a line of WHOIS data to the source of the WHOIS
99          */
100         template <typename T1>
101         void SendLine(unsigned int numeric, T1 p1)
102         {
103                 Numeric::Numeric n(numeric);
104                 n.push(target->nick);
105                 n.push(p1);
106                 SendLine(n);
107         }
108
109         template <typename T1, typename T2>
110         void SendLine(unsigned int numeric, T1 p1, T2 p2)
111         {
112                 Numeric::Numeric n(numeric);
113                 n.push(target->nick);
114                 n.push(p1);
115                 n.push(p2);
116                 SendLine(n);
117         }
118
119         template <typename T1, typename T2, typename T3>
120         void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3)
121         {
122                 Numeric::Numeric n(numeric);
123                 n.push(target->nick);
124                 n.push(p1);
125                 n.push(p2);
126                 n.push(p3);
127                 SendLine(n);
128         }
129
130         template <typename T1, typename T2, typename T3, typename T4>
131         void SendLine(unsigned int numeric, T1 p1, T2 p2, T3 p3, T4 p4)
132         {
133                 Numeric::Numeric n(numeric);
134                 n.push(target->nick);
135                 n.push(p1);
136                 n.push(p2);
137                 n.push(p3);
138                 n.push(p4);
139                 SendLine(n);
140         }
141
142         /** Send a line of WHOIS data to the source of the WHOIS
143          * @param numeric Numeric to send
144          */
145         virtual void SendLine(Numeric::Numeric& numeric) = 0;
146 };