]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
In the grand tradition of huge fucking commits:
[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 "wildcard.h"
16
17 /* $ModDesc: Provides /tline command used to test who a mask matches */
18
19 /** Handle /TLINE
20  */ 
21 class cmd_tline : public Command
22 {
23  public:
24         cmd_tline (InspIRCd* Instance) : Command(Instance,"TLINE", 'o', 1)
25         {
26                 this->source = "m_tline.so";
27                 this->syntax = "<mask>";
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, User *user)
31         {
32                 float n_counted = 0;
33                 float n_matched = 0;
34                 float n_match_host = 0;
35                 float n_match_ip = 0;
36
37                 for (user_hash::const_iterator u = ServerInstance->clientlist->begin(); u != ServerInstance->clientlist->end(); u++)
38                 {
39                         n_counted++;
40                         if (match(u->second->GetFullRealHost(),parameters[0]))
41                         {
42                                 n_matched++;
43                                 n_match_host++;
44                         }
45                         else
46                         {
47                                 char host[MAXBUF];
48                                 snprintf(host, MAXBUF, "%s@%s", u->second->ident, u->second->GetIPString());
49                                 if (match(host, parameters[0], true))
50                                 {
51                                         n_matched++;
52                                         n_match_ip++;
53                                 }
54                         }
55                 }
56                 if (n_matched)
57                         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);
58                 else
59                         user->WriteServ( "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick, n_counted, parameters[0]);
60
61                 return CMD_LOCALONLY;                   
62         }
63 };
64
65 class ModuleTLine : public Module
66 {
67         cmd_tline* newcommand;
68  public:
69         ModuleTLine(InspIRCd* Me)
70                 : Module(Me)
71         {
72                 
73                 newcommand = new cmd_tline(ServerInstance);
74                 ServerInstance->AddCommand(newcommand);
75         }
76
77         void Implements(char* List)
78         {
79         }
80
81         virtual ~ModuleTLine()
82         {
83         }
84         
85         virtual Version GetVersion()
86         {
87                 return Version(1, 1, 0, 0, VF_VENDOR,API_VERSION);
88         }
89 };
90
91 MODULE_INIT(ModuleTLine)
92