mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge pull request #7237 from Robyt3/Server-AuthKey-Removal-Fixes
Correctly update auth keys when using `auth_remove`
This commit is contained in:
commit
ab7fefe7bd
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue