]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
Access local user list via new UserManager::GetLocalUsers() and make local_users...
[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 (const std::vector<std::string> &parameters, User *src)
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(); ++u)
40                 {
41                         LocalUser* user = *u;
42                         if (user->registered != REG_ALL)
43                         {
44                                 ServerInstance->Users->QuitUser(user, "Closing all unknown connections per request");
45                                 std::string key = ConvToStr(user->GetIPString())+"."+ConvToStr(user->GetServerPort());
46                                 closed[key]++;
47                         }
48                 }
49
50                 int total = 0;
51                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
52                 {
53                         src->WriteNotice("*** Closed " + ConvToStr(ci->second) + " unknown " + (ci->second == 1 ? "connection" : "connections") +
54                                 " from [" + ci->first + "]");
55                         total += ci->second;
56                 }
57                 if (total)
58                         src->WriteNotice("*** " + ConvToStr(total) + " unknown " + (total == 1 ? "connection" : "connections") + " closed");
59                 else
60                         src->WriteNotice("*** No unknown connections found");
61
62                 return CMD_SUCCESS;
63         }
64 };
65
66 class ModuleClose : public Module
67 {
68         CommandClose cmd;
69  public:
70         ModuleClose()
71                 : cmd(this)
72         {
73         }
74
75         Version GetVersion() CXX11_OVERRIDE
76         {
77                 return Version("Provides /CLOSE functionality", VF_VENDOR);
78         }
79 };
80
81 MODULE_INIT(ModuleClose)