Improve the AltNick handling

Thanks to ViciousPotato for reporting that AltNicks were truncated to 9
characters.

We assumed the server's maximum nick length to be 9 by default which made the
code truncate the AltNick to 9 characters.

Now we save the nick we sent last to the IRC server. If the server reports a
"nick is already in use" with a nick shorter than we sent it, we assume this
that the server truncated our nick to the allowed length and use this length for
our retries (appending different characters to the default nick).

Not all irc servers truncate the nick this way if it's too long, on those that
don't this patch shouldn't cause any behavior change.


git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1620 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
psychon
2009-09-09 10:15:36 +00:00
parent 868e5343c2
commit 0104d3c5dc
+30 -16
View File
@@ -816,6 +816,9 @@ void CIRCSock::Connected() {
PutIRC("NICK " + sNick);
PutIRC("USER " + sIdent + " \"" + sIdent + "\" \"" + sIdent + "\" :" + sRealName);
// SendAltNick() needs this
m_Nick.SetNick(sNick);
}
void CIRCSock::Disconnected() {
@@ -1002,24 +1005,34 @@ void CIRCSock::ForwardRaw353(const CString& sLine) const {
}
void CIRCSock::SendAltNick(const CString& sBadNick) {
const unsigned int uMax = GetMaxNickLen();
const CString& sConfNick = m_pUser->GetNick().Left(uMax);
const CString& sAltNick = m_pUser->GetAltNick().Left(uMax);
const CString& sLastNick = m_Nick.GetNick();
if (sBadNick.Equals(sConfNick)) {
// We don't know the maximum allowed nick length yet, but we know which
// nick we sent last. If sBadNick is shorter than that, we assume the
// server truncated our nick.
if (sBadNick.length() < sLastNick.length())
m_uMaxNickLen = sBadNick.length();
unsigned int uMax = m_uMaxNickLen;
const CString& sConfNick = m_pUser->GetNick();
const CString& sAltNick = m_pUser->GetAltNick();
CString sNewNick;
if (sLastNick.Equals(sConfNick)) {
if ((!sAltNick.empty()) && (!sConfNick.Equals(sAltNick))) {
PutIRC("NICK " + sAltNick);
sNewNick = sAltNick;
} else {
PutIRC("NICK " + sConfNick.Left(uMax -1) + "-");
sNewNick = sConfNick.Left(uMax - 1) + "-";
}
} else if (sBadNick.Equals(sAltNick)) {
PutIRC("NICK " + sConfNick.Left(uMax -1) + "-");
} else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "-"))) {
PutIRC("NICK " + sConfNick.Left(uMax -1) + "|");
} else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "|"))) {
PutIRC("NICK " + sConfNick.Left(uMax -1) + "^");
} else if (sBadNick.Equals(CString(sConfNick.Left(uMax -1) + "^"))) {
PutIRC("NICK " + sConfNick.Left(uMax -1) + "a");
} else if (sLastNick.Equals(sAltNick)) {
sNewNick = sConfNick.Left(uMax -1) + "-";
} else if (sLastNick.Equals(CString(sConfNick.Left(uMax -1) + "-"))) {
sNewNick = sConfNick.Left(uMax -1) + "|";
} else if (sLastNick.Equals(CString(sConfNick.Left(uMax -1) + "|"))) {
sNewNick = sConfNick.Left(uMax -1) + "^";
} else if (sLastNick.Equals(CString(sConfNick.Left(uMax -1) + "^"))) {
sNewNick = sConfNick.Left(uMax -1) + "a";
} else {
char cLetter = 0;
if (sBadNick.empty()) {
@@ -1036,9 +1049,10 @@ void CIRCSock::SendAltNick(const CString& sBadNick) {
return;
}
CString sSend = "NICK " + sConfNick.Left(uMax -1) + ++cLetter;
PutIRC(sSend);
sNewNick = sConfNick.Left(uMax -1) + ++cLetter;
}
PutIRC("NICK " + sNewNick);
m_Nick.SetNick(sNewNick);
}
unsigned char CIRCSock::GetPermFromMode(unsigned char uMode) const {