Skip to content
Browse files

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.
  • Loading branch information...
1 parent faf1dd9 commit e13fdf2a545c65b8db340338fa3a4d514ab5a4b8 @sorbits sorbits committed Mar 20, 2013
Showing with 17 additions and 4 deletions.
  1. +17 −4 modules/crypt.cpp
View
21 modules/crypt.cpp
@@ -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 @@ class CCryptMod : public CModule {
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 @@ class CCryptMod : public CModule {
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 @@ class CCryptMod : public CModule {
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")) {

0 comments on commit e13fdf2

Please sign in to comment.
Something went wrong with that request. Please try again.