]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
8c8fa92f554d0b280bccdc886b7c6c26720d06b3
[user/henk/code/inspircd.git] / src / modules / m_close.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  *
13  * Based on the UnrealIRCd 4.0 (1.1.x fork) module
14  *
15  * UnrealIRCd 4.0 (C) 2007 Carsten Valdemar Munk
16  * This program is free but copyrighted software; see
17  *            the file COPYING for details.
18  *
19  * ---------------------------------------------------
20  */
21
22 #include "inspircd.h"
23
24 /* $ModDesc: Provides /CLOSE functionality */
25
26 /** Handle /CLOSE
27  */
28 class CommandClose : public Command
29 {
30  public:
31         /* Command 'close', needs operator */
32         CommandClose (InspIRCd* Instance) : Command(Instance,"CLOSE", "o", 0)
33         {
34                 this->source = "m_close.so";
35         }
36
37         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
38         {
39                 std::map<std::string,int> closed;
40
41                 for (std::vector<User*>::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++)
42                 {
43                         if ((*u)->registered != REG_ALL)
44                         {
45                                 ServerInstance->Users->QuitUser(*u, "Closing all unknown connections per request");
46                                 std::string key = ConvToStr((*u)->GetIPString())+"."+ConvToStr((*u)->GetServerPort());
47                                 closed[key]++;
48                         }
49                 }
50
51                 int total = 0;
52                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
53                 {
54                         user->WriteServ("NOTICE %s :*** Closed %d unknown connection%s from [%s]",user->nick.c_str(),(*ci).second,((*ci).second>1)?"s":"",(*ci).first.c_str());
55                         total += (*ci).second;
56                 }
57                 if (total)
58                         user->WriteServ("NOTICE %s :*** %i unknown connection%s closed",user->nick.c_str(),total,(total>1)?"s":"");
59                 else
60                         user->WriteServ("NOTICE %s :*** No unknown connections found",user->nick.c_str());
61
62                 return CMD_LOCALONLY;
63         }
64 };
65
66 class ModuleClose : public Module
67 {
68         CommandClose* newcommand;
69  public:
70         ModuleClose(InspIRCd* Me)
71                 : Module(Me)
72         {
73                 // Create a new command
74                 newcommand = new CommandClose(ServerInstance);
75                 ServerInstance->AddCommand(newcommand);
76
77         }
78
79         virtual ~ModuleClose()
80         {
81         }
82
83         virtual Version GetVersion()
84         {
85                 return Version("$Id$", VF_VENDOR, API_VERSION);
86         }
87 };
88
89 MODULE_INIT(ModuleClose)