]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_lusers.cpp
Replace copyright headers with headers granting specific authors copyright
[user/henk/code/inspircd.git] / src / commands / cmd_lusers.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
6  *
7  * This file is part of InspIRCd.  InspIRCd is free software: you can
8  * redistribute it and/or modify it under the terms of the GNU General Public
9  * License as published by the Free Software Foundation, version 2.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20
21 #include "inspircd.h"
22
23 #ifndef CMD_LUSERS_H
24 #define CMD_LUSERS_H
25
26 // include the common header files
27
28 #include "users.h"
29 #include "channels.h"
30
31 /** Handle /LUSERS. These command handlers can be reloaded by the core,
32  * and handle basic RFC1459 commands. Commands within modules work
33  * the same way, however, they can be fully unloaded, where these
34  * may not.
35  */
36 class CommandLusers : public Command
37 {
38         unsigned int max_local, max_global;
39  public:
40         /** Constructor for lusers.
41          */
42         CommandLusers ( Module* parent) : Command(parent,"LUSERS",0,0),
43                 max_local(0), max_global(0)
44         { }
45         /** Handle command.
46          * @param parameters The parameters to the comamnd
47          * @param pcnt The number of parameters passed to teh command
48          * @param user The user issuing the command
49          * @return A value from CmdResult to indicate command success or failure.
50          */
51         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
52 };
53
54 #endif
55
56
57 /** Handle /LUSERS
58  */
59 CmdResult CommandLusers::Handle (const std::vector<std::string>&, User *user)
60 {
61         unsigned int n_users = ServerInstance->Users->UserCount();
62         unsigned int n_invis = ServerInstance->Users->ModeCount('i');
63         ProtoServerList serverlist;
64         ServerInstance->PI->GetServerList(serverlist);
65         int n_serv = 0;
66         int n_local_servs = 0;
67         for(ProtoServerList::iterator i = serverlist.begin(); i != serverlist.end(); ++i)
68         {
69                 n_serv++;
70                 if (i->parentname == ServerInstance->Config->ServerName)
71                         n_local_servs++;
72         }
73         // fix for default GetServerList not returning us
74         if (!n_serv)
75                 n_serv = 1;
76
77         // these are updated on every connect (or /lusers invocation), which is good enough
78         if (ServerInstance->Users->LocalUserCount() > max_local)
79                 max_local = ServerInstance->Users->LocalUserCount();
80         if (n_users > max_global)
81                 max_global = n_users;
82
83         user->WriteNumeric(251, "%s :There are %d users and %d invisible on %d servers",user->nick.c_str(),
84                         n_users-n_invis, n_invis, n_serv);
85
86         if (ServerInstance->Users->OperCount())
87                 user->WriteNumeric(252, "%s %d :operator(s) online",user->nick.c_str(),ServerInstance->Users->OperCount());
88
89         if (ServerInstance->Users->UnregisteredUserCount())
90                 user->WriteNumeric(253, "%s %d :unknown connections",user->nick.c_str(),ServerInstance->Users->UnregisteredUserCount());
91
92         user->WriteNumeric(254, "%s %ld :channels formed",user->nick.c_str(),ServerInstance->ChannelCount());
93         user->WriteNumeric(255, "%s :I have %d clients and %d servers",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),n_local_servs);
94         user->WriteNumeric(265, "%s :Current Local Users: %d  Max: %d",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),max_local);
95         user->WriteNumeric(266, "%s :Current Global Users: %d  Max: %d",user->nick.c_str(),n_users,max_global);
96
97         return CMD_SUCCESS;
98 }
99
100
101 COMMAND_INIT(CommandLusers)