]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_xline/core_xline.h
Update copyright headers.
[user/henk/code/inspircd.git] / src / coremods / core_xline / core_xline.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2019 Robby <robby@chatbelgie.be>
5  *   Copyright (C) 2019 Matt Schatz <genius3000@g3k.solutions>
6  *   Copyright (C) 2017-2018 Sadie Powell <sadie@witchery.services>
7  *   Copyright (C) 2014 Attila Molnar <attilamolnar@hush.com>
8  *
9  * This file is part of InspIRCd.  InspIRCd is free software: you can
10  * redistribute it and/or modify it under the terms of the GNU General Public
11  * License as published by the Free Software Foundation, version 2.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #pragma once
24
25 #include "inspircd.h"
26
27 class InsaneBan
28 {
29  public:
30         class MatcherBase
31         {
32          public:
33                 virtual long Run(const std::string& mask) = 0;
34         };
35
36         template <typename T>
37         class Matcher : public MatcherBase
38         {
39          public:
40                 long Run(const std::string& mask) CXX11_OVERRIDE
41                 {
42                         long matches = 0;
43                         const T* c = static_cast<T*>(this);
44                         const user_hash& users = ServerInstance->Users->GetUsers();
45                         for (user_hash::const_iterator i = users.begin(); i != users.end(); ++i)
46                         {
47                                 if (c->Check(i->second, mask))
48                                         matches++;
49                         }
50                         return matches;
51                 }
52         };
53
54         class IPHostMatcher : public Matcher<IPHostMatcher>
55         {
56          public:
57                 bool Check(User* user, const std::string& mask) const;
58         };
59
60         /** Check if the given mask matches too many users according to the config, send an announcement if yes
61          * @param mask A mask to match against
62          * @param test The test that determines if a user matches the mask or not
63          * @param user A user whose nick will be included in the announcement if one is made
64          * @param bantype Type of the ban being set, will be used in the announcement if one is made
65          * @param confkey Name of the config key (inside the insane tag) which if false disables any checking
66          * @return True if the given mask matches too many users, false if not
67          */
68         static bool MatchesEveryone(const std::string& mask, MatcherBase& test, User* user, const char* bantype, const char* confkey);
69 };
70
71 /** Handle /ELINE.
72  */
73 class CommandEline : public Command
74 {
75  public:
76         /** Constructor for E-line.
77          */
78         CommandEline(Module* parent);
79
80         /** Handle command.
81          * @param parameters The parameters to the command
82          * @param user The user issuing the command
83          * @return A value from CmdResult to indicate command success or failure.
84          */
85         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
86 };
87
88 /** Handle /GLINE.
89  */
90 class CommandGline : public Command
91 {
92  public:
93         /** Constructor for G-line.
94          */
95         CommandGline(Module* parent);
96
97         /** Handle command.
98          * @param parameters The parameters to the command
99          * @param user The user issuing the command
100          * @return A value from CmdResult to indicate command success or failure.
101          */
102         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
103 };
104
105 /** Handle /KLINE.
106  */
107 class CommandKline : public Command
108 {
109  public:
110         /** Constructor for K-line.
111          */
112         CommandKline(Module* parent);
113
114         /** Handle command.
115          * @param parameters The parameters to the command
116          * @param user The user issuing the command
117          * @return A value from CmdResult to indicate command success or failure.
118          */
119         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
120 };
121
122 /** Handle /QLINE.
123  */
124 class CommandQline : public Command
125 {
126         class NickMatcher : public InsaneBan::Matcher<NickMatcher>
127         {
128          public:
129                 bool Check(User* user, const std::string& mask) const;
130         };
131
132  public:
133         /** Constructor for Q-line.
134          */
135         CommandQline(Module* parent);
136
137         /** Handle command.
138          * @param parameters The parameters to the command
139          * @param user The user issuing the command
140          * @return A value from CmdResult to indicate command success or failure.
141          */
142         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
143 };
144
145 /** Handle /ZLINE.
146  */
147 class CommandZline : public Command
148 {
149         class IPMatcher : public InsaneBan::Matcher<IPMatcher>
150         {
151          public:
152                 bool Check(User* user, const std::string& mask) const;
153         };
154
155  public:
156         /** Constructor for Z-line.
157          */
158         CommandZline(Module* parent);
159
160         /** Handle command.
161          * @param parameters The parameters to the command
162          * @param user The user issuing the command
163          * @return A value from CmdResult to indicate command success or failure.
164          */
165         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE;
166 };