]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
b8dd420cdfda9a37fd4e2b5a1d4ba66298040b54
[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, userrec* user)
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                                 // Bug Fix (#14) -- FCS
49                                 if (!strlen(data)) return;                              
50                                 char *user = strtok(data," ");
51                                 if (!strlen(data)) return;
52                                 char *ident = strtok(NULL," ");
53                                 if (!strlen(data)) return;
54                                 char *local = strtok(NULL," ");
55                                 if (!strlen(data)) return;
56                                 char *remote = strtok(NULL," :");
57                                 if (!strlen(data)) return;
58                                 char *gecos = strtok(NULL,"\r\n");
59                                 for (int j = 0; j < strlen(remote); j++)
60                                 {
61                                         if (((remote[j] < '0') || (remote[j] > '9')) && (remote[j] != '.'))
62                                         {
63                                                 not_bottler = true;
64                                         }
65                                 }
66
67                                 if (!not_bottler)
68                                 {
69                                         raw = "USER bottler "+std::string(local)+" "+std::string(remote)+" "+std::string(gecos)+" [Possible bottler, ident: "+std::string(ident)+"]";
70                                 }
71                         }
72                 }
73         }       
74 };
75
76
77 class ModuleAntiBottlerFactory : public ModuleFactory
78 {
79  public:
80         ModuleAntiBottlerFactory()
81         {
82         }
83         
84         ~ModuleAntiBottlerFactory()
85         {
86         }
87         
88         virtual Module * CreateModule()
89         {
90                 return new ModuleAntiBottler;
91         }
92         
93 };
94
95
96 extern "C" void * init_module( void )
97 {
98         return new ModuleAntiBottlerFactory;
99 }
100