]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_stats.cpp
Replace copyright headers with headers granting specific authors copyright
[user/henk/code/inspircd.git] / src / commands / cmd_stats.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
5  *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
6  *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
7  *
8  * This file is part of InspIRCd.  InspIRCd is free software: you can
9  * redistribute it and/or modify it under the terms of the GNU General Public
10  * License as published by the Free Software Foundation, version 2.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
15  * details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21
22 #include "inspircd.h"
23 #ifndef WIN32
24         #include <sys/resource.h>
25         /* This is just to be completely certain that the change which fixed getrusage on RH7 doesn't break anything else -- Om */
26         #ifndef RUSAGE_SELF
27         #define RUSAGE_SELF 0
28         #endif
29 #else
30         #include <psapi.h>
31         #include "inspircd_win32wrapper.h"
32         #pragma comment(lib, "psapi.lib")
33 #endif
34
35 #include "xline.h"
36
37 /** Handle /STATS. These command handlers can be reloaded by the core,
38  * and handle basic RFC1459 commands. Commands within modules work
39  * the same way, however, they can be fully unloaded, where these
40  * may not.
41  */
42 class CommandStats : public Command
43 {
44  public:
45         /** Constructor for stats.
46          */
47         CommandStats ( Module* parent) : Command(parent,"STATS",1,2) { syntax = "<stats-symbol> [<servername>]"; }
48         /** Handle command.
49          * @param parameters The parameters to the comamnd
50          * @param pcnt The number of parameters passed to teh command
51          * @param user The user issuing the command
52          * @return A value from CmdResult to indicate command success or failure.
53          */
54         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
55         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
56         {
57                 if (parameters.size() > 1)
58                         return ROUTE_UNICAST(parameters[1]);
59                 return ROUTE_LOCALONLY;
60         }
61 };
62
63 CmdResult CommandStats::Handle (const std::vector<std::string>& parameters, User *user)
64 {
65         if (parameters.size() > 1 && parameters[1] != ServerInstance->Config->ServerName)
66                 return CMD_SUCCESS;
67         string_list values;
68         char search = parameters[0][0];
69         ServerInstance->DoStats(search, user, values);
70         for (size_t i = 0; i < values.size(); i++)
71                 user->SendText(":%s", values[i].c_str());
72
73         return CMD_SUCCESS;
74 }
75
76 COMMAND_INIT(CommandStats)