]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
Fixed percentage in m_tline (division was backwards, so it displayed 200% instead...
[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 "wildcard.h"
24 #include "inspircd.h"
25 #include "dns.h"
26
27 /* $ModDesc: Provides /tline command used to test who a mask matches */
28
29 /** Handle /TLINE
30  */ 
31 class cmd_tline : public command_t
32 {
33  public:
34         cmd_tline (InspIRCd* Instance) : command_t(Instance,"TLINE", 'o', 1)
35         {
36                 this->source = "m_tline.so";
37                 this->syntax = "<mask>";
38         }
39
40         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
41         {
42                 float n_counted = 0;
43                 float n_matched = 0;
44                 float n_match_host = 0;
45                 float n_match_ip = 0;
46
47                 for (user_hash::const_iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
48                 {
49                         n_counted++;
50                         if (match(u->second->GetFullRealHost(),parameters[0]))
51                         {
52                                 n_matched++;
53                                 n_match_host++;
54                         }
55                         else
56                         {
57                                 char host[MAXBUF];
58                                 snprintf(host, MAXBUF, "%s@%s", u->second->ident, u->second->GetIPString());
59                                 if (match(host, parameters[0], true))
60                                 {
61                                         n_matched++;
62                                         n_match_ip++;
63                                 }
64                         }
65                 }
66                 if (n_matched)
67                         user->WriteServ( "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_matched/n_counted)*100, n_match_host, n_match_ip);
68                 else
69                         user->WriteServ( "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick, n_counted, parameters[0]);
70
71                 return CMD_FAILURE;
72                         
73         }
74 };
75
76 class ModuleTLine : public Module
77 {
78         cmd_tline* newcommand;
79  public:
80         ModuleTLine(InspIRCd* Me)
81                 : Module::Module(Me)
82         {
83                 
84                 newcommand = new cmd_tline(ServerInstance);
85                 ServerInstance->AddCommand(newcommand);
86         }
87
88         void Implements(char* List)
89         {
90         }
91
92         virtual ~ModuleTLine()
93         {
94         }
95         
96         virtual Version GetVersion()
97         {
98                 return Version(1, 0, 0, 0, VF_VENDOR,API_VERSION);
99         }
100 };
101
102
103 class ModuleTLineFactory : public ModuleFactory
104 {
105  public:
106         ModuleTLineFactory()
107         {
108         }
109         
110         ~ModuleTLineFactory()
111         {
112         }
113         
114         virtual Module * CreateModule(InspIRCd* Me)
115         {
116                 return new ModuleTLine(Me);
117         }
118         
119 };
120
121
122 extern "C" void * init_module( void )
123 {
124         return new ModuleTLineFactory;
125 }
126