added functions for target immunity testing
authorDavid Anderson <dvander@alliedmods.net>
Tue Feb 27 03:32:14 2007 +0000 (2007-02-27)
changeset 54027a380082863
parent 539 fa7e8a232a18
child 541 43e600fc2aa7
added functions for target immunity testing
core/smn_admin.cpp
core/smn_player.cpp
plugins/include/admin.inc
plugins/include/sourcemod.inc
     1.1 --- a/core/smn_admin.cpp	Mon Feb 26 09:21:08 2007 +0000
     1.2 +++ b/core/smn_admin.cpp	Tue Feb 27 03:32:14 2007 +0000
     1.3 @@ -418,6 +418,11 @@
     1.4  	}
     1.5  }
     1.6  
     1.7 +static cell_t CanAdminTarget(IPluginContext *pContext, const cell_t *params)
     1.8 +{
     1.9 +	return g_Admins.CanAdminTarget(params[1], params[2]) ? 1 : 0;
    1.10 +}
    1.11 +
    1.12  REGISTER_NATIVES(adminNatives)
    1.13  {
    1.14  	{"DumpAdminCache",			DumpAdminCache},
    1.15 @@ -454,6 +459,7 @@
    1.16  	{"FlagBitArrayToBits",		FlagBitArrayToBits},
    1.17  	{"FlagArrayToBits",			FlagArrayToBits},
    1.18  	{"FlagBitsToArray",			FlagBitsToArray},
    1.19 +	{"CanAdminTarget",			CanAdminTarget},
    1.20  	/* -------------------------------------------------- */
    1.21  	{NULL,						NULL},
    1.22  };
     2.1 --- a/core/smn_player.cpp	Mon Feb 26 09:21:08 2007 +0000
     2.2 +++ b/core/smn_player.cpp	Tue Feb 27 03:32:14 2007 +0000
     2.3 @@ -345,6 +345,30 @@
     2.4  	return engine->GetPlayerUserId(pPlayer->GetEdict());
     2.5  }
     2.6  
     2.7 +static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
     2.8 +{
     2.9 +	int client = params[1];
    2.10 +	int target = params[2];
    2.11 +
    2.12 +	CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
    2.13 +	if (!pPlayer)
    2.14 +	{
    2.15 +		return pContext->ThrowNativeError("Player %d is not a valid client", client);
    2.16 +	} else if (!pPlayer->IsConnected()) {
    2.17 +		return pContext->ThrowNativeError("Player %d is not connected", client);
    2.18 +	}
    2.19 +
    2.20 +	CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
    2.21 +	if (!pTarget)
    2.22 +	{
    2.23 +		return pContext->ThrowNativeError("Player %d is not a valid client", target);
    2.24 +	} else if (!pTarget->IsConnected()) {
    2.25 +		return pContext->ThrowNativeError("Player %d is not connected", target);
    2.26 +	}
    2.27 +
    2.28 +	return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
    2.29 +}
    2.30 +
    2.31  REGISTER_NATIVES(playernatives)
    2.32  {
    2.33  	{"GetMaxClients",			sm_GetMaxClients},
    2.34 @@ -364,6 +388,7 @@
    2.35  	{"SetUserFlagBits",			SetUserFlagBits},
    2.36  	{"GetUserFlagBits",			GetUserFlagBits},
    2.37  	{"GetClientUserId",			GetClientUserId},
    2.38 +	{"CanUserTarget",			CanUserTarget},
    2.39  	{NULL,						NULL}
    2.40  };
    2.41  
     3.1 --- a/plugins/include/admin.inc	Mon Feb 26 09:21:08 2007 +0000
     3.2 +++ b/plugins/include/admin.inc	Tue Feb 27 03:32:14 2007 +0000
     3.3 @@ -462,12 +462,33 @@
     3.4   */
     3.5  native FlagBitsToArray(bits, AdminFlag:array[], maxSize) =0;
     3.6  
     3.7 +/**
     3.8 + * Tests whether one admin can target another.
     3.9 + *
    3.10 + * @param admin			Admin doing the targetting (may be INVALID_ADMIN_ID).
    3.11 + * @param target		Target admin (may be INVALID_ADMIN_ID).
    3.12 + * @return				True if targetable, false if immune.
    3.13 + */
    3.14 +native CanAdminTarget(AdminId:admin, AdminId:target);
    3.15  
    3.16 +/**
    3.17 + * Converts a flag to its single bit.
    3.18 + * 
    3.19 + * @param flag			Flag to convert.
    3.20 + * @return				Bit representation of the flag.
    3.21 + */
    3.22  stock FlagToBit(AdminFlag:flag)
    3.23  {
    3.24  	return (1<<_:flag);
    3.25  }
    3.26  
    3.27 +/**
    3.28 + * Converts a bit to an AdminFlag.
    3.29 + *
    3.30 + * @param bit			Bit to convert.
    3.31 + * @param flag			Stores the converted flag by reference.
    3.32 + * @return				True on success, false otherwise.
    3.33 + */
    3.34  stock bool:BitToFlag(bit, &AdminFlag:flag)
    3.35  {
    3.36  	new AdminFlag:array[1];
     4.1 --- a/plugins/include/sourcemod.inc	Mon Feb 26 09:21:08 2007 +0000
     4.2 +++ b/plugins/include/sourcemod.inc	Tue Feb 27 03:32:14 2007 +0000
     4.3 @@ -329,6 +329,17 @@
     4.4  native GetUserFlagBits(client);
     4.5  
     4.6  /**
     4.7 + * Returns whether a user can target another user.
     4.8 + * This is a helper function for CanAdminTarget.
     4.9 + *
    4.10 + * @param client		Player's index.
    4.11 + * @param target		Target player's index.
    4.12 + * @return				True if target is targettable by the player, false otherwise.
    4.13 + * @error				Invalid or unconnected player indexers.
    4.14 + */
    4.15 +native bool:CanUserTarget(client, target);
    4.16 +
    4.17 +/**
    4.18   * Logs a generic message to the HL2 logs.
    4.19   *
    4.20   * @param format		String format.