Merge pull request #155 from alliedmodders/onclientauth-steam2

Make OnClientAuthorized use Steam2 ids where available (r=asherkin).
This commit is contained in:
Nicholas Hastings 2014-09-11 13:02:28 -04:00
commit 7f0b163b31
4 changed files with 20 additions and 12 deletions

View File

@ -423,13 +423,15 @@ void PlayerManager::RunAuthChecks()
m_AuthQueue[i] = 0; m_AuthQueue[i] = 0;
removed++; removed++;
const char *steamId = pPlayer->GetSteam2Id();
/* Send to extensions */ /* Send to extensions */
List<IClientListener *>::iterator iter; List<IClientListener *>::iterator iter;
IClientListener *pListener; IClientListener *pListener;
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{ {
pListener = (*iter); pListener = (*iter);
pListener->OnClientAuthorized(client, authstr); pListener->OnClientAuthorized(client, steamId ? steamId : authstr);
if (!pPlayer->IsConnected()) if (!pPlayer->IsConnected())
{ {
break; break;
@ -441,7 +443,8 @@ void PlayerManager::RunAuthChecks()
{ {
/* :TODO: handle the case of a player disconnecting in the middle */ /* :TODO: handle the case of a player disconnecting in the middle */
m_clauth->PushCell(client); m_clauth->PushCell(client);
m_clauth->PushString(authstr); /* For legacy reasons, people are expecting the Steam2 id here if using Steam auth */
m_clauth->PushString(steamId ? steamId : authstr);
m_clauth->Execute(NULL); m_clauth->Execute(NULL);
} }
@ -708,17 +711,20 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername
m_clconnect_post->PushCell(client); m_clconnect_post->PushCell(client);
m_clconnect_post->Execute(&res, NULL); m_clconnect_post->Execute(&res, NULL);
const char *steamId = pPlayer->GetSteam2Id();
/* Now do authorization */ /* Now do authorization */
for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
{ {
pListener = (*iter); pListener = (*iter);
pListener->OnClientAuthorized(client, pPlayer->m_AuthID.c_str()); pListener->OnClientAuthorized(client, steamId ? steamId : pPlayer->m_AuthID.c_str());
} }
/* Finally, tell plugins */ /* Finally, tell plugins */
if (m_clauth->GetFunctionCount()) if (m_clauth->GetFunctionCount())
{ {
m_clauth->PushCell(client); m_clauth->PushCell(client);
m_clauth->PushString(pPlayer->m_AuthID.c_str()); /* For legacy reasons, people are expecting the Steam2 id here if using Steam auth */
m_clauth->PushString(steamId ? steamId : pPlayer->m_AuthID.c_str());
m_clauth->Execute(NULL); m_clauth->Execute(NULL);
} }
pPlayer->Authorize_Post(); pPlayer->Authorize_Post();
@ -2151,7 +2157,7 @@ const CSteamID &CPlayer::GetSteamId(bool validated)
const char *CPlayer::GetSteam2Id(bool validated) const char *CPlayer::GetSteam2Id(bool validated)
{ {
if (validated && !IsAuthStringValidated()) if (!m_Steam2Id.length() || (validated && !IsAuthStringValidated()))
{ {
return NULL; return NULL;
} }
@ -2161,7 +2167,7 @@ const char *CPlayer::GetSteam2Id(bool validated)
const char *CPlayer::GetSteam3Id(bool validated) const char *CPlayer::GetSteam3Id(bool validated)
{ {
if (validated && !IsAuthStringValidated()) if (!m_Steam2Id.length() || (validated && !IsAuthStringValidated()))
{ {
return NULL; return NULL;
} }

View File

@ -394,7 +394,9 @@ void ClientPrefs::CatchLateLoadClients()
continue; continue;
} }
g_CookieManager.OnClientAuthorized(i, pPlayer->GetAuthString()); /* For legacy reasons, OnClientAuthorized gives the Steam2 id here if using Steam auth */
const char *steamId = pPlayer->GetSteam2Id();
g_CookieManager.OnClientAuthorized(i, steamId ? steamId : pPlayer->GetAuthString());
} }
} }

View File

@ -154,14 +154,14 @@ forward Action:OnClientCommand(client, args);
forward void OnClientSettingsChanged(client); forward void OnClientSettingsChanged(client);
/** /**
* Called when a client receives a Steam ID. The state of a client's * Called when a client receives an auth ID. The state of a client's
* authorization as an admin is not guaranteed here. Use * authorization as an admin is not guaranteed here. Use
* OnClientPostAdminCheck() if you need a client's admin status. * OnClientPostAdminCheck() if you need a client's admin status.
* *
* This is called by bots, but the ID will be "BOT". * This is called by bots, but the ID will be "BOT".
* *
* @param client Client index. * @param client Client index.
* @param auth Client auth string. * @param auth Client Steam2 id, if available, else engine auth id.
* @noreturn * @noreturn
*/ */
forward void OnClientAuthorized(client, const String:auth[]); forward void OnClientAuthorized(client, const String:auth[]);

View File

@ -282,7 +282,7 @@ namespace SourceMod
* *
* @param validated Check backend validation status. * @param validated Check backend validation status.
* *
* @return True on success or false if not available. * @return Steam2 Id on success or NULL if not available.
*/ */
virtual const char *GetSteam2Id(bool validated = true) =0; virtual const char *GetSteam2Id(bool validated = true) =0;
@ -291,7 +291,7 @@ namespace SourceMod
* *
* @param validated Check backend validation status. * @param validated Check backend validation status.
* *
* @return True on success or false if not available. * @return Steam3 Id on success or NULL if not available.
*/ */
virtual const char *GetSteam3Id(bool validated = true) =0; virtual const char *GetSteam3Id(bool validated = true) =0;
}; };
@ -365,7 +365,7 @@ namespace SourceMod
* @brief Called when a client has received authorization. * @brief Called when a client has received authorization.
* *
* @param client Index of the client. * @param client Index of the client.
* @param authstring Authorization string. * @param authstring Client Steam2 id, if available, else engine auth id.
*/ */
virtual void OnClientAuthorized(int client, const char *authstring) virtual void OnClientAuthorized(int client, const char *authstring)
{ {