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 'j' and 'k' flags in get_players for matching with admin flags #476

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
11 changes: 11 additions & 0 deletions amxmodx/amxmodx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,7 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */
{
int iNum = 0;
int ilen;
int pflags = 0;
char* sptemp = get_amxstring(amx, params[3], 0, ilen);
int flags = UTIL_ReadFlags(sptemp);

Expand All @@ -2268,6 +2269,12 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */
team = g_teamsIds.findTeamIdCase(sptemp);
}
}

if ((flags & 512) || (flags & 1024))
{
sptemp = get_amxstring(amx, params[4], 0, ilen);
pflags = UTIL_ReadFlags(sptemp);
}

for (int i = 1; i <= gpGlobals->maxClients; ++i)
{
Expand All @@ -2282,6 +2289,10 @@ static cell AMX_NATIVE_CALL get_players(AMX *amx, cell *params) /* 4 param */
continue;
if ((flags & 128) && (pPlayer->pEdict->v.flags & FL_PROXY))
continue;
if ((flags & 512) && ((pPlayer->flags[0] & pflags) != pflags))
continue;
if ((flags & 1024) && (!(pPlayer->flags[0] & pflags)))
Copy link

Choose a reason for hiding this comment

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

Maybe add consts for all flags?

continue;
if (flags & 32)
{
if (flags & 64)
Expand Down
4 changes: 3 additions & 1 deletion plugins/include/amxconst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,9 @@ enum GetPlayersFlags (<<= 1)
GetPlayers_MatchNameSubstring, // Match with part of name
GetPlayers_CaseInsensitive, // Match case insensitive
GetPlayers_ExcludeHLTV, // Do not include HLTV proxies
GetPlayers_IncludeConnecting // Include connecting clients
GetPlayers_IncludeConnecting, // Include connecting clients
GetPlayers_MatchAllFlags, // Match with all of the specified admin flags
GetPlayers_MatchAnyFlags // Match with any of the specified admin flags
};

/**
Expand Down
8 changes: 5 additions & 3 deletions plugins/include/amxmisc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -859,13 +859,15 @@ stock set_task_ex(Float:time, const function[], id = 0, const any:parameter[] =
* GetPlayers_CaseInsensitive - match case insensitive
* GetPlayers_ExcludeHLTV - do not include HLTV proxies
* GetPlayers_IncludeConnecting - include connecting clients
* @param team String to match against if the "e" or "f" flag is specified
* GetPlayers_MatchAllFlags - match with all of the specified admin flags
* GetPlayers_MatchAnyFlags - match with any of the specified admin flags
* @param string String to match against if the "e", "f", "j" or "k" flag is specified
*
* @noreturn
*/
stock get_players_ex(players[MAX_PLAYERS], &num, GetPlayersFlags:flags = GetPlayers_None, const team[] = "")
stock get_players_ex(players[MAX_PLAYERS], &num, GetPlayersFlags:flags = GetPlayers_None, const string[] = "")
{
new strFlags[10];
get_flags(_:flags, strFlags, charsmax(strFlags));
get_players(players, num, strFlags, team);
get_players(players, num, strFlags, string);
}
6 changes: 4 additions & 2 deletions plugins/include/amxmodx.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1387,11 +1387,13 @@ native get_playersnum(flag = 0);
* "g" - match case insensitive
* "h" - do not include HLTV proxies
* "i" - include connecting clients
* @param team String to match against if the "e" or "f" flag is specified
* "j" - match with all of the specified admin flags
* "k" - match with any of the specified admin flags
* @param string String to match against if the "e", "f", "j" or "k" flag is specified
*
* @noreturn
*/
native get_players(players[MAX_PLAYERS], &num, const flags[] = "", const team[] = "");
native get_players(players[MAX_PLAYERS], &num, const flags[] = "", const string[] = "");
Copy link
Member

Choose a reason for hiding this comment

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

You can't rename params like that. You will break backward compatibility. People can still explicit the param .team = .

Copy link
Member

@Arkshine Arkshine Aug 17, 2018

Choose a reason for hiding this comment

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

I think it's okay to not update get_players anyway. We should encourage the use of flags as a string. We don't need to keep the same functionalities, after all, get_players_ex is an extended version.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Arkshine I changed the param name back to team. I don't think however that get_players shouldn't be updated. get_players_ex is a stock that is depending on get_players.

stock get_players_ex(players[MAX_PLAYERS], &num, GetPlayersFlags:flags = GetPlayers_None, const team[] = "")
{
	new strFlags[12];
	get_flags(_:flags, strFlags, charsmax(strFlags));
	get_players(players, num, strFlags, team);
}

If we don't update get_players, this change will have no effect.


/**
* Retrieves argument of client command as string.
Expand Down