added experimental callback for modules to get authorization

This commit is contained in:
David Anderson 2006-02-28 09:59:03 +00:00
parent 628d38df7a
commit dc5506efe3
6 changed files with 74 additions and 8 deletions

View File

@ -134,11 +134,6 @@ bool CPlayer::Connect(const char* connectname, const char* ipaddress)
hudmap[i] = 0; hudmap[i] = 0;
} }
const char* authid = GETPLAYERAUTHID(pEdict);
if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0))
return true;
List<ClientCvarQuery_Info *>::iterator iter, end=queries.end(); List<ClientCvarQuery_Info *>::iterator iter, end=queries.end();
for (iter=queries.begin(); iter!=end; iter++) for (iter=queries.begin(); iter!=end; iter++)
{ {
@ -148,6 +143,11 @@ bool CPlayer::Connect(const char* connectname, const char* ipaddress)
} }
queries.clear(); queries.clear();
const char* authid = GETPLAYERAUTHID(pEdict);
if ((authid == 0) || (*authid == 0) || (strcmp(authid, "STEAM_ID_PENDING") == 0))
return true;
return false; return false;
} }

View File

@ -318,6 +318,8 @@ extern int FF_ClientAuthorized;
extern int FF_ChangeLevel; extern int FF_ChangeLevel;
extern bool g_coloredmenus; extern bool g_coloredmenus;
typedef void (*AUTHORIZEFUNC)(int player, const char *authstring);
#define MM_CVAR2_VERS 13 #define MM_CVAR2_VERS 13
struct func_s struct func_s

View File

@ -65,6 +65,8 @@ funEventCall modMsgs[MAX_REG_MSGS];
void (*function)(void*); void (*function)(void*);
void (*endfunction)(void*); void (*endfunction)(void*);
extern List<AUTHORIZEFUNC> g_auth_funcs;
CLog g_log; CLog g_log;
CForwardMngr g_forwards; CForwardMngr g_forwards;
CList<CPlayer*> g_auth; CList<CPlayer*> g_auth;
@ -587,6 +589,17 @@ BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *psz
g_auth.put(aa); g_auth.put(aa);
} else { } else {
pPlayer->Authorize(); pPlayer->Authorize();
if (g_auth_funcs.size())
{
List<AUTHORIZEFUNC>::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<cell>(pPlayer->index)); executeForwards(FF_ClientAuthorized, static_cast<cell>(pPlayer->index));
} }
} }
@ -640,6 +653,17 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer)
executeForwards(FF_ClientConnect, static_cast<cell>(pPlayer->index)); executeForwards(FF_ClientConnect, static_cast<cell>(pPlayer->index));
pPlayer->Authorize(); pPlayer->Authorize();
if (g_auth_funcs.size())
{
List<AUTHORIZEFUNC>::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<cell>(pPlayer->index)); executeForwards(FF_ClientAuthorized, static_cast<cell>(pPlayer->index));
pPlayer->PutInServer(); pPlayer->PutInServer();
@ -800,6 +824,16 @@ void C_StartFrame_Post(void)
if (strcmp(auth, "STEAM_ID_PENDING")) if (strcmp(auth, "STEAM_ID_PENDING"))
{ {
(*a)->Authorize(); (*a)->Authorize();
if (g_auth_funcs.size())
{
List<AUTHORIZEFUNC>::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<cell>((*a)->index)); executeForwards(FF_ClientAuthorized, static_cast<cell>((*a)->index));
a.remove(); a.remove();

View File

@ -1140,6 +1140,17 @@ int MNF_GetAmxStringLen(const cell *ptr)
return c; return c;
} }
List<AUTHORIZEFUNC> 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) char *MNF_FormatAmxString(AMX *amx, cell *params, int startParam, int *pLen)
{ {
int len; int len;
@ -1515,7 +1526,7 @@ int MNF_SetPlayerTeamInfo(int player, int teamid, const char *teamname)
return 1; return 1;
} }
void *MFN_PlayerPropAddr(int id, int prop) void *MNF_PlayerPropAddr(int id, int prop)
{ {
if (id < 1 || id > gpGlobals->maxClients) if (id < 1 || id > gpGlobals->maxClients)
return NULL; return NULL;
@ -1651,7 +1662,10 @@ void Module_CacheFunctions()
REGISTER_FUNC("CellToReal", MNF_CellToReal) REGISTER_FUNC("CellToReal", MNF_CellToReal)
REGISTER_FUNC("RealToCell", MNF_RealToCell) REGISTER_FUNC("RealToCell", MNF_RealToCell)
REGISTER_FUNC("SetPlayerTeamInfo", MNF_SetPlayerTeamInfo) 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 #ifdef MEMORY_TEST
REGISTER_FUNC("Allocator", m_allocator) REGISTER_FUNC("Allocator", m_allocator)

View File

@ -2504,6 +2504,8 @@ PFN_REQ_FNPTR g_fn_RequestFunction;
PFN_AMX_PUSH g_fn_AmxPush; PFN_AMX_PUSH g_fn_AmxPush;
PFN_SET_TEAM_INFO g_fn_SetTeamInfo; PFN_SET_TEAM_INFO g_fn_SetTeamInfo;
PFN_PLAYER_PROP_ADDR g_fn_PlayerPropAddr; PFN_PLAYER_PROP_ADDR g_fn_PlayerPropAddr;
PFN_REG_AUTH_FUNC g_fn_RegAuthFunc;
PFN_UNREG_AUTH_FUNC g_fn_UnregAuthFunc;
// *** Exports *** // *** Exports ***
C_DLLEXPORT int AMXX_Query(int *interfaceVersion, amxx_module_info_s *moduleInfo) 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("amx_Push", g_fn_AmxPush, PFN_AMX_PUSH);
REQFUNC("SetPlayerTeamInfo", g_fn_SetTeamInfo, PFN_SET_TEAM_INFO); REQFUNC("SetPlayerTeamInfo", g_fn_SetTeamInfo, PFN_SET_TEAM_INFO);
REQFUNC("PlayerPropAddr", g_fn_PlayerPropAddr, PFN_PLAYER_PROP_ADDR); 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 #ifdef MEMORY_TEST
// Memory // Memory
@ -2739,6 +2743,8 @@ void ValidateMacros_DontCallThis_Smiley()
MF_RegisterFunction(NULL, ""); MF_RegisterFunction(NULL, "");
MF_SetPlayerTeamInfo(0, 0, ""); MF_SetPlayerTeamInfo(0, 0, "");
MF_PlayerPropAddr(0, 0); MF_PlayerPropAddr(0, 0);
MF_RegAuthFunc(NULL);
MF_UnregAuthFunc(NULL);
} }
#endif #endif

