summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2014-03-07 18:03:01 +0100
committerAttila Molnar <attilamolnar@hush.com>2014-03-07 18:03:01 +0100
commit7f4a2cc351efa9c6b50ef15c5772c54cbaef4e75 (patch)
tree91398b69c0cf04ade6b957c2113aa8c5b95a8bc9
parent07f817fd47e2c5f7ca97ab73cef32307d84a6e79 (diff)
Move {prefix|suffix|fixed}{quit|part} into core_user
-rw-r--r--include/configreader.h24
-rw-r--r--src/configreader.cpp6
-rw-r--r--src/coremods/core_user/cmd_part.cpp14
-rw-r--r--src/coremods/core_user/cmd_quit.cpp17
-rw-r--r--src/coremods/core_user/core_user.cpp27
-rw-r--r--src/coremods/core_user/core_user.h28
6 files changed, 63 insertions, 53 deletions
diff --git a/include/configreader.h b/include/configreader.h
index 7f9e4a52d..fd6452b31 100644
--- a/include/configreader.h
+++ b/include/configreader.h
@@ -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;
diff --git a/src/configreader.cpp b/src/configreader.cpp
index f80764048..6d5fc9a87 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -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);
diff --git a/src/coremods/core_user/cmd_part.cpp b/src/coremods/core_user/cmd_part.cpp
index b8395f43e..9f82c15a5 100644
--- a/src/coremods/core_user/cmd_part.cpp
+++ b/src/coremods/core_user/cmd_part.cpp
@@ -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];
}
diff --git a/src/coremods/core_user/cmd_quit.cpp b/src/coremods/core_user/cmd_quit.cpp
index 40653745c..019fde0cf 100644
--- a/src/coremods/core_user/cmd_quit.cpp
+++ b/src/coremods/core_user/cmd_quit.cpp
@@ -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);
diff --git a/src/coremods/core_user/core_user.cpp b/src/coremods/core_user/core_user.cpp
index c862c0eb1..103880a6e 100644
--- a/src/coremods/core_user/core_user.cpp
+++ b/src/coremods/core_user/core_user.cpp
@@ -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);
diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h
index ad4b73919..9c63e6592 100644
--- a/src/coremods/core_user/core_user.h
+++ b/src/coremods/core_user/core_user.h
@@ -21,6 +21,30 @@
#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);