crypt: Use ASCII for nick prefix and make it configurable

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.
This commit is contained in:
Allan Odgaard
2013-03-20 17:20:20 +01:00
parent faf1dd9b7e
commit e13fdf2a54

View File

@@ -27,14 +27,20 @@
#include <znc/IRCNetwork.h>
#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")) {