From e13fdf2a545c65b8db340338fa3a4d514ab5a4b8 Mon Sep 17 00:00:00 2001 From: Allan Odgaard Date: Wed, 20 Mar 2013 17:20:20 +0100 Subject: [PATCH] crypt: Use ASCII for nick prefix and make it configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previously hardcoded value of ‘\244’ is causing problems for clients which expect valid UTF-8 from the server/bouncer. This commit fixes #228. The prefix is stored using a key of ‘[nick-prefix]’ in the general key/value store for the crypt module, which previously was only used for encryption keys. This is not the best design, but the least intrusive one. --- modules/crypt.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/crypt.cpp b/modules/crypt.cpp index ec1faa2a..614203ee 100644 --- a/modules/crypt.cpp +++ b/modules/crypt.cpp @@ -27,14 +27,20 @@ #include #define REQUIRESSL 1 +#define NICK_PREFIX_KEY "[nick-prefix]" class CCryptMod : public CModule { + CString NickPrefix() { + MCString::iterator it = FindNV(NICK_PREFIX_KEY); + return it != EndNV() ? it->second : "*"; + } + public: MODCONSTRUCTOR(CCryptMod) {} virtual ~CCryptMod() {} virtual EModRet OnUserMsg(CString& sTarget, CString& sMessage) { - sTarget.TrimLeft("\244"); + sTarget.TrimLeft(NickPrefix()); if (sMessage.Left(2) == "``") { sMessage.LeftChomp(2); @@ -47,8 +53,8 @@ public: CChan* pChan = m_pNetwork->FindChan(sTarget); if (pChan) { if (!pChan->AutoClearChanBuffer()) - pChan->AddBuffer(":\244" + _NAMEDFMT(m_pNetwork->GetIRCNick().GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sTarget) + " :{text}", sMessage); - m_pUser->PutUser(":\244" + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient); + pChan->AddBuffer(":" + NickPrefix() + _NAMEDFMT(m_pNetwork->GetIRCNick().GetNickMask()) + " PRIVMSG " + _NAMEDFMT(sTarget) + " :{text}", sMessage); + m_pUser->PutUser(":" + NickPrefix() + m_pNetwork->GetIRCNick().GetNickMask() + " PRIVMSG " + sTarget + " :" + sMessage, NULL, m_pClient); } CString sMsg = MakeIvec() + sMessage; @@ -83,7 +89,7 @@ public: sMessage.Decrypt(it->second); sMessage.LeftChomp(8); sMessage = sMessage.c_str(); - Nick.SetNick("\244" + Nick.GetNick()); + Nick.SetNick(NickPrefix() + Nick.GetNick()); } } @@ -131,6 +137,13 @@ public: Table.SetCell("Key", it->second); } + MCString::iterator it = FindNV(NICK_PREFIX_KEY); + if (it == EndNV()) { + Table.AddRow(); + Table.SetCell("Target", NICK_PREFIX_KEY); + Table.SetCell("Key", NickPrefix()); + } + PutModule(Table); } } else if (sCmd.Equals("HELP")) {