]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
e81c29d20fe459505aab313e07197e48f4774969
[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(Module* Creator) : Command(Creator,"CLOSE", 0)
33         {
34         flags_needed = 'o'; }
35
36         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
37         {
38                 std::map<std::string,int> closed;
39
40                 for (std::vector<User*>::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++)
41                 {
42                         if ((*u)->registered != REG_ALL)
43                         {
44                                 ServerInstance->Users->QuitUser(*u, "Closing all unknown connections per request");
45                                 std::string key = ConvToStr((*u)->GetIPString())+"."+ConvToStr((*u)->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                         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());
54                         total += (*ci).second;
55                 }
56                 if (total)
57                         user->WriteServ("NOTICE %s :*** %i unknown connection%s closed",user->nick.c_str(),total,(total>1)?"s":"");
58                 else
59                         user->WriteServ("NOTICE %s :*** No unknown connections found",user->nick.c_str());
60
61                 return CMD_SUCCESS;
62         }
63 };
64
65 class ModuleClose : public Module
66 {
67         CommandClose cmd;
68  public:
69         ModuleClose(InspIRCd* Me)
70                 : Module(Me), cmd(this)
71         {
72                 ServerInstance->AddCommand(&cmd);
73         }
74
75         virtual ~ModuleClose()
76         {
77         }
78
79         virtual Version GetVersion()
80         {
81                 return Version("$Id$", VF_VENDOR, API_VERSION);
82         }
83 };
84
85 MODULE_INIT(ModuleClose)