]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_antibottler.cpp
Now with binary versioning goodness
[user/henk/code/inspircd.git] / src / modules / m_antibottler.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 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  public:
27         ModuleAntiBottler(InspIRCd* Me)
28                 : Module::Module(Me)
29         {
30                 
31         }
32
33         void Implements(char* List)
34         {
35                 List[I_OnServerRaw] = 1;
36         }
37
38         
39         virtual ~ModuleAntiBottler()
40         {
41         }
42         
43         virtual Version GetVersion()
44         {
45                 return Version(1,0,0,1,VF_VENDOR,API_VERSION);
46         }
47
48         virtual void OnServerRaw(std::string &raw, bool inbound, userrec* user)
49         {
50                 if (inbound)
51                 {
52                         char data[MAXBUF];
53                         strlcpy(data,raw.c_str(),MAXBUF);
54                         bool not_bottler = false;
55                         if (!strncmp(data,"user ",5))
56                         {
57                                 for (char* j = data; *j; j++)
58                                 {
59                                         if (*j == ':')
60                                                 break;
61                                                 
62                                         if (*j == '"')
63                                         {
64                                                 not_bottler = true;
65                                         }
66                                 }
67                                 // Bug Fix (#14) -- FCS
68
69                                 if (!(data) || !(*data))
70                                         return;
71
72                                 strtok(data," ");
73                                 char *ident = strtok(NULL," ");
74                                 char *local = strtok(NULL," ");
75                                 char *remote = strtok(NULL," :");
76                                 char *gecos = strtok(NULL,"\r\n");
77
78                                 if (!ident || !local || !remote || !gecos)
79                                         return;
80
81                                 for (char* j = remote; *j; j++)
82                                 {
83                                         if (((*j < '0') || (*j > '9')) && (*j != '.'))
84                                         {
85                                                 not_bottler = true;
86                                         }
87                                 }
88
89                                 if (!not_bottler)
90                                 {
91                                         raw = "USER bottler "+std::string(local)+" "+std::string(remote)+" "+std::string(gecos)+" [Possible bottler, ident: "+std::string(ident)+"]";
92                                 }
93                         }
94                 }
95         }       
96 };
97
98
99 class ModuleAntiBottlerFactory : public ModuleFactory
100 {
101  public:
102         ModuleAntiBottlerFactory()
103         {
104         }
105         
106         ~ModuleAntiBottlerFactory()
107         {
108         }
109         
110         virtual Module * CreateModule(InspIRCd* Me)
111         {
112                 return new ModuleAntiBottler(Me);
113         }
114         
115 };
116
117
118 extern "C" void * init_module( void )
119 {
120         return new ModuleAntiBottlerFactory;
121 }
122