Permalink
Browse files

Fixed using a function on every call for /motd, causing lag on large …

…networks (requested by w00t)
  • Loading branch information...
1 parent 183fd75 commit a2d85a098e07b4c6de1c7ea9f272eaac10fec7c1 @Justasic committed Apr 22, 2012
Showing with 25 additions and 11 deletions.
  1. +4 −0 include/inspircd.h
  2. +20 −11 src/commands/cmd_motd.cpp
  3. +1 −0 src/commands/cmd_rehash.cpp
View
@@ -444,6 +444,10 @@ class CoreExport InspIRCd
*/
LocalStringExt OperQuit;
+ /** Holds whether the MOTD has been parsed for color codes
+ */
+ bool ProcessedMotdEscapes;
+
/** Get the current time
* Because this only calls time() once every time around the mainloop,
* it is much faster than calling time() directly.
View
@@ -23,7 +23,7 @@ class CommandMotd : public Command
public:
/** Constructor for motd.
*/
- CommandMotd ( Module* parent) : Command(parent,"MOTD",0,1) { syntax = "[<servername>]"; }
+ CommandMotd ( Module* parent) : Command(parent,"MOTD",0,1) { ServerInstance->ProcessedMotdEscapes = false; syntax = "[<servername>]"; }
/** Handle command.
* @param parameters The parameters to the comamnd
* @param pcnt The number of parameters passed to teh command
@@ -57,7 +57,7 @@ inline std::string replace_all(const std::string &str, const std::string &orig,
* can append other chars to replace if you like (such as %U
* being underline). -- Justasic
*/
-std::string ProcessColors(const std::string &string)
+void ProcessColors(ConfigFileCache::iterator &file)
{
static struct special_chars
{
@@ -78,17 +78,20 @@ std::string ProcessColors(const std::string &string)
special_chars("", "")
};
- std::string ret = string;
- for(int i = 0; special[i].character.empty() == false; ++i)
+ for(file_cache::iterator it = file->second.begin(); it != file->second.end(); it++)
{
- std::string::size_type pos = ret.find(special[i].character);
- if(pos != std::string::npos && ret[pos-1] == '\\' && ret[pos] == '\\')
- continue; // Skip double slashes.
+ std::string ret = *it;
+ for(int i = 0; special[i].character.empty() == false; ++i)
+ {
+ std::string::size_type pos = ret.find(special[i].character);
+ if(pos != std::string::npos && ret[pos-1] == '\\' && ret[pos] == '\\')
+ continue; // Skip double slashes.
- ret = replace_all(ret, special[i].character, special[i].replace);
+ ret = replace_all(ret, special[i].character, special[i].replace);
+ }
+ // Replace double slashes with a single slash before we return
+ *it = replace_all(ret, "\\\\", "\\");
}
- // Replace double slashes with a single slash before we return
- return replace_all(ret, "\\\\", "\\");
}
/** Handle /MOTD
@@ -110,11 +113,17 @@ CmdResult CommandMotd::Handle (const std::vector<std::string>& parameters, User
return CMD_SUCCESS;
}
+ if(!ServerInstance->ProcessedMotdEscapes)
+ {
+ ProcessColors(motd);
+ ServerInstance->ProcessedMotdEscapes = true;
+ }
+
user->SendText(":%s %03d %s :%s message of the day", ServerInstance->Config->ServerName.c_str(),
RPL_MOTDSTART, user->nick.c_str(), ServerInstance->Config->ServerName.c_str());
for (file_cache::iterator i = motd->second.begin(); i != motd->second.end(); i++)
- user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_MOTD, user->nick.c_str(), ProcessColors(*i).c_str());
+ user->SendText(":%s %03d %s :- %s", ServerInstance->Config->ServerName.c_str(), RPL_MOTD, user->nick.c_str(), i->c_str());
user->SendText(":%s %03d %s :End of message of the day.", ServerInstance->Config->ServerName.c_str(), RPL_ENDOFMOTD, user->nick.c_str());
@@ -81,6 +81,7 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
* after the config thread has completed.
*/
+ ServerInstance->ProcessedMotdEscapes = false; // Reprocess our motd file --Justasic
ServerInstance->RehashUsersAndChans();
FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());

0 comments on commit a2d85a0

Please sign in to comment.