From 4d35bd482e721d1047df6678524ac7622fa64c5c Mon Sep 17 00:00:00 2001 From: psychon Date: Sat, 26 Sep 2009 18:41:24 +0000 Subject: [PATCH] delserver: Allow selecting the server more exactly Before this you could only give the hostname of a server and delserver would delete the first server with that hostname. Now you can also specify port and password to select the server to remove more exactly. One can't specify the ssl flag for delserver since this would be a little ugly, but since you can't do ssl/plain-text on the same port anyway this shouldn't be a big problem. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1640 726aef4b-f618-498e-8847-2d620e286838 --- ClientCommand.cpp | 6 ++++-- User.cpp | 43 +++++++++++++++++++++++++------------------ User.h | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/ClientCommand.cpp b/ClientCommand.cpp index 99050807..9a422365 100644 --- a/ClientCommand.cpp +++ b/ClientCommand.cpp @@ -329,9 +329,11 @@ void CClient::UserCommand(CString& sLine) { } } else if (sCommand.Equals("REMSERVER") || sCommand.Equals("DELSERVER")) { CString sServer = sLine.Token(1); + unsigned short uPort = sLine.Token(2).ToUShort(); + CString sPass = sLine.Token(3); if (sServer.empty()) { - PutStatus("Usage: RemServer "); + PutStatus("Usage: RemServer [port] [pass]"); return; } @@ -340,7 +342,7 @@ void CClient::UserCommand(CString& sLine) { return; } - if (m_pUser->DelServer(sServer)) { + if (m_pUser->DelServer(sServer, uPort, sPass)) { PutStatus("Server removed"); } else { PutStatus("No such server"); diff --git a/User.cpp b/User.cpp index 0c214922..1b51e4ab 100644 --- a/User.cpp +++ b/User.cpp @@ -752,7 +752,7 @@ CServer* CUser::FindServer(const CString& sName) const { return NULL; } -bool CUser::DelServer(const CString& sName) { +bool CUser::DelServer(const CString& sName, unsigned short uPort, const CString& sPass) { if (sName.empty()) { return false; } @@ -762,29 +762,36 @@ bool CUser::DelServer(const CString& sName) { for (vector::iterator it = m_vServers.begin(); it != m_vServers.end(); it++, a++) { CServer* pServer = *it; - if (pServer->GetName().Equals(sName)) { - CServer* pCurServer = GetCurrentServer(); - m_vServers.erase(it); + if (!pServer->GetName().Equals(sName)) + continue; - if (pServer == pCurServer) { - CIRCSock* pIRCSock = GetIRCSock(); + if (uPort != 0 && pServer->GetPort() != uPort) + continue; - if (m_uServerIdx) { - m_uServerIdx--; - } + if (!sPass.empty() && pServer->GetPass() != sPass) + continue; - if (pIRCSock) { - pIRCSock->Quit(); - PutStatus("Your current server was removed, jumping..."); - } - } else if (m_uServerIdx >= m_vServers.size()) { - m_uServerIdx = 0; + CServer* pCurServer = GetCurrentServer(); + m_vServers.erase(it); + + if (pServer == pCurServer) { + CIRCSock* pIRCSock = GetIRCSock(); + + if (m_uServerIdx) { + m_uServerIdx--; } - delete pServer; - - return true; + if (pIRCSock) { + pIRCSock->Quit(); + PutStatus("Your current server was removed, jumping..."); + } + } else if (m_uServerIdx >= m_vServers.size()) { + m_uServerIdx = 0; } + + delete pServer; + + return true; } return false; diff --git a/User.h b/User.h index 9ce36da4..c3e692db 100644 --- a/User.h +++ b/User.h @@ -57,7 +57,7 @@ public: void JoinChans(); bool JoinChan(CChan* pChan); CServer* FindServer(const CString& sName) const; - bool DelServer(const CString& sName); + bool DelServer(const CString& sName, unsigned short uPort, const CString& sPass); bool AddServer(const CString& sName); bool AddServer(const CString& sName, unsigned short uPort, const CString& sPass = "", bool bSSL = false); CServer* GetNextServer();