]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/xline.h
Tons more docs
[user/henk/code/inspircd.git] / include / xline.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __XLINE_H
18 #define __XLINE_H
19
20 // include the common header files
21
22 #include <typeinfo>
23 #include <iostream>
24 #include <string>
25 #include <deque>
26 #include <sstream>
27 #include <vector>
28 #include "users.h"
29 #include "channels.h"
30
31 const int APPLY_GLINES  = 1;
32 const int APPLY_KLINES  = 2;
33 const int APPLY_QLINES  = 4;
34 const int APPLY_ZLINES  = 8;
35 const int APPLY_ALL     = APPLY_GLINES | APPLY_KLINES | APPLY_QLINES | APPLY_ZLINES;
36
37 /** XLine is the base class for ban lines such as G lines and K lines.
38  */
39 class XLine : public classbase
40 {
41   public:
42
43         /** The time the line was added.
44          */
45         time_t set_time;
46         
47         /** The duration of the ban, or 0 if permenant
48          */
49         long duration;
50         
51         /** Source of the ban. This can be a servername or an oper nickname
52          */
53         char source[256];
54         
55         /** Reason for the ban
56          */
57         char reason[MAXBUF];
58         
59         /** Number of times the core matches the ban, for statistics
60          */
61         long n_matches;
62         
63 };
64
65 /** KLine class
66  */
67 class KLine : public XLine
68 {
69   public:
70         /** Hostmask (ident@host) to match against
71          * May contain wildcards.
72          */
73         char hostmask[200];
74 };
75
76 /** GLine class
77  */
78 class GLine : public XLine
79 {
80   public:
81         /** Hostmask (ident@host) to match against
82          * May contain wildcards.
83          */
84         char hostmask[200];
85 };
86
87 class ELine : public XLine
88 {
89   public:
90         /** Hostmask (ident@host) to match against
91          * May contain wildcards.
92          */
93         char hostmask[200];
94 };
95
96 /** ZLine class
97  */
98 class ZLine : public XLine
99 {
100   public:
101         /** IP Address (xx.yy.zz.aa) to match against
102          * May contain wildcards.
103          */
104         char ipaddr[40];
105         /** Set if this is a global Z:line
106          * (e.g. it came from another server)
107          */
108         bool is_global;
109 };
110
111 /** QLine class
112  */
113 class QLine : public XLine
114 {
115   public:
116         /** Nickname to match against.
117          * May contain wildcards.
118          */
119         char nick[64];
120         /** Set if this is a global Z:line
121          * (e.g. it came from another server)
122          */
123         bool is_global;
124 };
125
126 class ServerConfig;
127 class InspIRCd;
128
129 bool InitXLine(ServerConfig* conf, const char* tag);
130 bool DoneXLine(ServerConfig* conf, const char* tag);
131
132 bool DoZLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
133 bool DoQLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
134 bool DoKLine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
135 bool DoELine(ServerConfig* conf, const char* tag, char** entries, void** values, int* types);
136
137 class XLineManager
138 {
139  protected:
140         InspIRCd* ServerInstance;
141
142         static bool XLineManager::GSortComparison ( const GLine one, const GLine two );
143         static bool XLineManager::ESortComparison ( const ELine one, const ELine two );
144         static bool XLineManager::ZSortComparison ( const ZLine one, const ZLine two );
145         static bool XLineManager::KSortComparison ( const KLine one, const KLine two );
146         static bool XLineManager::QSortComparison ( const QLine one, const QLine two );
147  public:
148         /* Lists for temporary lines with an expiry time */
149         std::vector<KLine> klines;
150         std::vector<GLine> glines;
151         std::vector<ZLine> zlines;
152         std::vector<QLine> qlines;
153         std::vector<ELine> elines;
154
155         /* Seperate lists for perm XLines that isnt checked by expiry functions */
156         std::vector<KLine> pklines;
157         std::vector<GLine> pglines;
158         std::vector<ZLine> pzlines;
159         std::vector<QLine> pqlines;
160         std::vector<ELine> pelines;
161          
162         XLineManager(InspIRCd* Instance);
163
164         bool add_gline(long duration, const char* source, const char* reason, const char* hostmask);
165         bool add_qline(long duration, const char* source, const char* reason, const char* nickname);
166         bool add_zline(long duration, const char* source, const char* reason, const char* ipaddr);
167         bool add_kline(long duration, const char* source, const char* reason, const char* hostmask);
168         bool add_eline(long duration, const char* source, const char* reason, const char* hostmask);
169
170         bool del_gline(const char* hostmask);
171         bool del_qline(const char* nickname);
172         bool del_zline(const char* ipaddr);
173         bool del_kline(const char* hostmask);
174         bool del_eline(const char* hostmask);
175
176         char* matches_qline(const char* nick);
177         char* matches_gline(const char* host);
178         char* matches_zline(const char* ipaddr);
179         char* matches_kline(const char* host);
180         char* matches_exception(const char* host);
181
182         void expire_lines();
183         void apply_lines(const int What);
184
185         void stats_k(userrec* user, string_list &results);
186         void stats_g(userrec* user, string_list &results);
187         void stats_q(userrec* user, string_list &results);
188         void stats_z(userrec* user, string_list &results);
189         void stats_e(userrec* user, string_list &results);
190
191         void gline_set_creation_time(const char* host, time_t create_time);
192         void qline_set_creation_time(const char* nick, time_t create_time);
193         void zline_set_creation_time(const char* ip, time_t create_time);
194         void eline_set_creation_time(const char* host, time_t create_time);
195         
196         bool zline_make_global(const char* ipaddr);
197         bool qline_make_global(const char* nickname);
198 };
199
200 #endif