core/AdminCache.cpp
changeset 458 77520125ee67
parent 438 e6e11c82d87e
child 464 765517f654a5
     1.1 --- a/core/AdminCache.cpp	Thu Feb 08 21:41:28 2007 +0000
     1.2 +++ b/core/AdminCache.cpp	Fri Feb 09 01:08:59 2007 +0000
     1.3 @@ -16,6 +16,7 @@
     1.4  #include "AdminCache.h"
     1.5  #include "ShareSys.h"
     1.6  #include "ForwardSys.h"
     1.7 +#include "CPlayerManager.h"
     1.8  
     1.9  AdminCache g_Admins;
    1.10  
    1.11 @@ -31,6 +32,7 @@
    1.12  	m_pCacheFwd = NULL;
    1.13  	m_FirstGroup = -1;
    1.14  	m_pAuthTables = sm_trie_create();
    1.15 +	m_InvalidatingAdmins = false;
    1.16  }
    1.17  
    1.18  AdminCache::~AdminCache()
    1.19 @@ -544,6 +546,11 @@
    1.20  		return false;
    1.21  	}
    1.22  
    1.23 +	if (!m_InvalidatingAdmins)
    1.24 +	{
    1.25 +		g_Players.ClearAdminId(id);
    1.26 +	}
    1.27 +
    1.28  	/* Unlink from the dbl link list */
    1.29  	if (id == m_FirstUser && id == m_LastUser)
    1.30  	{
    1.31 @@ -738,6 +745,8 @@
    1.32  
    1.33  void AdminCache::InvalidateAdminCache(bool unlink_admins)
    1.34  {
    1.35 +	m_InvalidatingAdmins = true;
    1.36 +	g_Players.ClearAllAdmins();
    1.37  	/* Wipe the identity cache first */
    1.38  	List<AuthMethod>::iterator iter;
    1.39  	for (iter=m_AuthMethods.begin();
    1.40 @@ -758,6 +767,7 @@
    1.41  		m_LastUser = -1;
    1.42  		m_FreeUserList = -1;
    1.43  	}
    1.44 +	m_InvalidatingAdmins = false;
    1.45  }
    1.46  
    1.47  void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild)
    1.48 @@ -950,6 +960,23 @@
    1.49  	return 0;
    1.50  }
    1.51  
    1.52 +void AdminCache::SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits)
    1.53 +{
    1.54 +	AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id);
    1.55 +	if (!pUser || pUser->magic != USR_MAGIC_SET)
    1.56 +	{
    1.57 +		return;
    1.58 +	}
    1.59 +
    1.60 +	if (mode == Access_Real)
    1.61 +	{
    1.62 +		pUser->flags = bits;
    1.63 +		pUser->eflags = bits;
    1.64 +	} else if (mode == Access_Effective) {
    1.65 +		pUser->eflags = bits;
    1.66 +	}
    1.67 +}
    1.68 +
    1.69  bool AdminCache::AdminInheritGroup(AdminId id, GroupId gid)
    1.70  {
    1.71  	AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id);
    1.72 @@ -1025,6 +1052,12 @@
    1.73  	return true;
    1.74  }
    1.75  
    1.76 +bool AdminCache::IsValidAdmin(AdminId id)
    1.77 +{
    1.78 +	AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id);
    1.79 +	return (pUser != NULL && pUser->magic == USR_MAGIC_SET);
    1.80 +}
    1.81 +
    1.82  unsigned int AdminCache::GetAdminGroupCount(AdminId id)
    1.83  {
    1.84  	AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id);