]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
Minor spelling errors in m_spanningtree.so
[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 /* $ModDesc: Provides /CLOSE functionality */
24
25 /** Handle /CLOSE
26  */
27 class CommandClose : public Command
28 {
29  public:
30         /* Command 'close', needs operator */
31         CommandClose(Module* Creator) : Command(Creator,"CLOSE", 0)
32         {
33         flags_needed = 'o'; }
34
35         CmdResult Handle (const std::vector<std::string> &parameters, User *src)
36         {
37                 std::map<std::string,int> closed;
38
39                 for (LocalUserList::const_iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.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->WriteServ("NOTICE %s :*** Closed %d unknown connection%s from [%s]",src->nick.c_str(),(*ci).second,((*ci).second>1)?"s":"",(*ci).first.c_str());
54                         total += (*ci).second;
55                 }
56                 if (total)
57                         src->WriteServ("NOTICE %s :*** %i unknown connection%s closed",src->nick.c_str(),total,(total>1)?"s":"");
58                 else
59                         src->WriteServ("NOTICE %s :*** No unknown connections found",src->nick.c_str());
60
61                 return CMD_SUCCESS;
62         }
63 };
64
65 class ModuleClose : public Module
66 {
67         CommandClose cmd;
68  public:
69         ModuleClose()
70                 : cmd(this)
71         {
72         }
73
74         void init()
75         {
76                 ServerInstance->Modules->AddService(cmd);
77         }
78
79         virtual ~ModuleClose()
80         {
81         }
82
83         virtual Version GetVersion()
84         {
85                 return Version("Provides /CLOSE functionality", VF_VENDOR);
86         }
87 };
88
89 MODULE_INIT(ModuleClose)