]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
e395b427fcd251f38cd44a99549edb0e6b2e881a
[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
14 /* $ModDesc: Provides /CLOSE functionality */
15
16 /** Handle /CLOSE
17  */
18 class cmd_close : public command_t
19 {
20  public:
21         /* Command 'close', needs operator */
22         cmd_close (InspIRCd* Instance) : command_t(Instance,"CLOSE", 'o', 0)
23         {
24                 this->source = "m_close.so";
25         }
26
27         CmdResult Handle (const char** parameters, int pcnt, userrec *user)
28         {
29                 std::map<std::string,int> closed;
30
31                 for (std::vector<userrec*>::iterator u = ServerInstance->local_users.begin(); u != ServerInstance->local_users.end(); u++)
32                 {
33                         if ((*u)->registered != REG_ALL)
34                         {
35                                 userrec::QuitUser(ServerInstance, *u, "Closing all unknown connections per request");
36                                 std::string key = ConvToStr((*u)->GetIPString())+"."+ConvToStr((*u)->GetPort());
37                                 closed[key]++;
38                         }
39                 }
40
41                 int total = 0;
42                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
43                 {
44                         user->WriteServ("NOTICE %s :*** Closed %d unknown connection%s from [%s]",user->nick,(*ci).second,((*ci).second>1)?"s":"",(*ci).first.c_str());
45                         total += (*ci).second;
46                 }
47                 if (total)
48                         user->WriteServ("NOTICE %s :*** %i unknown connection%s closed",user->nick,total,(total>1)?"s":"");
49                 else
50                         user->WriteServ("NOTICE %s :*** No unknown connections found",user->nick);
51                         
52                 return CMD_LOCALONLY;
53         }
54 };
55
56 class ModuleClose : public Module
57 {
58         cmd_close* newcommand;
59  public:
60         ModuleClose(InspIRCd* Me)
61                 : Module(Me)
62         {
63                 // Create a new command
64                 newcommand = new cmd_close(ServerInstance);
65                 ServerInstance->AddCommand(newcommand);
66         }
67
68         virtual ~ModuleClose()
69         {
70         }
71
72         virtual Version GetVersion()
73         {
74                 return Version(1, 1, 0, 0, VF_VENDOR, API_VERSION);
75         }
76 };
77
78 MODULE_INIT(ModuleClose)