]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_rules.cpp
Also allow <connect rules>
[user/henk/code/inspircd.git] / src / commands / cmd_rules.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 /** Handle /RULES. These command handlers can be reloaded by the core,
17  * and handle basic RFC1459 commands. Commands within modules work
18  * the same way, however, they can be fully unloaded, where these
19  * may not.
20  */
21 class CommandRules : public Command
22 {
23  public:
24         /** Constructor for rules.
25          */
26         CommandRules ( Module* parent) : Command(parent,"RULES",0,0) { syntax = "[<servername>]"; }
27         /** Handle command.
28          * @param parameters The parameters to the comamnd
29          * @param pcnt The number of parameters passed to teh command
30          * @param user The user issuing the command
31          * @return A value from CmdResult to indicate command success or failure.
32          */
33         CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34         RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
35         {
36                 if (parameters.size() > 0)
37                         return ROUTE_UNICAST(parameters[0]);
38                 return ROUTE_LOCALONLY;
39         }
40 };
41
42 CmdResult CommandRules::Handle (const std::vector<std::string>& parameters, User *user)
43 {
44         if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
45                 return CMD_SUCCESS;
46
47         ConfigTag* tag = NULL;
48         if (IS_LOCAL(user))
49                 tag = user->GetClass()->config;
50         std::string rules_name = tag->getString("rules", "rules");
51         ConfigFileCache::iterator rules = ServerInstance->Config->Files.find(rules_name);
52         if (rules == ServerInstance->Config->Files.end())
53         {
54                 user->SendText(":%s %03d %s :RULES file is missing.",
55                         ServerInstance->Config->ServerName.c_str(), ERR_NORULES, user->nick.c_str());
56                 return CMD_SUCCESS;
57         }
58         user->SendText(":%s %03d %s :%s server rules:", ServerInstance->Config->ServerName.c_str(),
59                 RPL_RULESTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str());
60
61         for (file_cache::iterator i = rules->second.begin(); i != rules->second.end(); i++)
62                 user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_RULES, user->nick.c_str(),i->c_str());
63
64         user->SendText(":%s %03d %s :End of RULES command.", ServerInstance->Config->ServerName.c_str(), RPL_RULESEND, user->nick.c_str());
65
66         return CMD_SUCCESS;
67 }
68
69 COMMAND_INIT(CommandRules)