Skip to content

Commit

Permalink
Add client_connectex & extend client_authorized forward
Browse files Browse the repository at this point in the history
  • Loading branch information
Amaroq7 committed Dec 22, 2015
1 parent 8bb8aaa commit 62a5c54
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
1 change: 1 addition & 0 deletions amxmodx/amxmodx.h
Expand Up @@ -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;

Expand Down
25 changes: 19 additions & 6 deletions amxmodx/meta_api.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<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), 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<cell>(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);
Expand Down Expand Up @@ -923,18 +935,18 @@ void C_ClientUserInfoChanged_Post(edict_t *pEntity, char *infobuffer)
executeForwards(FF_ClientConnect, static_cast<cell>(pPlayer->index));

pPlayer->Authorize();
const char* authid = GETPLAYERAUTHID(pEntity);
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), authid);

pPlayer->PutInServer();
++g_players_num;
Expand Down Expand Up @@ -1131,7 +1143,7 @@ void C_StartFrame_Post(void)
fn((*a)->index, auth);
}
}
executeForwards(FF_ClientAuthorized, static_cast<cell>((*a)->index));
executeForwards(FF_ClientAuthorized, static_cast<cell>((*a)->index), auth);
a.remove();

continue;
Expand Down Expand Up @@ -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));

Expand Down
21 changes: 19 additions & 2 deletions plugins/include/amxmodx.inc
Expand Up @@ -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.
Expand Down

0 comments on commit 62a5c54

Please sign in to comment.