9a7cc6349c6d3709bad79b33c7a663fa93a3f178
[NeonServV5.git] / src / bot_NeonSpam.h
1 /* bot_NeonSpam.h - NeonServ v5.1
2  * Copyright (C) 2011  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 //SPAMSCAN
24 #define SPAMSETTINGS_SPAMSCAN           0x000001
25 #define SPAMSETTINGS_SPAMSCAN_OPS       0x000002
26 #define SPAMSETTINGS_SPAMSCAN_VOICE     0x000004
27 #define SPAMSETTINGS_SPAMCHARS          "abc"
28 #define SPAMSETTINGS_SPAMEXCINDEX       0
29
30 //FLOODSCAN
31 #define SPAMSETTINGS_FLOODSCAN          0x000008
32 #define SPAMSETTINGS_FLOODSCAN_OPS      0x000010
33 #define SPAMSETTINGS_FLOODSCAN_VOICE    0x000020
34 #define SPAMSETTINGS_FLOODCHARS         "def"
35 #define SPAMSETTINGS_FLOODEXCINDEX      1
36 #define SPAMSETTINGS_FLOODSENINDEX      0
37
38 //JOINSCAN
39 #define SPAMSETTINGS_JOINSCAN           0x000040
40 #define SPAMSETTINGS_JOINSCAN_OPS       0x000080
41 #define SPAMSETTINGS_JOINSCAN_VOICE     0x000100
42 #define SPAMSETTINGS_JOINCHARS          "ghi"
43 #define SPAMSETTINGS_JOINEXCINDEX       2
44 #define SPAMSETTINGS_JOINSENINDEX       1
45
46 //BOTNET SCAN
47 #define SPAMSETTINGS_BOTNETSCAN         0x000200
48 #define SPAMSETTINGS_BOTNETSCAN_OPS     0x000400
49 #define SPAMSETTINGS_BOTNETSCAN_VOICE   0x000800
50 #define SPAMSETTINGS_BOTNETSCAN_STRIPCC 0x001000
51 #define SPAMSETTINGS_BOTNETCHARS        "jklm"
52 #define SPAMSETTINGS_BOTNETEXCINDEX     3
53
54 //CAPSSCAN
55 #define SPAMSETTINGS_CAPSSCAN           0x002000
56 #define SPAMSETTINGS_CAPSSCAN_OPS       0x004000
57 #define SPAMSETTINGS_CAPSSCAN_VOICE     0x008000
58 #define SPAMSETTINGS_CAPSCHARS          "nop"
59 #define SPAMSETTINGS_CAPSEXCINDEX       4
60 #define SPAMSETTINGS_CAPSPERCENTINDEX   0
61
62 //DIGITSCAN
63 #define SPAMSETTINGS_DIGITSCAN          0x010000
64 #define SPAMSETTINGS_DIGITSCAN_OPS      0x020000
65 #define SPAMSETTINGS_DIGITSCAN_VOICE    0x040000
66 #define SPAMSETTINGS_DIGITCHARS         "qrs"
67 #define SPAMSETTINGS_DIGITEXCINDEX      5
68 #define SPAMSETTINGS_DIGITPERCENTINDEX  1
69
70
71 #define SPAMSETTINGS_CHARS     SPAMSETTINGS_SPAMCHARS SPAMSETTINGS_FLOODCHARS SPAMSETTINGS_JOINCHARS SPAMSETTINGS_BOTNETCHARS SPAMSETTINGS_CAPSCHARS SPAMSETTINGS_DIGITCHARS
72 #define SPAMSETTINGS_FLAGS              0x07ffff /* all flags that can be stored in the database */
73 #define SPAMSETTINGS_EXCEPTINDEXES      6
74 #define SPAMSETTINGS_SENSIBILITYINDEXES 2
75 #define SPAMSETTINGS_PERCENTINDEXES     2
76
77 //SCRIPT FLAGS
78 #define SPAMSETTINGS_KICKEDBOTQUEUE     0x080000
79 #define SPAMSETTINGS_ISTIMEBAN          0x100000
80 #define SPAMSETTINGS_SETTIMEBAN         0x200000
81
82 #define MAX_FLOOD_AMOUNT 300
83 #define MIN_FLOOD_AMOUNT 2
84 #define MAX_FLOOD_TIME   200
85
86 #define MAX_JOIN_AMOUNT 300
87 #define MIN_JOIN_AMOUNT 2
88 #define MAX_JOIN_TIME   200
89
90 #define BOTNETSCAN_USERS 4
91 #define BOTNETSCAN_TIME 2
92
93 struct NeonSpamSettings {
94     unsigned int flags;
95     unsigned char spam_amount;
96     unsigned char sensibility_amount[SPAMSETTINGS_SENSIBILITYINDEXES];
97     unsigned char sensibility_time[SPAMSETTINGS_SENSIBILITYINDEXES];
98     unsigned int exceptlevel[SPAMSETTINGS_EXCEPTINDEXES];
99     unsigned char percent[SPAMSETTINGS_PERCENTINDEXES];
100     
101     //joinflood
102     struct NeonSpamJoinNode *join_nodes;
103     
104     //botnet
105     unsigned long lastmsg; //crc32 hash
106     time_t lastmsg_time;
107     char *botnicks[BOTNETSCAN_USERS];
108     
109     
110 };
111 /* PENALTY SYSTEM
112 * user gets MAX_FLOOD_TIME points per message
113 * points get removed each loop
114 * pounts to be removed each second:
115 *  MAX_FLOOD_TIME/flood_time
116
117 * the floodlimit is reached, if the penalty points 
118 * are bigger than MAX_FLOOD_TIME * flood_amount
119 */
120
121 #define NEONSPAMNODE_FLAG_CAPSSCAN_WARNED  0x01
122 #define NEONSPAMNODE_FLAG_DIGITSCAN_WARNED 0x02
123
124 struct NeonSpamNode {
125     unsigned long lastmsg; //crc32 hash
126     unsigned char spamcount;
127     int floodpenalty;
128     time_t last_penalty_update;
129     unsigned char flags;
130 };
131
132 struct NeonSpamJoinNode {
133     char *ident;
134     char *host;
135     int joinpenalty;
136     time_t last_penalty_update;
137     struct NeonSpamJoinNode *next;
138 };
139
140 void init_NeonSpam();
141 void loop_NeonSpam();
142 void free_NeonSpam();
143
144 void freeNeonSpamSettings(struct NeonSpamSettings *settings);
145 char* convertNeonSpamSettingsToString(unsigned int flags, char *buffer);
146
147 #endif