From cad1ee5367c4a77e3c078cd776269b4516d79bfe Mon Sep 17 00:00:00 2001 From: psychon Date: Thu, 18 Sep 2008 19:58:53 +0000 Subject: [PATCH] Keepnick: Dont forward nick change errors which we generated ourselves This blocks 433 replies from the irc server if the keepnick module tries to change our nick. This way the user isn't flooded with those errors. Oh and the actual logic is a little more complicated than this... This patch is inspired and implemented by SilverLeo. Thanks :) git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1209 726aef4b-f618-498e-8847-2d620e286838 --- modules/keepnick.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/modules/keepnick.cpp b/modules/keepnick.cpp index 264f0fde..d04fd6e0 100644 --- a/modules/keepnick.cpp +++ b/modules/keepnick.cpp @@ -124,6 +124,41 @@ public: m_pTimer = NULL; } + virtual EModRet OnUserRaw(CString& sLine) { + // We dont care if we are not connected to IRC + if (!m_pUser->IsIRCConnected()) + return CONTINUE; + + // We are trying to get the config nick and this is a /nick? + if (!m_pTimer || sLine.Token(0).CaseCmp("NICK") != 0) + return CONTINUE; + + // Is the nick change for the nick we are trying to get? + CString sNick = sLine.Token(1); + + // Don't even think of using spaces in your nick! + if (sNick.Left(1) == ":") + sNick.LeftChomp(); + + if (sNick.CaseCmp(GetNick()) != 0) + return CONTINUE; + + // Indeed trying to change to this nick, generate a 433 for it. + // This way we can *always* block incoming 433s from the server. + PutUser(":" + m_pUser->GetIRCServer() + " 433 " + m_pUser->GetIRCNick().GetNick() + + " " + sNick + " :ZNC is already trying to get this nickname"); + return CONTINUE; + } + + virtual EModRet OnRaw(CString& sLine) { + // Are we trying to get our primary nick and we caused this error? + // :irc.server.net 433 mynick badnick :Nickname is already in use. + if (m_pTimer && sLine.Token(1) == "433" && sLine.Token(3).CaseCmp(GetNick()) == 0) + return HALT; + + return CONTINUE; + } + void OnModCommand(const CString& sCommand) { CString sCmd = sCommand.AsUpper();