Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flags update forward and a override param in set_user_flags #475

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions amxmodx/amxmodx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2841,7 +2841,7 @@ static cell AMX_NATIVE_CALL get_user_flags(AMX *amx, cell *params) /* 2 param */
return GET_PLAYER_POINTER_I(index)->flags[id];
}

static cell AMX_NATIVE_CALL set_user_flags(AMX *amx, cell *params) /* 3 param */
static cell AMX_NATIVE_CALL set_user_flags(AMX *amx, cell *params) /* 4 param */
{
int index = params[1];

Expand All @@ -2860,8 +2860,16 @@ static cell AMX_NATIVE_CALL set_user_flags(AMX *amx, cell *params) /* 3 param */

if (id > 31)
id = 31;

pPlayer->flags[id] |= flag;

int oldflags = pPlayer->flags[id];

if((*params / sizeof(cell) >= 4) && params[4])
pPlayer->flags[id] = flag;
else
pPlayer->flags[id] |= flag;

if(oldflags != pPlayer->flags[id])
executeForwards(FF_ClientFlagsUpdated, static_cast<cell>(pPlayer->index), oldflags, pPlayer->flags[id], id);

return 1;
}
Expand All @@ -2885,9 +2893,14 @@ static cell AMX_NATIVE_CALL remove_user_flags(AMX *amx, cell *params) /* 3 param

if (id > 31)
id = 31;

int oldflags = pPlayer->flags[id];

pPlayer->flags[id] &= ~flag;


if(oldflags != pPlayer->flags[id])
executeForwards(FF_ClientFlagsUpdated, static_cast<cell>(pPlayer->index), oldflags, pPlayer->flags[id], id);

return 1;
}

Expand Down
1 change: 1 addition & 0 deletions amxmodx/amxmodx.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ extern int FF_InconsistentFile;
extern int FF_ClientAuthorized;
extern int FF_ChangeLevel;
extern int FF_ClientConnectEx;
extern int FF_ClientFlagsUpdated;

extern bool g_coloredmenus;

Expand Down
2 changes: 2 additions & 0 deletions amxmodx/meta_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ int FF_InconsistentFile = -1;
int FF_ClientAuthorized = -1;
int FF_ChangeLevel = -1;
int FF_ClientConnectEx = -1;
int FF_ClientFlagsUpdated = -1;

IFileSystem* g_FileSystem;
HLTypeConversion TypeConversion;
Expand Down Expand Up @@ -516,6 +517,7 @@ int C_Spawn(edict_t *pent)
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);
FF_ClientFlagsUpdated = registerForward("client_flags_updated", ET_IGNORE, FP_CELL, FP_CELL, FP_CELL, FP_CELL, FP_DONE);

CoreCfg.OnAmxxInitialized();

Expand Down
15 changes: 14 additions & 1 deletion plugins/include/amxmodx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ forward client_connect(id);
*/
forward client_connectex(id, const name[], const ip[], reason[128]);

/**
* Called after the client's admin flags are changed.
*
* @param id Client index
* @param oldflags Old client flags
* @param newflags New client flags
* @param set Flag set id
*
* @noreturn
*/
forward client_flags_updated(id, oldflags, newflags, set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use same terminology that is used in set_user_flags?
Client ID is index
Set ID is just id


/**
* Called when the client gets a valid SteamID.
*
Expand Down Expand Up @@ -1809,12 +1821,13 @@ native task_exists(id = 0, outside = 0);
* @param index Client index, 0 to set flags of server
* @param flags Admin flags
* @param id Flag set id, ranging from 0 to 31
* @param override If set to true, all other flags will be removed
*
* @noreturn
* @error If the index is not within the range of 0 to MaxClients, an
* error will be thrown.
*/
native set_user_flags(index, flags = -1, id = 0);
native set_user_flags(index, flags = -1, id = 0, bool:override = false);

/**
* Returns the client's admin flags as a bitflag sum.
Expand Down