]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
For some reason this was VF_STATIC
[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
24 #include "wildcard.h"
25 #include "inspircd.h"
26 #include "dns.h"
27
28 /* $ModDesc: Provides /tline command used to test who a mask matches */
29
30
31
32          
33 class cmd_tline : public command_t
34 {
35  public:
36  cmd_tline (InspIRCd* Instance) : command_t(Instance,"TLINE", 'o', 1)
37         {
38                 this->source = "m_tline.so";
39                 this->syntax = "<mask>";
40         }
41
42         void Handle (const char** parameters, int pcnt, userrec *user)
43         {
44                 float n_counted = 0;
45                 float n_matched = 0;
46                 float n_match_host = 0;
47                 float n_match_ip = 0;
48
49                 for (user_hash::const_iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
50                 {
51                         n_counted++;
52                         if (match(u->second->GetFullRealHost(),parameters[0]))
53                         {
54                                 n_matched++;
55                                 n_match_host++;
56                         }
57                         else
58                         {
59                                 char host[MAXBUF];
60                                 sprintf(host, "%s@%s", u->second->ident, u->second->GetIPString());
61                                 if (match(host, parameters[0], true))
62                                 {
63                                         n_matched++;
64                                         n_match_ip++;
65                                 }
66                         }
67                 }
68                 if (n_matched)
69                         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_counted/n_matched)*100, n_match_host, n_match_ip);
70                 else
71                         user->WriteServ( "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick, n_counted, parameters[0]);
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);
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