]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/core_xline.h
Improve X-line text consistency.
[user/henk/code/inspircd.git] / src / coremods / core_xline / core_xline.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2014 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 "inspircd.h"
23
24 class InsaneBan
25 {
26  public:
27         class MatcherBase
28         {
29          public:
30                 virtual long Run(const std::string& mask) = 0;
31         };
32
33         template <typename T>
34         class Matcher : public MatcherBase
35         {
36          public:
37                 long Run(const std::string& mask) CXX11_OVERRIDE
38                 {
39                         long matches = 0;
40                         const T* c = static_cast<T*>(this);
41                         const user_hash& users = ServerInstance->Users->GetUsers();
42                         for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i)
43                         {
44                                 if (c->Check(i->second, mask))
45                                         matches++;
46                         }
47                         return matches;
48                 }
49         };
50
51         class IPHostMatcher : public Matcher<IPHostMatcher>
52         {
53          public:
54                 bool Check(User* user, const std::string& mask) const;
55         };
56
57         /** Check if the given mask matches too many users according to the config, send an announcement if yes
58          * @param mask A mask to match against
59          * @param test The test that determines if a user matches the mask or not
60          * @param user A user whose nick will be included in the announcement if one is made
61          * @param bantype Type of the ban being set, will be used in the announcement if one is made
62          * @param confkey Name of the config key (inside the insane tag) which if false disables any checking
63          * @return True if the given mask matches too many users, false if not
64          */
65         static bool MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey);
66 };
67
68 /** Handle /ELINE.
69  */
70 class CommandEline : public Command
71 {
72  public:
73         /** Constructor for E-line.
74          */
75         CommandEline(Module* parent);
76
77         /** Handle command.
78          * @param parameters The parameters to the command
79          * @param user The user issuing the command
80          * @return A value from CmdResult to indicate command success or failure.
81          */
82         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
83 };
84
85 /** Handle /GLINE.
86  */
87 class CommandGline : public Command
88 {
89  public:
90         /** Constructor for G-line.
91          */
92         CommandGline(Module* parent);
93
94         /** Handle command.
95          * @param parameters The parameters to the command
96          * @param user The user issuing the command
97          * @return A value from CmdResult to indicate command success or failure.
98          */
99         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
100 };
101
102 /** Handle /KLINE.
103  */
104 class CommandKline : public Command
105 {
106  public:
107         /** Constructor for K-line.
108          */
109         CommandKline(Module* parent);
110
111         /** Handle command.
112          * @param parameters The parameters to the command
113          * @param user The user issuing the command
114          * @return A value from CmdResult to indicate command success or failure.
115          */
116         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
117 };
118
119 /** Handle /QLINE.
120  */
121 class CommandQline : public Command
122 {
123         class NickMatcher : public InsaneBan::Matcher<NickMatcher>
124         {
125          public:
126                 bool Check(User* user, const std::string& mask) const;
127         };
128
129  public:
130         /** Constructor for Q-line.
131          */
132         CommandQline(Module* parent);
133
134         /** Handle command.
135          * @param parameters The parameters to the command
136          * @param user The user issuing the command
137          * @return A value from CmdResult to indicate command success or failure.
138          */
139         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
140 };
141
142 /** Handle /ZLINE.
143  */
144 class CommandZline : public Command
145 {
146         class IPMatcher : public InsaneBan::Matcher<IPMatcher>
147         {
148          public:
149                 bool Check(User* user, const std::string& mask) const;
150         };
151
152  public:
153         /** Constructor for Z-line.
154          */
155         CommandZline(Module* parent);
156
157         /** Handle command.
158          * @param parameters The parameters to the command
159          * @param user The user issuing the command
160          * @return A value from CmdResult to indicate command success or failure.
161          */
162         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
163 };