]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
Fix these to use new hook system (u_listmode wasnt fixed yet)
[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                 Implementation eventlist[] = { I_OnPreCommand };
26                 ServerInstance->Modules->Attach(eventlist, this, 1);
27         }
28
29         void Implements(char* List)
30         {
31                 List[I_OnPreCommand] = 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 int OnPreCommand(const std::string &command, const char** parameters, int pcnt, User *user, bool validated, const std::string &original_line)
45         {
46                 char data[MAXBUF];
47                 strlcpy(data,original_line.c_str(),MAXBUF);
48                 bool not_bottler = false;
49                 if (!strncmp(data,"user ",5))
50                 {
51                         for (char* j = data; *j; j++)
52                         {
53                                 if (*j == ':')
54                                         break;
55                                         
56                                 if (*j == '"')
57                                 {
58                                         not_bottler = true;
59                                 }
60                         }
61                         // Bug Fix (#14) -- FCS
62                         if (!*data)
63                                 return 0;
64
65                         strtok(data," ");
66                         char *ident = strtok(NULL," ");
67                         char *local = strtok(NULL," ");
68                         char *remote = strtok(NULL," :");
69                         char *gecos = strtok(NULL,"\r\n");
70
71                         if (!ident || !local || !remote || !gecos)
72                                 return 0;
73
74                         for (char* j = remote; *j; j++)
75                         {
76                                 if (((*j < '0') || (*j > '9')) && (*j != '.'))
77                                 {
78                                         not_bottler = true;
79                                 }
80                         }
81
82                         if (!not_bottler)
83                         {
84                                 std::string strgecos = std::string(gecos) + "[Possible bottler, ident: " + std::string(ident) + "]";
85                                 const char* modified[4];
86                                 modified[0] = "bottler";
87                                 modified[1] = local;
88                                 modified[2] = remote;
89                                 modified[3] = strgecos.c_str();
90                                 ServerInstance->Parser->CallHandler("USER", modified, 4, user);
91                                 return 1;
92                         }
93                 }
94                 return 0;
95         }
96 };
97
98 MODULE_INIT(ModuleAntiBottler)