]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Move {prefix|suffix|fixed}{quit|part} into core_user
authorAttila Molnar <attilamolnar@hush.com>
Fri, 7 Mar 2014 17:03:01 +0000 (18:03 +0100)
committerAttila Molnar <attilamolnar@hush.com>
Fri, 7 Mar 2014 17:03:01 +0000 (18:03 +0100)
include/configreader.h
src/configreader.cpp
src/coremods/core_user/cmd_part.cpp
src/coremods/core_user/cmd_quit.cpp
src/coremods/core_user/core_user.cpp
src/coremods/core_user/core_user.h

index 7f9e4a52dd2bae7d909b568f0d242d7703c7bcf5..fd6452b31bed41f5eb082c061c154dc4d2e06186 100644 (file)
@@ -312,30 +312,6 @@ class CoreExport ServerConfig
         */
        std::string AdminNick;
 
-       /** The quit prefix in use, or an empty string
-        */
-       std::string PrefixQuit;
-
-       /** The quit suffix in use, or an empty string
-        */
-       std::string SuffixQuit;
-
-       /** The fixed quit message in use, or an empty string
-        */
-       std::string FixedQuit;
-
-       /** The part prefix in use, or an empty string
-        */
-       std::string PrefixPart;
-
-       /** The part suffix in use, or an empty string
-        */
-       std::string SuffixPart;
-
-       /** The fixed part message in use, or an empty string
-        */
-       std::string FixedPart;
-
        /** Pretend disabled commands don't exist.
         */
        bool DisabledDontExist;
index f80764048aa4a2f718729e2838b354406effff81..6d5fc9a8759da7c9006a76dd7df6cef14e9a2603 100644 (file)
@@ -366,12 +366,6 @@ void ServerConfig::Fill()
                if (!nsid.empty() && nsid != sid)
                        throw CoreException("You must restart to change the server id");
        }
-       PrefixQuit = options->getString("prefixquit");
-       SuffixQuit = options->getString("suffixquit");
-       FixedQuit = options->getString("fixedquit");
-       PrefixPart = options->getString("prefixpart");
-       SuffixPart = options->getString("suffixpart");
-       FixedPart = options->getString("fixedpart");
        SoftLimit = ConfValue("performance")->getInt("softlimit", SocketEngine::GetMaxFds(), 10, SocketEngine::GetMaxFds());
        CCOnConnect = ConfValue("performance")->getBool("clonesonconnect", true);
        MaxConn = ConfValue("performance")->getInt("somaxconn", SOMAXCONN);
index b8395f43ef43e01b6275a0b7d15e6520d16eeabe..9f82c15a501d5e1641998de5009c616625249c02 100644 (file)
@@ -31,17 +31,11 @@ CommandPart::CommandPart(Module* parent)
 CmdResult CommandPart::Handle (const std::vector<std::string>& parameters, User *user)
 {
        std::string reason;
-
-       if (IS_LOCAL(user))
-       {
-               if (!ServerInstance->Config->FixedPart.empty())
-                       reason = ServerInstance->Config->FixedPart;
-               else if (parameters.size() > 1)
-                       reason = ServerInstance->Config->PrefixPart + parameters[1] + ServerInstance->Config->SuffixPart;
-       }
-       else
+       if (parameters.size() > 1)
        {
-               if (parameters.size() > 1)
+               if (IS_LOCAL(user))
+                       msgwrap.Wrap(parameters[1], reason);
+               else
                        reason = parameters[1];
        }
 
index 40653745ca050cdba7494eaf37ac42a73f58282a..019fde0cf7fe08539eb40b659df027f77412a04d 100644 (file)
@@ -30,20 +30,11 @@ CommandQuit::CommandQuit(Module* parent)
 
 CmdResult CommandQuit::Handle (const std::vector<std::string>& parameters, User *user)
 {
-
        std::string quitmsg;
-
-       if (IS_LOCAL(user))
-       {
-               if (!ServerInstance->Config->FixedQuit.empty())
-                       quitmsg = ServerInstance->Config->FixedQuit;
-               else
-                       quitmsg = parameters.size() ?
-                               ServerInstance->Config->PrefixQuit + parameters[0] + ServerInstance->Config->SuffixQuit
-                               : "Client exited";
-       }
-       else
-               quitmsg = parameters.size() ? parameters[0] : "Client exited";
+       if (parameters.empty())
+               quitmsg = "Client exited";
+       else if (IS_LOCAL(user))
+               msgwrap.Wrap(parameters[0], quitmsg);
 
        std::string* operquit = ServerInstance->OperQuit.get(user);
        ServerInstance->Users->QuitUser(user, quitmsg, operquit);
index c862c0eb1a3b711f3355c86cb52b7c746de3c253..103880a6ecb3a5422070862abbb8535d1fdab5f0 100644 (file)
@@ -136,6 +136,27 @@ class CommandPong : public Command
        }
 };
 
+void MessageWrapper::Wrap(const std::string& message, std::string& out)
+{
+       // If there is a fixed message, it is stored in prefix. Otherwise prefix contains
+       // only the prefix, so append the message and the suffix
+       out.assign(prefix);
+       if (!fixed)
+               out.append(message).append(suffix);
+}
+
+void MessageWrapper::ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname)
+{
+       ConfigTag* tag = ServerInstance->Config->ConfValue("options");
+       prefix = tag->getString(fixedname);
+       fixed = (!prefix.empty());
+       if (!fixed)
+       {
+               prefix = tag->getString(prefixname);
+               suffix = tag->getString(suffixname);
+       }
+}
+
 class CoreModUser : public Module
 {
        CommandAway cmdaway;
@@ -155,6 +176,12 @@ class CoreModUser : public Module
        {
        }
 
+       void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
+       {
+               cmdpart.msgwrap.ReadConfig("prefixpart", "suffixpart", "fixedpart");
+               cmdquit.msgwrap.ReadConfig("prefixquit", "suffixquit", "fixedquit");
+       }
+
        Version GetVersion() CXX11_OVERRIDE
        {
                return Version("Provides the AWAY, MODE, NICK, PART, PASS, PING, PONG, QUIT and USER commands", VF_VENDOR|VF_CORE);
index ad4b739199d16921ababb57932269852df4b10b6..9c63e6592342d61a1280a52c3543cbba16890a7a 100644 (file)
 
 #include "inspircd.h"
 
+class MessageWrapper
+{
+       std::string prefix;
+       std::string suffix;
+       bool fixed;
+
+ public:
+       /**
+        * Wrap the given message according to the config rules
+        * @param message The message to wrap
+        * @param out String where the result is placed
+        */
+       void Wrap(const std::string& message, std::string& out);
+
+       /**
+        * Read the settings from the given config keys (options block)
+        * @param prefixname Name of the config key to read the prefix from
+        * @param suffixname Name of the config key to read the suffix from
+        * @param fixedname Name of the config key to read the fixed string string from.
+        * If this key has a non-empty value, all messages will be replaced with it.
+        */
+       void ReadConfig(const char* prefixname, const char* suffixname, const char* fixedname);
+};
+
 /** Handle /AWAY.
  */
 class CommandAway : public Command
@@ -60,6 +84,8 @@ class CommandNick : public Command
 class CommandPart : public Command
 {
  public:
+       MessageWrapper msgwrap;
+
        /** Constructor for part.
         */
        CommandPart(Module* parent);
@@ -78,6 +104,8 @@ class CommandPart : public Command
 class CommandQuit : public Command
 {
  public:
+       MessageWrapper msgwrap;
+
        /** Constructor for quit.
         */
        CommandQuit(Module* parent);