]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
64beb31203c5db6adcd5a7425cf238af80b88b7b
[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 /** Handle /TLINE
24  */
25 class CommandTline : public Command
26 {
27  public:
28         CommandTline(Module* Creator) : Command(Creator,"TLINE", 1)
29         {
30                 flags_needed = 'o'; this->syntax = "<mask>";
31         }
32
33         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
34         {
35                 unsigned int n_matched = 0;
36                 unsigned int n_match_host = 0;
37                 unsigned int n_match_ip = 0;
38
39                 for (user_hash::const_iterator u = ServerInstance->Users->clientlist->begin(); u != ServerInstance->Users->clientlist->end(); u++)
40                 {
41                         if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
42                         {
43                                 n_matched++;
44                                 n_match_host++;
45                         }
46                         else
47                         {
48                                 std::string host = u->second->ident + "@" + u->second->GetIPString();
49                                 if (InspIRCd::MatchCIDR(host, parameters[0]))
50                                 {
51                                         n_matched++;
52                                         n_match_ip++;
53                                 }
54                         }
55                 }
56
57                 unsigned long n_counted = ServerInstance->Users->clientlist->size();
58                 if (n_matched)
59                 {
60                         float p = (n_matched / (float)n_counted) * 100;
61                         user->WriteNotice(InspIRCd::Format("*** TLINE: Counted %lu user(s). Matched '%s' against %u user(s) (%0.2f%% of the userbase). %u by hostname and %u by IP address.", n_counted, parameters[0].c_str(), n_matched, p, n_match_host, n_match_ip));
62                 }
63                 else
64                         user->WriteNotice(InspIRCd::Format("*** TLINE: Counted %lu user(s). Matched '%s' against no user(s).", n_counted, parameters[0].c_str()));
65
66                 return CMD_SUCCESS;
67         }
68 };
69
70 class ModuleTLine : public Module
71 {
72         CommandTline cmd;
73  public:
74         ModuleTLine()
75                 : cmd(this)
76         {
77         }
78
79         Version GetVersion() CXX11_OVERRIDE
80         {
81                 return Version("Provides /tline command used to test who a mask matches", VF_VENDOR);
82         }
83 };
84
85 MODULE_INIT(ModuleTLine)