]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
code tidyups
[user/henk/code/inspircd.git] / src / modules / m_close.cpp
1 /*       +------------------------------------+
2  *       | UnrealIRCd v4.0                    |
3  *       +------------------------------------+
4  *
5  * UnrealIRCd 4.0 (C) 2008 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 CommandClose : public Command
19 {
20  public:
21         /* Command 'close', needs operator */
22         CommandClose (InspIRCd* Instance) : Command(Instance,"CLOSE", "o", 0)
23         {
24                 this->source = "m_close.so";
25         }
26
27         CmdResult Handle (const std::vector<std::string> &parameters, User *user)
28         {
29                 std::map<std::string,int> closed;
30
31                 for (std::vector<User*>::iterator u = ServerInstance->Users->local_users.begin(); u != ServerInstance->Users->local_users.end(); u++)
32                 {
33                         if ((*u)->registered != REG_ALL)
34                         {
35                                 ServerInstance->Users->QuitUser(*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         CommandClose* newcommand;
59  public:
60         ModuleClose(InspIRCd* Me)
61                 : Module(Me)
62         {
63                 // Create a new command
64                 newcommand = new CommandClose(ServerInstance);
65                 ServerInstance->AddCommand(newcommand);
66
67         }
68
69         virtual ~ModuleClose()
70         {
71         }
72
73         virtual Version GetVersion()
74         {
75                 return Version(1, 2, 0, 0, VF_VENDOR, API_VERSION);
76         }
77 };
78
79 MODULE_INIT(ModuleClose)