core/PlayerManager.cpp
changeset 1273 9afc766f8e9c
parent 1231 17badaf66ce4
child 1288 ae5f77aef635
     1.1 --- a/core/PlayerManager.cpp	Wed Aug 08 15:08:01 2007 +0000
     1.2 +++ b/core/PlayerManager.cpp	Wed Aug 08 16:22:51 2007 +0000
     1.3 @@ -45,6 +45,8 @@
     1.4  
     1.5  PlayerManager g_Players;
     1.6  bool g_OnMapStarted = false;
     1.7 +IForward *PreAdminCheck = NULL;
     1.8 +IForward *PostAdminCheck = NULL;
     1.9  
    1.10  SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
    1.11  SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
    1.12 @@ -112,6 +114,9 @@
    1.13  	m_clauth = g_Forwards.CreateForward("OnClientAuthorized", ET_Ignore, 2, NULL, Param_Cell, Param_String);
    1.14  	m_onActivate = g_Forwards.CreateForward("OnServerLoad", ET_Ignore, 0, NULL);
    1.15  	m_onActivate2 = g_Forwards.CreateForward("OnMapStart", ET_Ignore, 0, NULL);
    1.16 +
    1.17 +	PreAdminCheck = g_Forwards.CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1);
    1.18 +	PostAdminCheck = g_Forwards.CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1);
    1.19  }
    1.20  
    1.21  void PlayerManager::OnSourceModShutdown()
    1.22 @@ -135,6 +140,9 @@
    1.23  	g_Forwards.ReleaseForward(m_onActivate);
    1.24  	g_Forwards.ReleaseForward(m_onActivate2);
    1.25  
    1.26 +	g_Forwards.ReleaseForward(PreAdminCheck);
    1.27 +	g_Forwards.ReleaseForward(PostAdminCheck);
    1.28 +
    1.29  	delete [] m_Players;
    1.30  }
    1.31  
    1.32 @@ -751,6 +759,7 @@
    1.33  	m_Admin = INVALID_ADMIN_ID;
    1.34  	m_TempAdmin = false;
    1.35  	m_Info = NULL;
    1.36 +	m_bAdminCheckSignalled = false;
    1.37  	m_LastPassword.clear();
    1.38  }
    1.39  
    1.40 @@ -760,6 +769,7 @@
    1.41  	m_Name.assign(name);
    1.42  	m_Ip.assign(ip);
    1.43  	m_pEdict = pEntity;
    1.44 +	m_iIndex = engine->IndexOfEdict(pEntity);
    1.45  
    1.46  	char ip2[24], *ptr;
    1.47  	strncopy(ip2, ip, sizeof(ip2));
    1.48 @@ -791,7 +801,7 @@
    1.49  
    1.50  	if (m_IsAuthorized)
    1.51  	{
    1.52 -		DoBasicAdminChecks();
    1.53 +		DoPostConnectAuthorization();
    1.54  	}
    1.55  }
    1.56  
    1.57 @@ -817,6 +827,7 @@
    1.58  	m_AuthID.clear();
    1.59  	m_pEdict = NULL;
    1.60  	m_Info = NULL;
    1.61 +	m_bAdminCheckSignalled = false;
    1.62  }
    1.63  
    1.64  void CPlayer::SetName(const char *name)
    1.65 @@ -902,8 +913,7 @@
    1.66  
    1.67  void CPlayer::Kick(const char *str)
    1.68  {
    1.69 -	int client = engine->IndexOfEdict(m_pEdict);
    1.70 -	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(client));
    1.71 +	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(m_iIndex));
    1.72  	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
    1.73  	pClient->Disconnect("%s", str);
    1.74  }
    1.75 @@ -912,8 +922,47 @@
    1.76  {
    1.77  	if (m_IsInGame)
    1.78  	{
    1.79 -		DoBasicAdminChecks();
    1.80 +		DoPostConnectAuthorization();
    1.81 +	}
    1.82 +}
    1.83 +
    1.84 +void CPlayer::DoPostConnectAuthorization()
    1.85 +{
    1.86 +	cell_t result;
    1.87 +	PreAdminCheck->PushCell(m_iIndex);
    1.88 +	PreAdminCheck->Execute(&result);
    1.89 +
    1.90 +	/* Defer, for better or worse */
    1.91 +	if ((ResultType)result >= Pl_Handled)
    1.92 +	{
    1.93 +		return;
    1.94 +	}
    1.95 +
    1.96 +	/* Sanity check */
    1.97 +	if (!IsConnected())
    1.98 +	{
    1.99 +		return;
   1.100  	}
   1.101 +
   1.102 +	/* Otherwise, go ahead and do admin checks */
   1.103 +	DoBasicAdminChecks();
   1.104 +
   1.105 +	/* Send the notification out */
   1.106 +	NotifyPostAdminChecks();
   1.107 +}
   1.108 +
   1.109 +void CPlayer::NotifyPostAdminChecks()
   1.110 +{
   1.111 +	if (m_bAdminCheckSignalled)
   1.112 +	{
   1.113 +		return;
   1.114 +	}
   1.115 +
   1.116 +	/* Block beforehand so they can't double-call */
   1.117 +	m_bAdminCheckSignalled = true;
   1.118 +
   1.119 +	PostAdminCheck->PushCell(m_iIndex);
   1.120 +	PostAdminCheck->Execute(NULL);
   1.121  }
   1.122  
   1.123  void CPlayer::DoBasicAdminChecks()