From baab007f2be0d073ed0ba9c43b5007a399d08672 Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 20 Dec 2008 19:59:36 +0000 Subject: [PATCH] Allow adding a server multiple times if a different port or pass is used This also moves the check for multiple servers from CClient to CUser::AddServer(). The idea for this is from cnu, thanks. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1295 726aef4b-f618-498e-8847-2d620e286838 --- ClientCommand.cpp | 6 +----- User.cpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ClientCommand.cpp b/ClientCommand.cpp index 621600cb..7d71c3cc 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -321,15 +321,11 @@ void CClient::UserCommand(const CString& sLine) { return; } - if (m_pUser->FindServer(sServer)) { - PutStatus("That server already exists"); - return; - } - if (m_pUser->AddServer(sLine.Token(1, true))) { PutStatus("Server added"); } else { PutStatus("Unable to add that server"); + PutStatus("Perhaps the server is already added or openssl is disabled?"); } } else if (sCommand.Equals("REMSERVER") || sCommand.Equals("DELSERVER")) { CString sServer = sLine.Token(1); diff --git a/User.cpp b/User.cpp index 7e0420d9..737f55c8 100644 --- a/User.cpp +++ b/User.cpp @@ -768,6 +768,29 @@ bool CUser::AddServer(const CString& sName, unsigned short uPort, const CString& uPort = 6667; } + // Check if server is already added + for (unsigned int a = 0; a < m_vServers.size(); a++) { + CServer* pServer = m_vServers[a]; + + if (!sName.Equals(pServer->GetName())) + continue; + + if (uPort != pServer->GetPort()) + continue; + + if (sPass != pServer->GetPass()) + continue; + + if (bSSL != pServer->IsSSL()) + continue; + + if (bIPV6 != pServer->IsIPV6()) + continue; + + // Server is already added + return false; + } + CServer* pServer = new CServer(sName, uPort, sPass, bSSL); m_vServers.push_back(pServer);