1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /** Handle /MOTD. 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
21 class CommandMotd : public Command
24 /** Constructor for motd.
26 CommandMotd ( Module* parent) : Command(parent,"MOTD",0,1) { ServerInstance->ProcessedMotdEscapes = false; syntax = "[<servername>]"; }
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.
33 CmdResult Handle(const std::vector<std::string>& parameters, User *user);
34 RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
36 if (parameters.size() > 0)
37 return ROUTE_UNICAST(parameters[0]);
38 return ROUTE_LOCALONLY;
43 * Replace all color codes from the special[] array to actual
44 * color code chars using C++ style escape sequences. You
45 * can append other chars to replace if you like (such as %U
46 * being underline). -- Justasic
48 void ProcessColors(ConfigFileCache::iterator &file)
50 static struct special_chars
52 std::string character;
54 special_chars(const std::string &c, const std::string &r) : character(c), replace(r) { }
58 special_chars("\\002", "\002"), // Bold
59 special_chars("\\037", "\037"), // underline
60 special_chars("\\003", "\003"), // Color
61 special_chars("\\0017", "\017"), // Stop colors
62 special_chars("\\u", "\037"), // Alias for underline
63 special_chars("\\b", "\002"), // Alias for Bold
64 special_chars("\\x", "\017"), // Alias for stop
65 special_chars("\\c", "\003"), // Alias for color
69 for(file_cache::iterator it = file->second.begin(); it != file->second.end(); it++)
71 std::string ret = *it;
72 for(int i = 0; special[i].character.empty() == false; ++i)
74 std::string::size_type pos = ret.find(special[i].character);
75 if(pos != std::string::npos && ret[pos-1] == '\\' && ret[pos] == '\\')
76 continue; // Skip double slashes.
78 // Replace all our characters in the array
79 while(pos != std::string::npos)
81 ret = ret.substr(0, pos) + special[i].replace + ret.substr(pos + special[i].character.size());
82 pos = ret.find(special[i].character, pos + special[i].replace.size());
86 // Replace double slashes with a single slash before we return
87 std::string::size_type pos = ret.find("\\\\");
88 while(pos != std::string::npos)
90 ret = ret.substr(0, pos) + "\\" + ret.substr(pos + 2);
91 pos = ret.find("\\\\", pos + 1);
99 CmdResult CommandMotd::Handle (const std::vector<std::string>& parameters, User *user)
101 if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName)
104 ConfigTag* tag = NULL;
106 tag = user->GetClass()->config;
107 std::string motd_name = tag->getString("motd", "motd");
108 ConfigFileCache::iterator motd = ServerInstance->Config->Files.find(motd_name);
109 if (motd == ServerInstance->Config->Files.end())
111 user->SendText(":%s %03d %s :Message of the day file is missing.",
112 ServerInstance->Config->ServerName.c_str(), ERR_NOMOTD, user->nick.c_str());
116 if(!ServerInstance->ProcessedMotdEscapes)
119 ServerInstance->ProcessedMotdEscapes = true;
122 user->SendText(":%s %03d %s :%s message of the day", ServerInstance->Config->ServerName.c_str(),
123 RPL_MOTDSTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str());
125 for (file_cache::iterator i = motd->second.begin(); i != motd->second.end(); i++)
126 user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_MOTD, user->nick.c_str(), i->c_str());
128 user->SendText(":%s %03d %s :End of message of the day.", ServerInstance->Config->ServerName.c_str(), RPL_ENDOFMOTD, user->nick.c_str());
133 COMMAND_INIT(CommandMotd)