]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
Annotations
[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         CmdResult 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                 return CMD_FAILURE;
74                         
75         }
76 };
77
78 class ModuleTLine : public Module
79 {
80         cmd_tline* newcommand;
81  public:
82         ModuleTLine(InspIRCd* Me)
83                 : Module::Module(Me)
84         {
85                 
86                 newcommand = new cmd_tline(ServerInstance);
87                 ServerInstance->AddCommand(newcommand);
88         }
89
90         void Implements(char* List)
91         {
92         }
93
94         virtual ~ModuleTLine()
95         {
96         }
97         
98         virtual Version GetVersion()
99         {
100                 return Version(1, 0, 0, 0, VF_VENDOR);
101         }
102 };
103
104
105 class ModuleTLineFactory : public ModuleFactory
106 {
107  public:
108         ModuleTLineFactory()
109         {
110         }
111         
112         ~ModuleTLineFactory()
113         {
114         }
115         
116         virtual Module * CreateModule(InspIRCd* Me)
117         {
118                 return new ModuleTLine(Me);
119         }
120         
121 };
122
123
124 extern "C" void * init_module( void )
125 {
126         return new ModuleTLineFactory;
127 }
128