View File

@ -1950,6 +1950,8 @@ enum PlayerProp
Player_NewmenuPage, //int Player_NewmenuPage, //int
}; };
typedef void (*AUTHORIZEFUNC)(int player, const char *authstring);
typedef int (*PFN_ADD_NATIVES) (const AMX_NATIVE_INFO * /*list*/); typedef int (*PFN_ADD_NATIVES) (const AMX_NATIVE_INFO * /*list*/);
typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...); typedef char * (*PFN_BUILD_PATHNAME) (const char * /*format*/, ...);
typedef char * (*PFN_BUILD_PATHNAME_R) (char * /*buffer*/, size_t /* maxlen */, 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 void (*PFN_REGISTERFUNCTION) (void * /*pfn*/, const char * /*desc*/);
typedef int (*PFN_AMX_PUSH) (AMX * /*amx*/, cell /*value*/); typedef int (*PFN_AMX_PUSH) (AMX * /*amx*/, cell /*value*/);
typedef int (*PFN_SET_TEAM_INFO) (int /*player */, int /*teamid */, const char * /*name */); 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_ADD_NATIVES g_fn_AddNatives;
extern PFN_BUILD_PATHNAME g_fn_BuildPathname; 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_AMX_PUSH g_fn_AmxPush;
extern PFN_SET_TEAM_INFO g_fn_SetTeamInfo; extern PFN_SET_TEAM_INFO g_fn_SetTeamInfo;
extern PFN_PLAYER_PROP_ADDR g_fn_PlayerPropAddr; 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 #ifdef MAY_NEVER_BE_DEFINED
// Function prototypes for intellisense and similar systems // 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_AmxExec (AMX *amx, cell *retval, int idx) { }
int MF_SetPlayerTeamInfo (int id, int teamid, const char *teamname) { } int MF_SetPlayerTeamInfo (int id, int teamid, const char *teamname) { }
void * MF_PlayerPropAddr (int id, int prop) { } void * MF_PlayerPropAddr (int id, int prop) { }
void MF_RegAuthFunc (AUTHORIZEFUNC fn) { }
void MF_UnregAuthFunc (AUTHORIZEFUNC fn) { }
#endif // MAY_NEVER_BE_DEFINED #endif // MAY_NEVER_BE_DEFINED
#define MF_AddNatives g_fn_AddNatives #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_GetPlayerEdict g_fn_GetPlayerEdict
#define MF_Format g_fn_Format #define MF_Format g_fn_Format
#define MF_RegisterFunction g_fn_RegisterFunction #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_AmxPush g_fn_AmxPush
#define MF_SetPlayerTeamInfo g_fn_SetTeamInfo #define MF_SetPlayerTeamInfo g_fn_SetTeamInfo
#define MF_PlayerPropAddr g_fn_PlayerPropAddr #define MF_PlayerPropAddr g_fn_PlayerPropAddr
#define MF_RegAuthFunc g_fn_RegAuthFunc
#define MF_UnregAuthFunc g_fn_UnregAuthFunc
#ifdef MEMORY_TEST #ifdef MEMORY_TEST
/*** Memory ***/ /*** Memory ***/