Slightly speed up OnClientAuthorized where possible (#2504)

This commit is contained in:
Nicholas Hastings
2026-07-16 13:29:22 -04:00
parent d49ed86a1d
commit c7fb295eab
5 changed files with 51 additions and 4 deletions
+28
View File
@@ -46,6 +46,7 @@
#include <iserver.h>
#include <IGameConfigs.h>
#include "ConsoleDetours.h"
#include "frame_hooks.h"
#include "logic_bridge.h"
#include <sourcemod_version.h>
#include "smn_keyvalues.h"
@@ -78,6 +79,16 @@ SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *)
#endif
SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
// mock lacks NetworkIDValidated; episode1/darkm (< SE_ORANGEBOX) predate it.
#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_MOCK
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
SH_DECL_HOOK3_void(IServerGameClients, NetworkIDValidated, SH_NOATTRIB, 0, const char *, const char *, CSteamID);
#else
SH_DECL_HOOK2_void(IServerGameClients, NetworkIDValidated, SH_NOATTRIB, 0, const char *, const char *);
#endif
#define SM_HAS_NETWORKID_VALIDATED 1
#endif
#if SOURCE_ENGINE >= SE_EYE
SH_DECL_HOOK2_void(IServerGameClients, ClientCommandKeyValues, SH_NOATTRIB, 0, edict_t *, KeyValues *);
#endif
@@ -175,6 +186,9 @@ void PlayerManager::OnSourceModAllInitialized()
SH_ADD_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues_Post), true);
#endif
SH_ADD_HOOK(IServerGameClients, ClientSettingsChanged, serverClients, SH_MEMBER(this, &PlayerManager::OnClientSettingsChanged), true);
#if defined SM_HAS_NETWORKID_VALIDATED
SH_ADD_HOOK(IServerGameClients, NetworkIDValidated, serverClients, SH_MEMBER(this, &PlayerManager::OnNetworkIDValidated), true);
#endif
SH_ADD_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerActivate), true);
#if SOURCE_ENGINE >= SE_LEFT4DEAD
SH_ADD_HOOK(IServerGameDLL, ServerHibernationUpdate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true);
@@ -232,6 +246,9 @@ void PlayerManager::OnSourceModShutdown()
SH_REMOVE_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues_Post), true);
#endif
SH_REMOVE_HOOK(IServerGameClients, ClientSettingsChanged, serverClients, SH_MEMBER(this, &PlayerManager::OnClientSettingsChanged), true);
#if defined SM_HAS_NETWORKID_VALIDATED
SH_REMOVE_HOOK(IServerGameClients, NetworkIDValidated, serverClients, SH_MEMBER(this, &PlayerManager::OnNetworkIDValidated), true);
#endif
SH_REMOVE_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerActivate), true);
#if SOURCE_ENGINE >= SE_LEFT4DEAD
SH_REMOVE_HOOK(IServerGameDLL, ServerHibernationUpdate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true);
@@ -492,6 +509,17 @@ void PlayerManager::RunAuthChecks()
}
}
#if defined SM_HAS_NETWORKID_VALIDATED
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
void PlayerManager::OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID, CSteamID steamID)
#else
void PlayerManager::OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID)
#endif
{
g_PendingAuthCheck = true;
}
#endif
bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
{
int client = IndexOfEdict(pEntity);
+7
View File
@@ -194,6 +194,13 @@ public:
#endif
void OnClientSettingsChanged(edict_t *pEntity);
//void OnClientSettingsChanged_Pre(edict_t *pEntity);
#if SOURCE_ENGINE >= SE_ORANGEBOX && SOURCE_ENGINE != SE_MOCK
#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV
void OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID, CSteamID steamID);
#else
void OnNetworkIDValidated(const char *pszUserName, const char *pszNetworkID);
#endif
#endif
void OnClientLanguageChanged(int client, unsigned int language);
void OnServerHibernationUpdate(bool bHibernating);
void OnClientPrintf(edict_t *pEdict, const char *szMsg);
+9 -1
View File
@@ -45,6 +45,7 @@ static Queue<FrameAction> *frame_actions;
static float g_LastMenuTime = 0.0f;
static float g_LastAuthCheck = 0.0f;
bool g_PendingInternalPush = false;
bool g_PendingAuthCheck = false;
class FrameActionInit : public SMGlobalClass
{
@@ -114,9 +115,16 @@ void RunFrameHooks(bool simulating)
g_LastMenuTime = curtime;
}
if (*g_NumPlayersToAuth && curtime - g_LastAuthCheck >= 0.7f)
/* g_PendingAuthCheck is set by the NetworkIDValidated hook so that a client
* whose Steam ticket was just validated is authorized on the next frame rather
* than waiting up to 0.7s for the periodic check. It's deferred to the next frame
* (instead of authorizing inline in the hook) because the engine doesn't flag the
* client as fully authenticated until after the NetworkIDValidated callback returns.
*/
if (*g_NumPlayersToAuth && (g_PendingAuthCheck || curtime - g_LastAuthCheck >= 0.7f))
{
g_Players.RunAuthChecks();
g_LastAuthCheck = curtime;
g_PendingAuthCheck = false;
}
}
+1
View File
@@ -46,6 +46,7 @@ struct FrameAction
};
extern bool g_PendingInternalPush;
extern bool g_PendingAuthCheck;
void AddFrameAction(const FrameAction & action);
void RunFrameHooks(bool simulating);
+6 -3
View File
@@ -170,9 +170,12 @@ forward void OnClientCommandKeyValues_Post(int client, KeyValues kv);
forward void OnClientSettingsChanged(int client);
/**
* Called when a client receives an auth ID. The state of a client's
* authorization as an admin is not guaranteed here. Use
* OnClientPostAdminCheck() if you need a client's admin status.
* Called after a client's auth ID has been validated. The state
* of a client's authorization as an admin is not guaranteed here.
* Use OnClientPostAdminCheck() if you need a client's admin status.
*
* There may be a delay in receiving this callback if the Steam
* netowrk is experience downtime or other issues.
*
* This is called by bots, but the ID will be "BOT".
*