diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-03-07 18:03:01 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-03-07 18:03:01 +0100 |
commit | 7f4a2cc351efa9c6b50ef15c5772c54cbaef4e75 (patch) | |
tree | 91398b69c0cf04ade6b957c2113aa8c5b95a8bc9 /src/coremods | |
parent | 07f817fd47e2c5f7ca97ab73cef32307d84a6e79 (diff) |
Move {prefix|suffix|fixed}{quit|part} into core_user
Diffstat (limited to 'src/coremods')
-rw-r--r-- | src/coremods/core_user/cmd_part.cpp | 14 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_quit.cpp | 17 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.cpp | 27 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.h | 28 |
4 files changed, 63 insertions, 23 deletions
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); |