]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
New 'Implements' system
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16 using namespace std;
17
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21
22 /* $ModDesc: Changes the ident of connecting bottler clients to 'bottler' */
23
24 class ModuleAntiBottler : public Module
25 {
26  private:
27          
28          Server *Srv;
29  public:
30         ModuleAntiBottler(Server* Me)
31                 : Module::Module(Me)
32         {
33                 Srv = Me;
34         }
35
36         void Implements(char* List)
37         {
38                 List[I_OnServerRaw] = 1;
39         }
40
41         
42         virtual ~ModuleAntiBottler()
43         {
44         }
45         
46         virtual Version GetVersion()
47         {
48                 return Version(1,0,0,1,VF_VENDOR);
49         }
50
51         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
52         {
53                 if (inbound)
54                 {
55                         char data[MAXBUF];
56                         strncpy(data,raw.c_str(),MAXBUF);
57                         bool not_bottler = false;
58                         if (!strncmp(data,"user ",5))
59                         {
60                                 for (char* j = data; *j; j++)
61                                 {
62                                         if (*j == ':')
63                                                 break;
64                                                 
65                                         if (*j == '"')
66                                         {
67                                                 not_bottler = true;
68                                         }
69                                 }
70                                 // Bug Fix (#14) -- FCS
71
72                                 if (!(data) || !(*data))
73                                         return;
74
75                                 /*
76                                  * slight efficiency fix: strtok() just returns NULL if it has no more
77                                  * tokens to return. Plus strlen's here really could have been replaced
78                                  * with above pointer voodoo :-). --w00t
79                                  */
80                                 strtok(data," ");
81                                 char *ident = strtok(NULL," ");
82                                 char *local = strtok(NULL," ");
83                                 char *remote = strtok(NULL," :");
84                                 char *gecos = strtok(NULL,"\r\n");
85
86                                 if (!ident || !local || !remote || !gecos)
87                                         return;
88
89                                 for (char* j = remote; *j; j++)
90                                 {
91                                         if (((*j < '0') || (*j > '9')) && (*j != '.'))
92                                         {
93                                                 not_bottler = true;
94                                         }
95                                 }
96
97                                 if (!not_bottler)
98                                 {
99                                         raw = "USER bottler "+std::string(local)+" "+std::string(remote)+" "+std::string(gecos)+" [Possible bottler, ident: "+std::string(ident)+"]";
100                                 }
101                         }
102                 }
103         }       
104 };
105
106
107 class ModuleAntiBottlerFactory : public ModuleFactory
108 {
109  public:
110         ModuleAntiBottlerFactory()
111         {
112         }
113         
114         ~ModuleAntiBottlerFactory()
115         {
116         }
117         
118         virtual Module * CreateModule(Server* Me)
119         {
120                 return new ModuleAntiBottler(Me);
121         }
122         
123 };
124
125
126 extern "C" void * init_module( void )
127 {
128         return new ModuleAntiBottlerFactory;
129 }
130