From dc5506efe3450d3a3395caa0b6defc470c88c67a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 28 Feb 2006 09:59:03 +0000 Subject: [PATCH] added experimental callback for modules to get authorization --- amxmodx/CMisc.cpp | 10 +++++----- amxmodx/amxmodx.h | 2 ++ amxmodx/meta_api.cpp | 34 ++++++++++++++++++++++++++++++++++ amxmodx/modules.cpp | 18 ++++++++++++++++-- amxmodx/sdk/amxxmodule.cpp | 6 ++++++ amxmodx/sdk/amxxmodule.h | 12 +++++++++++- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/amxmodx/CMisc.cpp b/amxmodx/CMisc.cpp index 951b6558..e5d1d385 100755 --- a/amxmodx/CMisc.cpp +++ b/amxmodx/CMisc.cpp @@ -134,11 +134,6 @@ bool CPlayer::Connect(const char* connectname, const char* ipaddress) hudmap[i] = 0; } - const char* authid = GETPLAYERAUTHID(pEdict); - - if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0)) - return true; - List::iterator iter, end=queries.end(); for (iter=queries.begin(); iter!=end; iter++) { @@ -148,6 +143,11 @@ bool CPlayer::Connect(const char* connectname, const char* ipaddress) } queries.clear(); + const char* authid = GETPLAYERAUTHID(pEdict); + + if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0)) + return true; + return false; } diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index fbaaa3b7..02b9b2c4 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -318,6 +318,8 @@ extern int FF_ClientAuthorized; extern int FF_ChangeLevel; extern bool g_coloredmenus; +typedef void (*AUTHORIZEFUNC)(int player, const char *authstring); + #define MM_CVAR2_VERS 13 struct func_s diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index c6eb92a3..b23d4800 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -65,6 +65,8 @@ funEventCall modMsgs[MAX_REG_MSGS]; void (*function)(void*); void (*endfunction)(void*); +extern List g_auth_funcs; + CLog g_log; CForwardMngr g_forwards; CList g_auth; @@ -587,6 +589,17 @@ BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *psz g_auth.put(aa); } else { pPlayer->Authorize(); + if (g_auth_funcs.size()) + { + List::iterator iter, end=g_auth_funcs.end(); + AUTHORIZEFUNC fn; + const char* authid = GETPLAYERAUTHID(pEntity); + for (iter=g_auth_funcs.begin(); iter!=end; iter++) + { + fn = (*iter); + fn(pPlayer->index, authid); + } + } executeForwards(FF_ClientAuthorized, static_cast(pPlayer->index)); } } @@ -640,6 +653,17 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer) executeForwards(FF_ClientConnect, static_cast(pPlayer->index)); pPlayer->Authorize(); + if (g_auth_funcs.size()) + { + List::iterator iter, end=g_auth_funcs.end(); + AUTHORIZEFUNC fn; + const char* authid = GETPLAYERAUTHID(pEntity); + for (iter=g_auth_funcs.begin(); iter!=end; iter++) + { + fn = (*iter); + fn(pPlayer->index, authid); + } + } executeForwards(FF_ClientAuthorized, static_cast(pPlayer->index)); pPlayer->PutInServer(); @@ -800,6 +824,16 @@ void C_StartFrame_Post(void) if (strcmp(auth, "STEAM_ID_PENDING")) { (*a)->Authorize(); + if (g_auth_funcs.size()) + { + List::iterator iter, end=g_auth_funcs.end(); + AUTHORIZEFUNC fn; + for (iter=g_auth_funcs.begin(); iter!=end; iter++) + { + fn = (*iter); + fn((*a)->index, auth); + } + } executeForwards(FF_ClientAuthorized, static_cast((*a)->index)); a.remove(); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 9441921a..197da96c 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -1140,6 +1140,17 @@ int MNF_GetAmxStringLen(const cell *ptr) return c; } +List g_auth_funcs; +void MNF_RegAuthorizeFunc(AUTHORIZEFUNC fn) +{ + g_auth_funcs.push_back(fn); +} + +void MNF_UnregAuthorizeFunc(AUTHORIZEFUNC fn) +{ + g_auth_funcs.remove(fn); +} + char *MNF_FormatAmxString(AMX *amx, cell *params, int startParam, int *pLen) { int len; @@ -1515,7 +1526,7 @@ int MNF_SetPlayerTeamInfo(int player, int teamid, const char *teamname) return 1; } -void *MFN_PlayerPropAddr(int id, int prop) +void *MNF_PlayerPropAddr(int id, int prop) { if (id < 1 || id > gpGlobals->maxClients) return NULL; @@ -1651,7 +1662,10 @@ void Module_CacheFunctions() REGISTER_FUNC("CellToReal", MNF_CellToReal) REGISTER_FUNC("RealToCell", MNF_RealToCell) REGISTER_FUNC("SetPlayerTeamInfo", MNF_SetPlayerTeamInfo) - REGISTER_FUNC("PlayerPropAddr", MFN_PlayerPropAddr) + REGISTER_FUNC("PlayerPropAddr", MNF_PlayerPropAddr) + + REGISTER_FUNC("RegAuthFunc", MNF_RegAuthorizeFunc); + REGISTER_FUNC("UnregAuthFunc", MNF_UnregAuthorizeFunc); #ifdef MEMORY_TEST REGISTER_FUNC("Allocator", m_allocator) diff --git a/amxmodx/sdk/amxxmodule.cpp b/amxmodx/sdk/amxxmodule.cpp index 7355cded..1441e450 100755 --- a/amxmodx/sdk/amxxmodule.cpp +++ b/amxmodx/sdk/amxxmodule.cpp @@ -2504,6 +2504,8 @@ PFN_REQ_FNPTR g_fn_RequestFunction; PFN_AMX_PUSH g_fn_AmxPush; PFN_SET_TEAM_INFO g_fn_SetTeamInfo; PFN_PLAYER_PROP_ADDR g_fn_PlayerPropAddr; +PFN_REG_AUTH_FUNC g_fn_RegAuthFunc; +PFN_UNREG_AUTH_FUNC g_fn_UnregAuthFunc; // *** Exports *** C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo) @@ -2615,6 +2617,8 @@ C_DLLEXPORT int AMXX_Attach(PFN_REQ_FNPTR reqFnptrFunc) REQFUNC("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH); REQFUNC("SetPlayerTeamInfo", g_fn_SetTeamInfo, PFN_SET_TEAM_INFO); REQFUNC("PlayerPropAddr", g_fn_PlayerPropAddr, PFN_PLAYER_PROP_ADDR); + REQFUNC("RegAuthFunc", g_fn_RegAuthFunc, PFN_REG_AUTH_FUNC); + REQFUNC("UnregAuthFunc", g_fn_UnregAuthFunc, PFN_UNREG_AUTH_FUNC); #ifdef MEMORY_TEST // Memory @@ -2739,6 +2743,8 @@ void ValidateMacros_DontCallThis_Smiley() MF_RegisterFunction(NULL, ""); MF_SetPlayerTeamInfo(0, 0, ""); MF_PlayerPropAddr(0, 0); + MF_RegAuthFunc(NULL); + MF_UnregAuthFunc(NULL); } #endif diff --git a/amxmodx/sdk/amxxmodule.h b/amxmodx/sdk/amxxmodule.h index 3d20f50e..168fa2b4 100755 --- a/amxmodx/sdk/amxxmodule.h +++ b/amxmodx/sdk/amxxmodule.h @@ -1950,6 +1950,8 @@ enum PlayerProp Player_NewmenuPage, //int }; +typedef void (*AUTHORIZEFUNC)(int player, const char *authstring); + typedef int (*PFN_ADD_NATIVES) (const AMX_NATIVE_INFO * /*list*/); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, const char * /* format */, ...); @@ -2027,6 +2029,8 @@ typedef const char * (*PFN_FORMAT) (const char * /*fmt*/, ... /*params*/); typedef void (*PFN_REGISTERFUNCTION) (void * /*pfn*/, const char * /*desc*/); typedef int (*PFN_AMX_PUSH) (AMX * /*amx*/, cell /*value*/); typedef int (*PFN_SET_TEAM_INFO) (int /*player */, int /*teamid */, const char * /*name */); +typedef void (*PFN_REG_AUTH_FUNC) (AUTHORIZEFUNC); +typedef void (*PFN_UNREG_AUTH_FUNC) (AUTHORIZEFUNC); extern PFN_ADD_NATIVES g_fn_AddNatives; extern PFN_BUILD_PATHNAME g_fn_BuildPathname; @@ -2092,6 +2096,8 @@ extern PFN_REQ_FNPTR g_fn_RequestFunction; extern PFN_AMX_PUSH g_fn_AmxPush; extern PFN_SET_TEAM_INFO g_fn_SetTeamInfo; extern PFN_PLAYER_PROP_ADDR g_fn_PlayerPropAddr; +extern PFN_REG_AUTH_FUNC g_fn_RegAuthFunc; +extern PFN_UNREG_AUTH_FUNC g_fn_UnregAuthFunc; #ifdef MAY_NEVER_BE_DEFINED // Function prototypes for intellisense and similar systems @@ -2154,6 +2160,8 @@ int MF_AmxPush (AMX *amx, cell *params) { } int MF_AmxExec (AMX *amx, cell *retval, int idx) { } int MF_SetPlayerTeamInfo (int id, int teamid, const char *teamname) { } void * MF_PlayerPropAddr (int id, int prop) { } +void MF_RegAuthFunc (AUTHORIZEFUNC fn) { } +void MF_UnregAuthFunc (AUTHORIZEFUNC fn) { } #endif // MAY_NEVER_BE_DEFINED #define MF_AddNatives g_fn_AddNatives @@ -2217,10 +2225,12 @@ void MF_LogError(AMX *amx, int err, const char *fmt, ...); #define MF_GetPlayerEdict g_fn_GetPlayerEdict #define MF_Format g_fn_Format #define MF_RegisterFunction g_fn_RegisterFunction -#define MF_RequestFunction g_fn_RequestFunction; +#define MF_RequestFunction g_fn_RequestFunction #define MF_AmxPush g_fn_AmxPush #define MF_SetPlayerTeamInfo g_fn_SetTeamInfo #define MF_PlayerPropAddr g_fn_PlayerPropAddr +#define MF_RegAuthFunc g_fn_RegAuthFunc +#define MF_UnregAuthFunc g_fn_UnregAuthFunc #ifdef MEMORY_TEST /*** Memory ***/