]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
Added preliminary support for a bottler-detection module
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
1 #include "users.h"
2 #include "channels.h"
3 #include "modules.h"
4
5 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
6
7 class ModuleAntiBottler : public Module
8 {
9  private:
10          
11          Server *Srv;
12  public:
13         ModuleAntiBottler()
14         {
15                 Srv = new Server;
16         }
17         
18         virtual ~ModuleAntiBottler()
19         {
20                 delete Srv;
21         }
22         
23         virtual Version GetVersion()
24         {
25                 return Version(1,0,0,0);
26         }
27
28
29         virtual void OnServerRaw(std::string &raw, bool inbound)
30         {
31                 if (inbound)
32                 {
33                         char data[MAXBUF];
34                         strncpy(data,raw.c_str(),MAXBUF);
35                         bool not_bottler = false;
36                         if (!strncmp(data,"user ",5))
37                         {
38                                 for (int j = 0; j < strlen(data); j++)
39                                 {
40                                         if (data[j] = ':')
41                                                 break;
42                                                 
43                                         if (data[j] = '"')
44                                         {
45                                                 not_bottler = true;
46                                         }
47                                 }
48                                 char *user = strtok(data," ");
49                                 char *ident = strtok(NULL," ");
50                                 char *local = strtok(NULL," ");
51                                 char *remote = strtok(NULL," :");
52                                 char *gecos = strtok(NULL,"\r\n");
53                                 for (int j = 0; j < strlen(remote); j++)
54                                 {
55                                         if (((remote[j] < '0') || (remote[j] > '9')) && (remote[j] != '.'))
56                                         {
57                                                 not_bottler = true;
58                                         }
59                                 }
60
61                                 if (!not_bottler)
62                                 {
63                                         raw = "USER bottler "+std::string(local)+" "+std::string(remote)+" "+std::string(gecos)+" [Possible bottler, ident: "+std::string(ident)+"]";
64                                 }
65                         }
66                 }
67         }       
68 };
69
70
71 class ModuleAntiBottlerFactory : public ModuleFactory
72 {
73  public:
74         ModuleAntiBottlerFactory()
75         {
76         }
77         
78         ~ModuleAntiBottlerFactory()
79         {
80         }
81         
82         virtual Module * CreateModule()
83         {
84                 return new ModuleAntiBottler;
85         }
86         
87 };
88
89
90 extern "C" void * init_module( void )
91 {
92         return new ModuleAntiBottlerFactory;
93 }
94