From fc450cb4867639cb1ba049187a6b24569d9aa28b Mon Sep 17 00:00:00 2001 From: Cizzle Date: Wed, 22 Feb 2017 16:25:08 +0100 Subject: [PATCH] Don't use the same or overlapping NickPrefix as StatusPrefix in the crypt module Don't use a key which is a valid nickname, now changed to "@nick-prefix@" instead. If you had loaded the crypt module before, the old settings will be converted. Also check if the nick-prefix and status-prefix aren't the same or overlapping, "*" or "." are then used depending on either value. If they would be the same, you would be messaging a module instead of a user. And if they'd overlap, depending on the nick, you could be messaging a module as well. --- modules/crypt.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/modules/crypt.cpp b/modules/crypt.cpp index d134ae3f..c41e57c8 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -45,12 +45,26 @@ #include #define REQUIRESSL 1 -#define NICK_PREFIX_KEY "[nick-prefix]" +// To be removed in future versions +#define NICK_PREFIX_OLD_KEY "[nick-prefix]" +#define NICK_PREFIX_KEY "@nick-prefix@" class CCryptMod : public CModule { CString NickPrefix() { MCString::iterator it = FindNV(NICK_PREFIX_KEY); - return it != EndNV() ? it->second : "*"; + /* + * Check for different Prefixes to not confuse modules with nicknames + * Also check for overlap for rare cases like: + * SP = "*"; NP = "*s"; "tatus" sends an encrypted message appearing at "*status" + */ + CString sStatusPrefix = GetUser()->GetStatusPrefix(); + if (it != EndNV()) { + size_t sp = sStatusPrefix.size(); + size_t np = it->second.size(); + if (sStatusPrefix.CaseCmp(it->second, std::min(sp, np)) != 0) + return it->second; + } + return sStatusPrefix.StartsWith("*") ? "." : "*"; } public: @@ -69,6 +83,19 @@ class CCryptMod : public CModule { ~CCryptMod() override {} + bool OnLoad(const CString& sArgsi, CString& sMessage) override { + MCString::iterator it = FindNV(NICK_PREFIX_KEY); + if (it == EndNV()) { + /* Don't have the new prefix key yet */ + it = FindNV(NICK_PREFIX_OLD_KEY); + if (it != EndNV()) { + SetNV(NICK_PREFIX_KEY, it->second); + DelNV(NICK_PREFIX_OLD_KEY); + } + } + return true; + } + EModRet OnUserMsg(CString& sTarget, CString& sMessage) override { sTarget.TrimPrefix(NickPrefix());