2 * InspIRCd -- Internet Relay Chat Daemon
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>
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.
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
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/>.
30 class CommandTline : public Command
33 CommandTline(Module* Creator) : Command(Creator,"TLINE", 1)
35 flags_needed = 'o'; this->syntax = "<mask>";
38 CmdResult Handle(User* user, const Params& parameters) CXX11_OVERRIDE
40 unsigned int n_matched = 0;
41 unsigned int n_match_host = 0;
42 unsigned int n_match_ip = 0;
44 const user_hash& users = ServerInstance->Users->GetUsers();
45 for (user_hash::const_iterator u = users.begin(); u != users.end(); ++u)
47 if (InspIRCd::Match(u->second->GetFullRealHost(),parameters[0]))
54 std::string host = u->second->ident + "@" + u->second->GetIPString();
55 if (InspIRCd::MatchCIDR(host, parameters[0]))
63 unsigned long n_counted = users.size();
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));
70 user->WriteNotice(InspIRCd::Format("*** TLINE: Counted %lu user(s). Matched '%s' against no user(s).", n_counted, parameters[0].c_str()));
76 class ModuleTLine : public Module
85 Version GetVersion() CXX11_OVERRIDE
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);
91 MODULE_INIT(ModuleTLine)