From 62a5c54a18485356825689dc6a8a80c4a44321d5 Mon Sep 17 00:00:00 2001 From: Karol Szuster Date: Tue, 22 Dec 2015 16:36:51 +0100 Subject: [PATCH] Add client_connectex & extend client_authorized forward --- amxmodx/amxmodx.h | 1 + amxmodx/meta_api.cpp | 25 +++++++++++++++++++------ plugins/include/amxmodx.inc | 21 +++++++++++++++++++-- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/amxmodx/amxmodx.h b/amxmodx/amxmodx.h index e7f939ea..296326bd 100755 --- a/amxmodx/amxmodx.h +++ b/amxmodx/amxmodx.h @@ -339,6 +339,7 @@ extern int FF_PluginEnd; extern int FF_InconsistentFile; extern int FF_ClientAuthorized; extern int FF_ChangeLevel; +extern int FF_ClientConnectEx; extern bool g_coloredmenus; diff --git a/amxmodx/meta_api.cpp b/amxmodx/meta_api.cpp index cd03f377..108da745 100755 --- a/amxmodx/meta_api.cpp +++ b/amxmodx/meta_api.cpp @@ -145,6 +145,7 @@ int FF_PluginEnd = -1; int FF_InconsistentFile = -1; int FF_ClientAuthorized = -1; int FF_ChangeLevel = -1; +int FF_ClientConnectEx = -1; IFileSystem* g_FileSystem; HLTypeConversion TypeConversion; @@ -503,8 +504,9 @@ int C_Spawn(edict_t *pent) FF_PluginLog = registerForward("plugin_log", ET_STOP, FP_DONE); FF_PluginEnd = registerForward("plugin_end", ET_IGNORE, FP_DONE); FF_InconsistentFile = registerForward("inconsistent_file", ET_STOP, FP_CELL, FP_STRING, FP_STRINGEX, FP_DONE); - FF_ClientAuthorized = registerForward("client_authorized", ET_IGNORE, FP_CELL, FP_DONE); + FF_ClientAuthorized = registerForward("client_authorized", ET_IGNORE, FP_CELL, FP_STRING, FP_DONE); FF_ChangeLevel = registerForward("server_changelevel", ET_STOP, FP_STRING, FP_DONE); + FF_ClientConnectEx = registerForward("client_connectex", ET_STOP, FP_CELL, FP_STRING, FP_STRING, FP_ARRAY, FP_DONE); CoreCfg.OnAmxxInitialized(); @@ -820,24 +822,34 @@ BOOL C_ClientConnect_Post(edict_t *pEntity, const char *pszName, const char *psz g_auth.put(aa); } else { pPlayer->Authorize(); + const char* authid = GETPLAYERAUTHID(pEntity); 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)); + executeForwards(FF_ClientAuthorized, static_cast(pPlayer->index), authid); } } RETURN_META_VALUE(MRES_IGNORED, TRUE); } +BOOL C_ClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char szRejectReason[128]) +{ + CPlayer* pPlayer = GET_PLAYER_POINTER(pEntity); + + if(executeForwards(FF_ClientConnectEx, static_cast(pPlayer->index), pszName, pszAddress, prepareCharArray(szRejectReason, 128, true))) + RETURN_META_VALUE(MRES_SUPERCEDE, FALSE); + + RETURN_META_VALUE(MRES_IGNORED, TRUE); +} + void C_ClientDisconnect(edict_t *pEntity) { CPlayer *pPlayer = GET_PLAYER_POINTER(pEntity); @@ -923,18 +935,18 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer) executeForwards(FF_ClientConnect, static_cast(pPlayer->index)); pPlayer->Authorize(); + const char* authid = GETPLAYERAUTHID(pEntity); 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)); + executeForwards(FF_ClientAuthorized, static_cast(pPlayer->index), authid); pPlayer->PutInServer(); ++g_players_num; @@ -1131,7 +1143,7 @@ void C_StartFrame_Post(void) fn((*a)->index, auth); } } - executeForwards(FF_ClientAuthorized, static_cast((*a)->index)); + executeForwards(FF_ClientAuthorized, static_cast((*a)->index), auth); a.remove(); continue; @@ -1717,6 +1729,7 @@ C_DLLEXPORT int GetEntityAPI2(DLL_FUNCTIONS *pFunctionTable, int *interfaceVersi gFunctionTable.pfnClientDisconnect = C_ClientDisconnect; gFunctionTable.pfnInconsistentFile = C_InconsistentFile; gFunctionTable.pfnServerActivate = C_ServerActivate; + gFunctionTable.pfnClientConnect = C_ClientConnect; memcpy(pFunctionTable, &gFunctionTable, sizeof(DLL_FUNCTIONS)); diff --git a/plugins/include/amxmodx.inc b/plugins/include/amxmodx.inc index 4cf896af..fe6f1c6d 100755 --- a/plugins/include/amxmodx.inc +++ b/plugins/include/amxmodx.inc @@ -143,17 +143,34 @@ forward client_infochanged(id); */ forward client_connect(id); +/** + * Called when a client is connecting. + * + * @note This forward is called too early to do anything that directly affects + * the client. + * + * @param id Client index + * @param name Client name + * @param ip Client ip address with port + * @param reason A reason that will be displayed when player gets rejected (can be overwritten) + * + * @return PLUGIN_CONTINUE to let a client join to the server + * PLUGIN_HANDLED or higher to prevent a client to join + */ +forward client_connectex(id, const name[], const ip[], reason[128]); + /** * Called when the client gets a valid SteamID. * * @note This may occur before or after client_putinserver has been called. * @note This is called for bots, and the SteamID will be "BOT". * - * @param id Client index + * @param id Client index + * @param authid Client auth * * @noreturn */ -forward client_authorized(id); +forward client_authorized(id, const authid[]); /** * @deprecated This function does not catch all cases.