diff --git a/src/engine/server/authmanager.cpp b/src/engine/server/authmanager.cpp index 62b7be582..6014af70f 100644 --- a/src/engine/server/authmanager.cpp +++ b/src/engine/server/authmanager.cpp @@ -65,21 +65,21 @@ int CAuthManager::AddKey(const char *pIdent, const char *pPw, int AuthLevel) return AddKeyHash(pIdent, HashPassword(pPw, aSalt), aSalt, AuthLevel); } -int CAuthManager::RemoveKey(int Slot) +void CAuthManager::RemoveKey(int Slot) { m_vKeys.erase(m_vKeys.begin() + Slot); + // Update indices of default keys for(int &Default : m_aDefault) { if(Default == Slot) { Default = -1; } - else if(Default == (int)m_vKeys.size()) + else if(Default > Slot) { - Default = Slot; + --Default; } } - return m_vKeys.size(); } int CAuthManager::FindKey(const char *pIdent) const diff --git a/src/engine/server/authmanager.h b/src/engine/server/authmanager.h index feea4ac4f..9845100e8 100644 --- a/src/engine/server/authmanager.h +++ b/src/engine/server/authmanager.h @@ -30,7 +30,7 @@ public: void Init(); int AddKeyHash(const char *pIdent, MD5_DIGEST Hash, const unsigned char *pSalt, int AuthLevel); int AddKey(const char *pIdent, const char *pPw, int AuthLevel); - int RemoveKey(int Slot); // Returns the old key slot that is now in the named one. + void RemoveKey(int Slot); int FindKey(const char *pIdent) const; bool CheckKey(int Slot, const char *pPw) const; int DefaultKey(int AuthLevel) const; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index aeff8a1ab..77223869b 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -3107,16 +3107,20 @@ static int GetAuthLevel(const char *pLevel) void CServer::AuthRemoveKey(int KeySlot) { - int NewKeySlot = KeySlot; - int OldKeySlot = m_AuthManager.RemoveKey(KeySlot); + m_AuthManager.RemoveKey(KeySlot); LogoutKey(KeySlot, "key removal"); // Update indices. - if(OldKeySlot != NewKeySlot) + for(auto &Client : m_aClients) { - for(auto &Client : m_aClients) - if(Client.m_AuthKey == OldKeySlot) - Client.m_AuthKey = NewKeySlot; + if(Client.m_AuthKey == KeySlot) + { + Client.m_AuthKey = -1; + } + else if(Client.m_AuthKey > KeySlot) + { + --Client.m_AuthKey; + } } }