]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
Implement feature in bug #395 reported by stealth, and tidy up a bit
[user/henk/code/inspircd.git] / src / modules / m_close.cpp
1 /*       +------------------------------------+
2  *       | UnrealIRCd v4.0                    |
3  *       +------------------------------------+
4  *
5  * UnrealIRCd 4.0 (C) 2007 Carsten Valdemar Munk 
6  * This program is free but copyrighted software; see
7  *            the file COPYING for details.
8  *
9  * ---------------------------------------------------
10  */
11
12 #include "inspircd.h"
13 #include "users.h"
14 #include "channels.h"
15 #include "modules.h"
16
17 /* $ModDesc: Provides /CLOSE functionality */
18
19 /** Handle /CLOSE
20  */
21 class cmd_close : public command_t
22 {
23  public:
24         /* Command 'close', needs operator */
25         cmd_close (InspIRCd* Instance) : command_t(Instance,"CLOSE", 'o', 0)
26         {
27                 this->source = "m_close.so";
28         }
29
30         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
31         {
32                 std::map<std::string,int> closed;
33
34                 for (std::vector<userrec*>::iterator u = ServerInstance->local_users.begin(); u != ServerInstance->local_users.end(); u++)
35                 {
36                         if ((*u)->registered != REG_ALL)
37                         {
38                                 userrec::QuitUser(ServerInstance, *u, "Closing all unknown connections per request");
39                                 std::string key = ConvToStr((*u)->GetIPString())+"."+ConvToStr((*u)->GetPort());
40                                 closed[key]++;
41                         }
42                 }
43
44                 int total = 0;
45                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
46                 {
47                         user->WriteServ("NOTICE %s :*** Closed %d unknown connection%s from [%s]",user->nick,(*ci).second,((*ci).second>1)?"s":"",(*ci).first.c_str());
48                         total += (*ci).second;
49                 }
50                 if (total)
51                         user->WriteServ("NOTICE %s :*** %i unknown connection%s closed",user->nick,total,(total>1)?"s":"");
52                 else
53                         user->WriteServ("NOTICE %s :*** No unknown connections found",user->nick);
54                         
55                 return CMD_LOCALONLY;
56         }
57 };
58
59 class ModuleClose : public Module
60 {
61         cmd_close* newcommand;
62  public:
63         ModuleClose(InspIRCd* Me)
64                 : Module(Me)
65         {
66                 // Create a new command
67                 newcommand = new cmd_close(ServerInstance);
68                 ServerInstance->AddCommand(newcommand);
69         }
70
71         virtual ~ModuleClose()
72         {
73         }
74
75         virtual Version GetVersion()
76         {
77                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
78         }
79 };
80
81 MODULE_INIT(ModuleClose)