]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_lusers.cpp
Fixes for bug #12
[user/henk/code/inspircd.git] / src / commands / cmd_lusers.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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
14 #include "inspircd.h"
15
16 #ifndef CMD_LUSERS_H
17 #define CMD_LUSERS_H
18
19 // include the common header files
20
21 #include "users.h"
22 #include "channels.h"
23
24 /** Handle /LUSERS. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandLusers : public Command
30 {
31         unsigned int max_local, max_global;
32  public:
33         /** Constructor for lusers.
34          */
35         CommandLusers ( Module* parent) : Command(parent,"LUSERS",0,0),
36                 max_local(0), max_global(0)
37         { }
38         /** Handle command.
39          * @param parameters The parameters to the comamnd
40          * @param pcnt The number of parameters passed to teh command
41          * @param user The user issuing the command
42          * @return A value from CmdResult to indicate command success or failure.
43          */
44         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
45 };
46
47 #endif
48
49
50 /** Handle /LUSERS
51  */
52 CmdResult CommandLusers::Handle (const std::vector<std::string>&, User *user)
53 {
54         unsigned int n_users = ServerInstance->Users->UserCount();
55         unsigned int n_invis = ServerInstance->Users->ModeCount('i');
56         ProtoServerList serverlist;
57         ServerInstance->PI->GetServerList(serverlist);
58         int n_serv = 0;
59         int n_local_servs = 0;
60         for(ProtoServerList::iterator i = serverlist.begin(); i != serverlist.end(); ++i)
61         {
62                 n_serv++;
63                 if (i->parentname == ServerInstance->Config->ServerName)
64                         n_local_servs++;
65         }
66         // fix for default GetServerList not returning us
67         if (!n_serv)
68                 n_serv = 1;
69
70         // these are updated on every connect (or /lusers invocation), which is good enough
71         if (ServerInstance->Users->LocalUserCount() > max_local)
72                 max_local = ServerInstance->Users->LocalUserCount();
73         if (n_users > max_global)
74                 max_global = n_users;
75
76         user->WriteNumeric(251, "%s :There are %d users and %d invisible on %d servers",user->nick.c_str(),
77                         n_users-n_invis, n_invis, n_serv);
78
79         if (ServerInstance->Users->OperCount())
80                 user->WriteNumeric(252, "%s %d :operator(s) online",user->nick.c_str(),ServerInstance->Users->OperCount());
81
82         if (ServerInstance->Users->UnregisteredUserCount())
83                 user->WriteNumeric(253, "%s %d :unknown connections",user->nick.c_str(),ServerInstance->Users->UnregisteredUserCount());
84
85         user->WriteNumeric(254, "%s %ld :channels formed",user->nick.c_str(),ServerInstance->ChannelCount());
86         user->WriteNumeric(255, "%s :I have %d clients and %d servers",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),n_local_servs);
87         user->WriteNumeric(265, "%s :Current Local Users: %d  Max: %d",user->nick.c_str(),ServerInstance->Users->LocalUserCount(),max_local);
88         user->WriteNumeric(266, "%s :Current Global Users: %d  Max: %d",user->nick.c_str(),n_users,max_global);
89
90         return CMD_SUCCESS;
91 }
92
93
94 COMMAND_INIT(CommandLusers)