]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
Use CommandBase::Params instead of std::vector<std::string>.
[user/henk/code/inspircd.git] / src / modules / m_close.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
5  *   Copyright (C) 2007 Carsten Valdemar Munk <carsten.munk+inspircd@gmail.com>
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 /CLOSE
24  */
25 class CommandClose : public Command
26 {
27  public:
28         /* Command 'close', needs operator */
29         CommandClose(Module* Creator) : Command(Creator,"CLOSE", 0)
30         {
31                 flags_needed = 'o';
32         }
33
34         CmdResult Handle(User* src, const Params& parameters) CXX11_OVERRIDE
35         {
36                 std::map<std::string,int> closed;
37
38                 const UserManager::LocalList& list = ServerInstance->Users.GetLocalUsers();
39                 for (UserManager::LocalList::const_iterator u = list.begin(); u != list.end(); )
40                 {
41                         // Quitting the user removes it from the list
42                         LocalUser* user = *u;
43                         ++u;
44                         if (user->registered != REG_ALL)
45                         {
46                                 ServerInstance->Users->QuitUser(user, "Closing all unknown connections per request");
47                                 std::string key = ConvToStr(user->GetIPString())+"."+ConvToStr(user->GetServerPort());
48                                 closed[key]++;
49                         }
50                 }
51
52                 int total = 0;
53                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
54                 {
55                         src->WriteNotice("*** Closed " + ConvToStr(ci->second) + " unknown " + (ci->second == 1 ? "connection" : "connections") +
56                                 " from [" + ci->first + "]");
57                         total += ci->second;
58                 }
59                 if (total)
60                         src->WriteNotice("*** " + ConvToStr(total) + " unknown " + (total == 1 ? "connection" : "connections") + " closed");
61                 else
62                         src->WriteNotice("*** No unknown connections found");
63
64                 return CMD_SUCCESS;
65         }
66 };
67
68 class ModuleClose : public Module
69 {
70         CommandClose cmd;
71  public:
72         ModuleClose()
73                 : cmd(this)
74         {
75         }
76
77         Version GetVersion() CXX11_OVERRIDE
78         {
79                 return Version("Provides /CLOSE functionality", VF_VENDOR);
80         }
81 };
82
83 MODULE_INIT(ModuleClose)