]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
Change module versions to use a string instead of fixed digits, and use propset ID...
[user/henk/code/inspircd.git] / src / modules / m_tline.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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
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 (InspIRCd* Instance) : Command(Instance,"TLINE", "o", 1)
24         {
25                 this->source = "m_tline.so";
26                 this->syntax = "<mask>";
27         }
28
29         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
30         {
31                 float n_counted = 0;
32                 float n_matched = 0;
33                 float n_match_host = 0;
34                 float n_match_ip = 0;
35
36                 for (user_hash::const_iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
37                 {
38                         n_counted++;
39                         if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
40                         {
41                                 n_matched++;
42                                 n_match_host++;
43                         }
44                         else
45                         {
46                                 std::string host = std::string(u->second->ident) + "@" + u->second->GetIPString();
47                                 if (InspIRCd::MatchCIDR(host, parameters[0]))
48                                 {
49                                         n_matched++;
50                                         n_match_ip++;
51                                 }
52                         }
53                 }
54                 if (n_matched)
55                         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);
56                 else
57                         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());
58
59                 return CMD_LOCALONLY;
60         }
61 };
62
63 class ModuleTLine : public Module
64 {
65         CommandTline* newcommand;
66  public:
67         ModuleTLine(InspIRCd* Me)
68                 : Module(Me)
69         {
70
71                 newcommand = new CommandTline(ServerInstance);
72                 ServerInstance->AddCommand(newcommand);
73
74         }
75
76
77         virtual ~ModuleTLine()
78         {
79         }
80
81         virtual Version GetVersion()
82         {
83                 return Version("$Id$", VF_VENDOR,API_VERSION);
84         }
85 };
86
87 MODULE_INIT(ModuleTLine)
88