]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_close.cpp
Remove InspIRCd* parameters and fields
[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                 std::vector<User*>::reverse_iterator u = ServerInstance->Users->local_users.rbegin();
41                 while (u != ServerInstance->Users->local_users.rend())
42                 {
43                         User* user = *u++;
44                         if (user->registered != REG_ALL)
45                         {
46                                 ServerInstance->Users->QuitUser(user, "Closing all unknown connections per request");
47                                 std::string key = ConvToStr(user->GetIPString())+"."+ConvToStr(user->GetServerPort());
48                                 closed[key]++;
49                         }
50                 }
51
52                 int total = 0;
53                 for (std::map<std::string,int>::iterator ci = closed.begin(); ci != closed.end(); ci++)
54                 {
55                         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());
56                         total += (*ci).second;
57                 }
58                 if (total)
59                         user->WriteServ("NOTICE %s :*** %i unknown connection%s closed",user->nick.c_str(),total,(total>1)?"s":"");
60                 else
61                         user->WriteServ("NOTICE %s :*** No unknown connections found",user->nick.c_str());
62
63                 return CMD_SUCCESS;
64         }
65 };
66
67 class ModuleClose : public Module
68 {
69         CommandClose cmd;
70  public:
71         ModuleClose()
72                 : cmd(this)
73         {
74                 ServerInstance->AddCommand(&cmd);
75         }
76
77         virtual ~ModuleClose()
78         {
79         }
80
81         virtual Version GetVersion()
82         {
83                 return Version("Provides /CLOSE functionality", VF_VENDOR, API_VERSION);
84         }
85 };
86
87 MODULE_INIT(ModuleClose)