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