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