]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
Header rearrangement, move inspircd.h to top, remove stdio, stdlib, stdblahblah that...
[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 "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18
19 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
20
21 class ModuleAntiBottler : public Module
22 {
23  public:
24         ModuleAntiBottler(InspIRCd* Me)
25                 : Module(Me)
26         {
27                 
28         }
29
30         void Implements(char* List)
31         {
32                 List[I_OnPreCommand] = 1;
33         }
34
35         
36         virtual ~ModuleAntiBottler()
37         {
38         }
39         
40         virtual Version GetVersion()
41         {
42                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
43         }
44
45         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, userrec *user, bool validated, const std::string &original_line)
46         {
47                 char data[MAXBUF];
48                 strlcpy(data,original_line.c_str(),MAXBUF);
49                 bool not_bottler = false;
50                 if (!strncmp(data,"user ",5))
51                 {
52                         for (char* j = data; *j; j++)
53                         {
54                                 if (*j == ':')
55                                         break;
56                                         
57                                 if (*j == '"')
58                                 {
59                                         not_bottler = true;
60                                 }
61                         }
62                         // Bug Fix (#14) -- FCS
63                         if (!(data) || !(*data))
64                                 return 0;
65
66                         strtok(data," ");
67                         char *ident = strtok(NULL," ");
68                         char *local = strtok(NULL," ");
69                         char *remote = strtok(NULL," :");
70                         char *gecos = strtok(NULL,"\r\n");
71
72                         if (!ident || !local || !remote || !gecos)
73                                 return 0;
74
75                         for (char* j = remote; *j; j++)
76                         {
77                                 if (((*j < '0') || (*j > '9')) && (*j != '.'))
78                                 {
79                                         not_bottler = true;
80                                 }
81                         }
82
83                         if (!not_bottler)
84                         {
85                                 std::string strgecos = std::string(gecos) + "[Possible bottler, ident: " + std::string(ident) + "]";
86                                 const char* modified[3];
87                                 modified[0] = "bottler";
88                                 modified[1] = local;
89                                 modified[2] = remote;
90                                 modified[3] = strgecos.c_str();
91                                 ServerInstance->Parser->CallHandler("USER", modified, 4, user);
92                                 return 1;
93                         }
94                 }
95                 return 0;
96         }
97 };
98
99
100 class ModuleAntiBottlerFactory : public ModuleFactory
101 {
102  public:
103         ModuleAntiBottlerFactory()
104         {
105         }
106         
107         ~ModuleAntiBottlerFactory()
108         {
109         }
110         
111         virtual Module * CreateModule(InspIRCd* Me)
112         {
113                 return new ModuleAntiBottler(Me);
114         }
115         
116 };
117
118
119 extern "C" DllExport void * init_module( void )
120 {
121         return new ModuleAntiBottlerFactory;
122 }
123