From eec57eb81ee6c58c4d90f0bebafb51cb6f853258 Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 14 Nov 2009 12:03:03 +0000 Subject: [PATCH] Bug fix for CUser::DelServer() DelServer() didn't always update m_uServerIdx correctly which means GetCurServer() started to return the wrong server. This should now be fixed. This log shows the bug. ZNC starts to think it's connected to irc.efnet.nl: listservers <*status> +-------------------+------+-----+------+ <*status> | Host | Port | SSL | Pass | <*status> +-------------------+------+-----+------+ <*status> | irc.efnet.pl | 6667 | | | <*status> | irc.spotchat.org* | 6667 | | | <*status> | irc.efnet.nl | 6667 | | | <*status> | irc.freenode.org | 6667 | | | <*status> +-------------------+------+-----+------+ delserver irc.efnet.pl <*status> Server removed listservers <*status> +------------------+------+-----+------+ <*status> | Host | Port | SSL | Pass | <*status> +------------------+------+-----+------+ <*status> | irc.spotchat.org | 6667 | | | <*status> | irc.efnet.nl* | 6667 | | | <*status> | irc.freenode.org | 6667 | | | <*status> +------------------+------+-----+------+ Thanks to tomaw for reporting this bug. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1659 726aef4b-f618-498e-8847-2d620e286838 --- User.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/User.cpp b/User.cpp index 7af817bd..a9bcf2cc 100644 --- a/User.cpp +++ b/User.cpp @@ -768,10 +768,15 @@ bool CUser::DelServer(const CString& sName, unsigned short uPort, const CString& } unsigned int a = 0; + bool bSawCurrentServer = false; + CServer* pCurServer = GetCurrentServer(); for (vector::iterator it = m_vServers.begin(); it != m_vServers.end(); it++, a++) { CServer* pServer = *it; + if (pServer == pCurServer) + bSawCurrentServer = true; + if (!pServer->GetName().Equals(sName)) continue; @@ -781,12 +786,12 @@ bool CUser::DelServer(const CString& sName, unsigned short uPort, const CString& if (!sPass.empty() && pServer->GetPass() != sPass) continue; - CServer* pCurServer = GetCurrentServer(); m_vServers.erase(it); if (pServer == pCurServer) { CIRCSock* pIRCSock = GetIRCSock(); + // Make sure we don't skip the next server in the list! if (m_uServerIdx) { m_uServerIdx--; } @@ -795,8 +800,11 @@ bool CUser::DelServer(const CString& sName, unsigned short uPort, const CString& pIRCSock->Quit(); PutStatus("Your current server was removed, jumping..."); } - } else if (m_uServerIdx >= m_vServers.size()) { - m_uServerIdx = 0; + } else if (!bSawCurrentServer) { + // Our current server comes after the server which we + // are removing. This means that it now got a different + // index in m_vServers! + m_uServerIdx--; } delete pServer;