modified code to use IOHandler functions instead of own ones
[NeonServV5.git] / src / modules / NeonSpam.mod / bot_NeonSpam.h
1 /* bot_NeonSpam.h - NeonServ v5.5
2  * Copyright (C) 2011-2012  Philipp Kreil (pk910)
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License 
15  * along with this program. If not, see <http://www.gnu.org/licenses/>. 
16  */
17
18 #ifndef _bot_NeonSpam_h
19 #define _bot_NeonSpam_h
20
21 #include "../../main.h"
22
23 struct ChanNode;
24
25 //SPAMSCAN
26 #define SPAMSETTINGS_SPAMSCAN           0x000001
27 #define SPAMSETTINGS_SPAMSCAN_OPS       0x000002
28 #define SPAMSETTINGS_SPAMSCAN_VOICE     0x000004
29 #define SPAMSETTINGS_SPAMCHARS          "abc"
30 #define SPAMSETTINGS_SPAMEXCINDEX       0
31
32 //FLOODSCAN
33 #define SPAMSETTINGS_FLOODSCAN          0x000008
34 #define SPAMSETTINGS_FLOODSCAN_OPS      0x000010
35 #define SPAMSETTINGS_FLOODSCAN_VOICE    0x000020
36 #define SPAMSETTINGS_FLOODCHARS         "def"
37 #define SPAMSETTINGS_FLOODEXCINDEX      1
38 #define SPAMSETTINGS_FLOODSENINDEX      0
39
40 //JOINSCAN
41 #define SPAMSETTINGS_JOINSCAN           0x000040
42 #define SPAMSETTINGS_JOINSCAN_OPS       0x000080
43 #define SPAMSETTINGS_JOINSCAN_VOICE     0x000100
44 #define SPAMSETTINGS_JOINCHARS          "ghi"
45 #define SPAMSETTINGS_JOINEXCINDEX       2
46 #define SPAMSETTINGS_JOINSENINDEX       1
47
48 //BOTNET SCAN
49 #define SPAMSETTINGS_BOTNETSCAN         0x000200
50 #define SPAMSETTINGS_BOTNETSCAN_OPS     0x000400
51 #define SPAMSETTINGS_BOTNETSCAN_VOICE   0x000800
52 #define SPAMSETTINGS_BOTNETSCAN_STRIPCC 0x001000
53 #define SPAMSETTINGS_BOTNETCHARS        "jklm"
54 #define SPAMSETTINGS_BOTNETEXCINDEX     3
55
56 //CAPSSCAN
57 #define SPAMSETTINGS_CAPSSCAN           0x002000
58 #define SPAMSETTINGS_CAPSSCAN_OPS       0x004000
59 #define SPAMSETTINGS_CAPSSCAN_VOICE     0x008000
60 #define SPAMSETTINGS_CAPSCHARS          "nop"
61 #define SPAMSETTINGS_CAPSEXCINDEX       4
62 #define SPAMSETTINGS_CAPSPERCENTINDEX   0
63
64 //DIGITSCAN
65 #define SPAMSETTINGS_DIGITSCAN          0x010000
66 #define SPAMSETTINGS_DIGITSCAN_OPS      0x020000
67 #define SPAMSETTINGS_DIGITSCAN_VOICE    0x040000
68 #define SPAMSETTINGS_DIGITCHARS         "qrs"
69 #define SPAMSETTINGS_DIGITEXCINDEX      5
70 #define SPAMSETTINGS_DIGITPERCENTINDEX  1
71
72 //BADWORDSCAN
73 #define SPAMSETTINGS_BADWORDSCAN        0x080000
74 #define SPAMSETTINGS_BADWORDSCAN_OPS    0x100000
75 #define SPAMSETTINGS_BADWORDSCAN_VOICE  0x200000
76 #define SPAMSETTINGS_BADWORDCHARS       "tuv"
77 #define SPAMSETTINGS_BADWORDEXCINDEX    6
78
79 #define SPAMSETTINGS_CHARS     SPAMSETTINGS_SPAMCHARS SPAMSETTINGS_FLOODCHARS SPAMSETTINGS_JOINCHARS SPAMSETTINGS_BOTNETCHARS SPAMSETTINGS_CAPSCHARS SPAMSETTINGS_DIGITCHARS SPAMSETTINGS_BADWORDCHARS
80 #define SPAMSETTINGS_FLAGS              0x7fffff /* all flags that can be stored in the database */
81 #define SPAMSETTINGS_EXCEPTINDEXES      7
82 #define SPAMSETTINGS_SENSIBILITYINDEXES 2
83 #define SPAMSETTINGS_PERCENTINDEXES     2
84
85 //SCRIPT FLAGS
86 #define SPAMSETTINGS_KICKEDBOTQUEUE     0x0400000
87 #define SPAMSETTINGS_ISTIMEBAN          0x0800000
88 #define SPAMSETTINGS_SETTIMEBAN         0x1000000
89
90 #define MAX_FLOOD_AMOUNT 300
91 #define MIN_FLOOD_AMOUNT 2
92 #define MAX_FLOOD_TIME   200
93
94 #define MAX_JOIN_AMOUNT 300
95 #define MIN_JOIN_AMOUNT 2
96 #define MAX_JOIN_TIME   200
97
98 #define BOTNETSCAN_USERS 4
99 #define BOTNETSCAN_TIME 2
100
101 struct NeonSpamSettings {
102     unsigned int flags;
103     unsigned char spam_amount;
104     unsigned char sensibility_amount[SPAMSETTINGS_SENSIBILITYINDEXES];
105     unsigned char sensibility_time[SPAMSETTINGS_SENSIBILITYINDEXES];
106     unsigned int exceptlevel[SPAMSETTINGS_EXCEPTINDEXES];
107     unsigned char percent[SPAMSETTINGS_PERCENTINDEXES];
108     
109     //joinflood
110     struct NeonSpamJoinNode *join_nodes;
111     
112     //botnet
113     unsigned long lastmsg; //crc32 hash
114     time_t lastmsg_time;
115     char *botnicks[BOTNETSCAN_USERS];
116     
117     //badword scan
118     struct NeonSpamBadword *badwords;
119 };
120
121 struct NeonSpamBadword {
122     int id;
123     char *badword;
124     unsigned char use_defaults : 1;
125     unsigned int exceptlevel : 9;
126     unsigned char scan_ops : 1;
127     unsigned char scan_voice : 1;
128     unsigned char use_default_reaction : 1;
129     unsigned int reaction;
130     unsigned int reaction_time;
131     struct NeonSpamBadword *next;
132 };
133
134 /* PENALTY SYSTEM
135 * user gets MAX_FLOOD_TIME points per message
136 * points get removed each loop
137 * pounts to be removed each second:
138 *  MAX_FLOOD_TIME/flood_time
139
140 * the floodlimit is reached, if the penalty points 
141 * are bigger than MAX_FLOOD_TIME * flood_amount
142 */
143
144 #define NEONSPAMNODE_FLAG_CAPSSCAN_WARNED  0x01
145 #define NEONSPAMNODE_FLAG_DIGITSCAN_WARNED 0x02
146
147 struct NeonSpamNode {
148     unsigned long lastmsg; //crc32 hash
149     unsigned char spamcount;
150     int floodpenalty;
151     time_t last_penalty_update;
152     unsigned char flags;
153 };
154
155 struct NeonSpamJoinNode {
156     char *ident;
157     char *host;
158     int joinpenalty;
159     time_t last_penalty_update;
160     struct NeonSpamJoinNode *next;
161 };
162
163 void init_NeonSpam(int type);
164 void free_NeonSpam(int type);
165
166 void freeNeonSpamSettings(struct NeonSpamSettings *settings);
167 char* convertNeonSpamSettingsToString(unsigned int flags, char *buffer);
168 int loadNeonSpamSettings(struct ChanNode *chan);
169
170 #endif