]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_tline.cpp
Add support for blocking tag messages with the deaf mode.
[user/henk/code/inspircd.git] / src / modules / m_tline.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2013, 2018 Sadie Powell <sadie@witchery.services>
5  *   Copyright (C) 2012, 2019 Robby <robby@chatbelgie.be>
6  *   Copyright (C) 2012, 2014 Attila Molnar <attilamolnar@hush.com>
7  *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
8  *   Copyright (C) 2007-2008 Robin Burchell <robin+git@viroteck.net>
9  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
10  *   Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
11  *
12  * This file is part of InspIRCd.  InspIRCd is free software: you can
13  * redistribute it and/or modify it under the terms of the GNU General Public
14  * License as published by the Free Software Foundation, version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but WITHOUT
17  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23  */
24
25
26 #include "inspircd.h"
27
28 /** Handle /TLINE
29  */
30 class CommandTline : public Command
31 {
32  public:
33         CommandTline(Module* Creator) : Command(Creator,"TLINE", 1)
34         {
35                 flags_needed = 'o'; this->syntax = "<mask>";
36         }
37
38         CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
39         {
40                 unsigned int n_matched = 0;
41                 unsigned int n_match_host = 0;
42                 unsigned int n_match_ip = 0;
43
44                 const user_hash& users = ServerInstance->Users->GetUsers();
45                 for (user_hash::const_iterator u = users.begin(); u != users.end(); ++u)
46                 {
47                         if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
48                         {
49                                 n_matched++;
50                                 n_match_host++;
51                         }
52                         else
53                         {
54                                 std::string host = u->second->ident + "@" + u->second->GetIPString();
55                                 if (InspIRCd::MatchCIDR(host, parameters[0]))
56                                 {
57                                         n_matched++;
58                                         n_match_ip++;
59                                 }
60                         }
61                 }
62
63                 unsigned long n_counted = users.size();
64                 if (n_matched)
65                 {
66                         float p = (n_matched / (float)n_counted) * 100;
67                         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));
68                 }
69                 else
70                         user->WriteNotice(InspIRCd::Format("*** TLINE: Counted %lu user(s). Matched '%s' against no user(s).", n_counted, parameters[0].c_str()));
71
72                 return CMD_SUCCESS;
73         }
74 };
75
76 class ModuleTLine : public Module
77 {
78         CommandTline cmd;
79  public:
80         ModuleTLine()
81                 : cmd(this)
82         {
83         }
84
85         Version GetVersion() CXX11_OVERRIDE
86         {
87                 return Version("Adds the /TLINE command which allows server operators to determine how many users would be affected by an X-line on a specified pattern.", VF_VENDOR);
88         }
89 };
90
91 MODULE_INIT(ModuleTLine)