]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
01aa2e0b3fd7736266dcdb1a5d90964b426b7f19
[user/henk/code/inspircd.git] / src / modules / m_tline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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
16 /* $ModDesc: Provides /tline command used to test who a mask matches */
17
18 /** Handle /TLINE
19  */
20 class CommandTline : public Command
21 {
22  public:
23         CommandTline(Module* Creator) : Command(Creator,"TLINE", 1)
24         {
25                 flags_needed = 'o'; this->syntax = "<mask>";
26         }
27
28         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
29         {
30                 float n_counted = 0;
31                 float n_matched = 0;
32                 float n_match_host = 0;
33                 float n_match_ip = 0;
34
35                 for (user_hash::const_iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
36                 {
37                         n_counted++;
38                         if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
39                         {
40                                 n_matched++;
41                                 n_match_host++;
42                         }
43                         else
44                         {
45                                 std::string host = std::string(u->second->ident) + "@" + u->second->GetIPString();
46                                 if (InspIRCd::MatchCIDR(host, parameters[0]))
47                                 {
48                                         n_matched++;
49                                         n_match_ip++;
50                                 }
51                         }
52                 }
53                 if (n_matched)
54                         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.c_str(), n_counted, parameters[0].c_str(), n_matched, (n_matched/n_counted)*100, n_match_host, n_match_ip);
55                 else
56                         user->WriteServ( "NOTICE %s :*** TLINE: Counted %0.0f user(s). Matched '%s' against no user(s).", user->nick.c_str(), n_counted, parameters[0].c_str());
57
58                 return CMD_SUCCESS;
59         }
60 };
61
62 class ModuleTLine : public Module
63 {
64         CommandTline cmd;
65  public:
66         ModuleTLine()
67                 : cmd(this)
68         {
69                 ServerInstance->AddCommand(&cmd);
70         }
71
72
73         virtual ~ModuleTLine()
74         {
75         }
76
77         virtual Version GetVersion()
78         {
79                 return Version("Provides /tline command used to test who a mask matches", VF_VENDOR);
80         }
81 };
82
83 MODULE_INIT(ModuleTLine)
84