]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
21441e456a844140f8960111463b1e7b2d64d84b
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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                 Implementation eventlist[] = { I_OnPreCommand };
26                 ServerInstance->Modules->Attach(eventlist, this, 1);
27         }
28
29
30
31         virtual ~ModuleAntiBottler()
32         {
33         }
34
35         virtual Version GetVersion()
36         {
37                 return Version("$Id$",VF_VENDOR,API_VERSION);
38         }
39
40         virtual int OnPreCommand(std::string &command, std::vector<std::string> &parameters, User *user, bool validated, const std::string &original_line)
41         {
42                 char data[MAXBUF];
43                 strlcpy(data,original_line.c_str(),MAXBUF);
44                 bool not_bottler = false;
45                 if (!strncmp(data,"user ",5))
46                 {
47                         for (char* j = data; *j; j++)
48                         {
49                                 if (*j == ':')
50                                         break;
51
52                                 if (*j == '"')
53                                 {
54                                         not_bottler = true;
55                                 }
56                         }
57                         // Bug Fix (#14) -- FCS
58                         if (!*data)
59                                 return 0;
60
61                         strtok(data," ");
62                         char *ident = strtok(NULL," ");
63                         char *local = strtok(NULL," ");
64                         char *remote = strtok(NULL," :");
65                         char *gecos = strtok(NULL,"\r\n");
66
67                         if (!ident || !local || !remote || !gecos)
68                                 return 0;
69
70                         for (char* j = remote; *j; j++)
71                         {
72                                 if (((*j < '0') || (*j > '9')) && (*j != '.'))
73                                 {
74                                         not_bottler = true;
75                                 }
76                         }
77
78                         if (!not_bottler)
79                         {
80                                 std::string strgecos = std::string(gecos) + "[Possible bottler, ident: " + std::string(ident) + "]";
81                                 std::vector<std::string> modified;
82                                 modified.push_back("bottler");
83                                 modified.push_back(local);
84                                 modified.push_back(remote);
85                                 modified.push_back(strgecos);
86                                 ServerInstance->Parser->CallHandler("USER", modified, user);
87                                 return 1;
88                         }
89                 }
90                 return 0;
91         }
92 };
93
94 MODULE_INIT(ModuleAntiBottler)