]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
Consider your crackpipes confiscated, there was some right dailywtf-worthy stuff...
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "users.h"
15 #include "channels.h"
16 #include "modules.h"
17
18 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
19
20 class ModuleAntiBottler : public Module
21 {
22  public:
23         ModuleAntiBottler(InspIRCd* Me)
24                 : Module::Module(Me)
25         {
26                 
27         }
28
29         void Implements(char* List)
30         {
31                 List[I_OnServerRaw] = 1;
32         }
33
34         
35         virtual ~ModuleAntiBottler()
36         {
37         }
38         
39         virtual Version GetVersion()
40         {
41                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
42         }
43
44         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
45         {
46                 if (inbound)
47                 {
48                         char data[MAXBUF];
49                         strlcpy(data,raw.c_str(),MAXBUF);
50                         bool not_bottler = false;
51                         if (!strncmp(data,"user ",5))
52                         {
53                                 for (char* j = data; *j; j++)
54                                 {
55                                         if (*j == ':')
56                                                 break;
57                                                 
58                                         if (*j == '"')
59                                         {
60                                                 not_bottler = true;
61                                         }
62                                 }
63                                 // Bug Fix (#14) -- FCS
64
65                                 if (!(data) || !(*data))
66                                         return;
67
68                                 strtok(data," ");
69                                 char *ident = strtok(NULL," ");
70                                 char *local = strtok(NULL," ");
71                                 char *remote = strtok(NULL," :");
72                                 char *gecos = strtok(NULL,"\r\n");
73
74                                 if (!ident || !local || !remote || !gecos)
75                                         return;
76
77                                 for (char* j = remote; *j; j++)
78                                 {
79                                         if (((*j < '0') || (*j > '9')) && (*j != '.'))
80                                         {
81                                                 not_bottler = true;
82                                         }
83                                 }
84
85                                 if (!not_bottler)
86                                 {
87                                         raw = "USER bottler "+std::string(local)+" "+std::string(remote)+" "+std::string(gecos)+" [Possible bottler, ident: "+std::string(ident)+"]";
88                                 }
89                         }
90                 }
91         }       
92 };
93
94
95 class ModuleAntiBottlerFactory : public ModuleFactory
96 {
97  public:
98         ModuleAntiBottlerFactory()
99         {
100         }
101         
102         ~ModuleAntiBottlerFactory()
103         {
104         }
105         
106         virtual Module * CreateModule(InspIRCd* Me)
107         {
108                 return new ModuleAntiBottler(Me);
109         }
110         
111 };
112
113
114 extern "C" void * init_module( void )
115 {
116         return new ModuleAntiBottlerFactory;
117 }
118