]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
Replace copyright headers with headers granting specific authors copyright
[user/henk/code/inspircd.git] / src / modules / m_tline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 /* $ModDesc: Provides /tline command used to test who a mask matches */
24
25 /** Handle /TLINE
26  */
27 class CommandTline : public Command
28 {
29  public:
30         CommandTline(Module* Creator) : Command(Creator,"TLINE", 1)
31         {
32                 flags_needed = 'o'; this->syntax = "<mask>";
33         }
34
35         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
36         {
37                 float n_counted = 0;
38                 float n_matched = 0;
39                 float n_match_host = 0;
40                 float n_match_ip = 0;
41
42                 for (user_hash::const_iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
43                 {
44                         n_counted++;
45                         if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
46                         {
47                                 n_matched++;
48                                 n_match_host++;
49                         }
50                         else
51                         {
52                                 std::string host = std::string(u->second->ident) + "@" + u->second->GetIPString();
53                                 if (InspIRCd::MatchCIDR(host, parameters[0]))
54                                 {
55                                         n_matched++;
56                                         n_match_ip++;
57                                 }
58                         }
59                 }
60                 if (n_matched)
61                         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);
62                 else
63                         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());
64
65                 return CMD_SUCCESS;
66         }
67 };
68
69 class ModuleTLine : public Module
70 {
71         CommandTline cmd;
72  public:
73         ModuleTLine()
74                 : cmd(this)
75         {
76                 ServerInstance->AddCommand(&cmd);
77         }
78
79
80         virtual ~ModuleTLine()
81         {
82         }
83
84         virtual Version GetVersion()
85         {
86                 return Version("Provides /tline command used to test who a mask matches", VF_VENDOR);
87         }
88 };
89
90 MODULE_INIT(ModuleTLine)
91