]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
834cb7f4cf7c4be236fb92e76d88e217fc6f1684
[user/henk/code/inspircd.git] / src / modules / m_tline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "channels.h"
17 #include "modules.h"
18 #include "wildcard.h"
19
20 /* $ModDesc: Provides /tline command used to test who a mask matches */
21
22 /** Handle /TLINE
23  */ 
24 class cmd_tline : public command_t
25 {
26  public:
27         cmd_tline (InspIRCd* Instance) : command_t(Instance,"TLINE", 'o', 1)
28         {
29                 this->source = "m_tline.so";
30                 this->syntax = "<mask>";
31         }
32
33         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
34         {
35                 float n_counted = 0;
36                 float n_matched = 0;
37                 float n_match_host = 0;
38                 float n_match_ip = 0;
39
40                 for (user_hash::const_iterator u = ServerInstance->clientlist->begin(); u != ServerInstance->clientlist->end(); u++)
41                 {
42                         n_counted++;
43                         if (match(u->second->GetFullRealHost(),parameters[0]))
44                         {
45                                 n_matched++;
46                                 n_match_host++;
47                         }
48                         else
49                         {
50                                 char host[MAXBUF];
51                                 snprintf(host, MAXBUF, "%s@%s", u->second->ident, u->second->GetIPString());
52                                 if (match(host, parameters[0], true))
53                                 {
54                                         n_matched++;
55                                         n_match_ip++;
56                                 }
57                         }
58                 }
59                 if (n_matched)
60                         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);
61                 else
62                         user->WriteServ( "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick, n_counted, parameters[0]);
63
64                 return CMD_LOCALONLY;                   
65         }
66 };
67
68 class ModuleTLine : public Module
69 {
70         cmd_tline* newcommand;
71  public:
72         ModuleTLine(InspIRCd* Me)
73                 : Module(Me)
74         {
75                 
76                 newcommand = new cmd_tline(ServerInstance);
77                 ServerInstance->AddCommand(newcommand);
78         }
79
80         void Implements(char* List)
81         {
82         }
83
84         virtual ~ModuleTLine()
85         {
86         }
87         
88         virtual Version GetVersion()
89         {
90                 return Version(1, 1, 0, 0, VF_VENDOR,API_VERSION);
91         }
92 };
93
94 MODULE_INIT(ModuleTLine)
95