]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
General cleanup of code., add support for +Q channel mode (and config tag <remove...
[user/henk/code/inspircd.git] / src / modules / m_tline.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
17 using namespace std;
18
19 #include <stdio.h>
20 #include "users.h"
21 #include "channels.h"
22 #include "modules.h"
23 #include "helperfuncs.h"
24 #include "wildcard.h"
25 #include "dns.h"
26
27 /* $ModDesc: Provides /tline command used to test who a mask matches */
28
29 static Server *Srv;
30 extern user_hash clientlist;
31          
32 class cmd_tline : public command_t
33 {
34  public:
35         cmd_tline () : command_t("TLINE", 'o', 1)
36         {
37                 this->source = "m_tline.so";
38                 this->syntax = "<mask>";
39         }
40
41         void Handle (const char** parameters, int pcnt, userrec *user)
42         {
43                 float n_counted = 0;
44                 float n_matched = 0;
45                 float n_match_host = 0;
46                 float n_match_ip = 0;
47
48                 for (user_hash::const_iterator u = clientlist.begin(); u != clientlist.end(); u++)
49                 {
50                         n_counted++;
51                         if (match(u->second->GetFullRealHost(),parameters[0]))
52                         {
53                                 n_matched++;
54                                 n_match_host++;
55                         }
56                         else
57                         {
58                                 char host[MAXBUF];
59                                 sprintf(host, "%s@%s", u->second->ident, u->second->GetIPString());
60                                 if (match(host, parameters[0], true))
61                                 {
62                                         n_matched++;
63                                         n_match_ip++;
64                                 }
65                         }
66                 }
67                 if (n_matched)
68                         WriteServ(user->fd, "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against %0.0f user(s) (%0.2f%% of the userbase). %0.0f by hostname and %0.0f by IP address.",user->nick, n_counted, parameters[0], n_matched, (n_counted/n_matched)*100, n_match_host, n_match_ip);
69                 else
70                         WriteServ(user->fd, "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick, n_counted, parameters[0]);
71                         
72         }
73 };
74
75 class ModuleTLine : public Module
76 {
77         cmd_tline* newcommand;
78  public:
79         ModuleTLine(Server* Me)
80                 : Module::Module(Me)
81         {
82                 Srv = Me;
83                 newcommand = new cmd_tline();
84                 Srv->AddCommand(newcommand);
85         }
86
87         void Implements(char* List)
88         {
89         }
90
91         virtual ~ModuleTLine()
92         {
93         }
94         
95         virtual Version GetVersion()
96         {
97                 return Version(1,0,0,0,VF_STATIC|VF_VENDOR);
98         }
99 };
100
101
102 class ModuleTLineFactory : public ModuleFactory
103 {
104  public:
105         ModuleTLineFactory()
106         {
107         }
108         
109         ~ModuleTLineFactory()
110         {
111         }
112         
113         virtual Module * CreateModule(Server* Me)
114         {
115                 return new ModuleTLine(Me);
116         }
117         
118 };
119
120
121 extern "C" void * init_module( void )
122 {
123         return new ModuleTLineFactory;
124 }
125