core/PlayerManager.cpp
changeset 930 4ce68e8f7577
parent 916 39ae94ad60ce
child 931 d1c12f218789
     1.1 --- a/core/PlayerManager.cpp	Fri Jun 08 06:31:46 2007 +0000
     1.2 +++ b/core/PlayerManager.cpp	Fri Jun 08 07:54:45 2007 +0000
     1.3 @@ -19,6 +19,7 @@
     1.4  #include "ConCmdManager.h"
     1.5  #include "MenuStyle_Valve.h"
     1.6  #include "MenuStyle_Radio.h"
     1.7 +#include "sm_stringutil.h"
     1.8  
     1.9  PlayerManager g_Players;
    1.10  bool g_OnMapStarted = false;
    1.11 @@ -115,6 +116,24 @@
    1.12  	g_OnMapStarted = true;
    1.13  }
    1.14  
    1.15 +bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
    1.16 +{
    1.17 +	const char *password = g_Admins.GetAdminPassword(id);
    1.18 +	if (password != NULL)
    1.19 +	{
    1.20 +		/* Whoa... the user needs a password! */
    1.21 +		const char *given = engine->GetClientConVarValue(index, "_password");
    1.22 +		if (!given || strcmp(given, password) != 0)
    1.23 +		{
    1.24 +			return false;
    1.25 +		}
    1.26 +	}
    1.27 +
    1.28 +	pPlayer->SetAdminId(id, false);
    1.29 +
    1.30 +	return true;
    1.31 +}
    1.32 +
    1.33  void PlayerManager::RunAuthChecks()
    1.34  {
    1.35  	CPlayer *pPlayer;
    1.36 @@ -136,6 +155,13 @@
    1.37  			m_AuthQueue[i] = 0;
    1.38  			removed++;
    1.39  
    1.40 +			/* Do admin lookups */
    1.41 +			AdminId id = g_Admins.FindAdminByIdentity("steam", authstr);
    1.42 +			if (id != INVALID_ADMIN_ID)
    1.43 +			{
    1.44 +				CheckSetAdmin(client, pPlayer, id);
    1.45 +			}
    1.46 +
    1.47  			/* Send to extensions */
    1.48  			List<IClientListener *>::iterator iter;
    1.49  			IClientListener *pListener;
    1.50 @@ -233,6 +259,7 @@
    1.51  {
    1.52  	int client = engine->IndexOfEdict(pEntity);
    1.53  	bool orig_value = META_RESULT_ORIG_RET(bool);
    1.54 +	CPlayer *pPlayer = GetPlayerByIndex(client);
    1.55  	if (orig_value)
    1.56  	{
    1.57  		List<IClientListener *>::iterator iter;
    1.58 @@ -241,6 +268,27 @@
    1.59  		{
    1.60  			pListener = (*iter);
    1.61  			pListener->OnClientConnected(client);
    1.62 +			if (!pPlayer->IsConnected())
    1.63 +			{
    1.64 +				break;
    1.65 +			}
    1.66 +		}
    1.67 +	}
    1.68 +
    1.69 +	if (pPlayer->IsConnected())
    1.70 +	{
    1.71 +		/* Do an ip based lookup */
    1.72 +		char ip[24], *ptr;
    1.73 +		strncopy(ip, pszAddress, sizeof(ip));
    1.74 +		if ((ptr = strchr(ip, ':')) != NULL)
    1.75 +		{
    1.76 +			*ptr = '\0';
    1.77 +		}
    1.78 +		
    1.79 +		AdminId id = g_Admins.FindAdminByIdentity("ip", pPlayer->GetIPAddress());
    1.80 +		if (id != INVALID_ADMIN_ID)
    1.81 +		{
    1.82 +			CheckSetAdmin(client, pPlayer, id);
    1.83  		}
    1.84  	}
    1.85