]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
In the grand tradition of huge fucking commits:
[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
16 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
17
18 class ModuleAntiBottler : public Module
19 {
20  public:
21         ModuleAntiBottler(InspIRCd* Me)
22                 : Module(Me)
23         {
24                 
25         }
26
27         void Implements(char* List)
28         {
29                 List[I_OnPreCommand] = 1;
30         }
31
32         
33         virtual ~ModuleAntiBottler()
34         {
35         }
36         
37         virtual Version GetVersion()
38         {
39                 return Version(1,1,0,1,VF_VENDOR,API_VERSION);
40         }
41
42         virtual int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
43         {
44                 char data[MAXBUF];
45                 strlcpy(data,original_line.c_str(),MAXBUF);
46                 bool not_bottler = false;
47                 if (!strncmp(data,"user ",5))
48                 {
49                         for (char* j = data; *j; j++)
50                         {
51                                 if (*j == ':')
52                                         break;
53                                         
54                                 if (*j == '"')
55                                 {
56                                         not_bottler = true;
57                                 }
58                         }
59                         // Bug Fix (#14) -- FCS
60                         if (!(data) || !(*data))
61                                 return 0;
62
63                         strtok(data," ");
64                         char *ident = strtok(NULL," ");
65                         char *local = strtok(NULL," ");
66                         char *remote = strtok(NULL," :");
67                         char *gecos = strtok(NULL,"\r\n");
68
69                         if (!ident || !local || !remote || !gecos)
70                                 return 0;
71
72                         for (char* j = remote; *j; j++)
73                         {
74                                 if (((*j < '0') || (*j > '9')) && (*j != '.'))
75                                 {
76                                         not_bottler = true;
77                                 }
78                         }
79
80                         if (!not_bottler)
81                         {
82                                 std::string strgecos = std::string(gecos) + "[Possible bottler, ident: " + std::string(ident) + "]";
83                                 const char* modified[4];
84                                 modified[0] = "bottler";
85                                 modified[1] = local;
86                                 modified[2] = remote;
87                                 modified[3] = strgecos.c_str();
88                                 ServerInstance->Parser->CallHandler("USER", modified, 4, user);
89                                 return 1;
90                         }
91                 }
92                 return 0;
93         }
94 };
95
96 MODULE_INIT(ModuleAntiBottler)