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