added functions for target immunity testing

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40546
This commit is contained in:
David Anderson 2007-02-27 03:32:14 +00:00
parent 52de18813c
commit 09887584f4
4 changed files with 63 additions and 0 deletions

View File

@ -418,6 +418,11 @@ static cell_t FlagBitsToArray(IPluginContext *pContext, const cell_t *params)
} }
} }
static cell_t CanAdminTarget(IPluginContext *pContext, const cell_t *params)
{
return g_Admins.CanAdminTarget(params[1], params[2]) ? 1 : 0;
}
REGISTER_NATIVES(adminNatives) REGISTER_NATIVES(adminNatives)
{ {
{"DumpAdminCache", DumpAdminCache}, {"DumpAdminCache", DumpAdminCache},
@ -454,6 +459,7 @@ REGISTER_NATIVES(adminNatives)
{"FlagBitArrayToBits", FlagBitArrayToBits}, {"FlagBitArrayToBits", FlagBitArrayToBits},
{"FlagArrayToBits", FlagArrayToBits}, {"FlagArrayToBits", FlagArrayToBits},
{"FlagBitsToArray", FlagBitsToArray}, {"FlagBitsToArray", FlagBitsToArray},
{"CanAdminTarget", CanAdminTarget},
/* -------------------------------------------------- */ /* -------------------------------------------------- */
{NULL, NULL}, {NULL, NULL},
}; };

View File

@ -345,6 +345,30 @@ static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
return engine->GetPlayerUserId(pPlayer->GetEdict()); return engine->GetPlayerUserId(pPlayer->GetEdict());
} }
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
int target = params[2];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid client", client);
} else if (!pPlayer->IsConnected()) {
return pContext->ThrowNativeError("Player %d is not connected", client);
}
CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
if (!pTarget)
{
return pContext->ThrowNativeError("Player %d is not a valid client", target);
} else if (!pTarget->IsConnected()) {
return pContext->ThrowNativeError("Player %d is not connected", target);
}
return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
}
REGISTER_NATIVES(playernatives) REGISTER_NATIVES(playernatives)
{ {
{"GetMaxClients", sm_GetMaxClients}, {"GetMaxClients", sm_GetMaxClients},
@ -364,6 +388,7 @@ REGISTER_NATIVES(playernatives)
{"SetUserFlagBits", SetUserFlagBits}, {"SetUserFlagBits", SetUserFlagBits},
{"GetUserFlagBits", GetUserFlagBits}, {"GetUserFlagBits", GetUserFlagBits},
{"GetClientUserId", GetClientUserId}, {"GetClientUserId", GetClientUserId},
{"CanUserTarget", CanUserTarget},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -462,12 +462,33 @@ native FlagArrayToBits(const AdminFlag:array[], numFlags) =0;
*/ */
native FlagBitsToArray(bits, AdminFlag:array[], maxSize) =0; native FlagBitsToArray(bits, AdminFlag:array[], maxSize) =0;
/**
* Tests whether one admin can target another.
*
* @param admin Admin doing the targetting (may be INVALID_ADMIN_ID).
* @param target Target admin (may be INVALID_ADMIN_ID).
* @return True if targetable, false if immune.
*/
native CanAdminTarget(AdminId:admin, AdminId:target);
/**
* Converts a flag to its single bit.
*
* @param flag Flag to convert.
* @return Bit representation of the flag.
*/
stock FlagToBit(AdminFlag:flag) stock FlagToBit(AdminFlag:flag)
{ {
return (1<<_:flag); return (1<<_:flag);
} }
/**
* Converts a bit to an AdminFlag.
*
* @param bit Bit to convert.
* @param flag Stores the converted flag by reference.
* @return True on success, false otherwise.
*/
stock bool:BitToFlag(bit, &AdminFlag:flag) stock bool:BitToFlag(bit, &AdminFlag:flag)
{ {
new AdminFlag:array[1]; new AdminFlag:array[1];

View File

@ -328,6 +328,17 @@ native SetUserFlagBits(client, flags);
*/ */
native GetUserFlagBits(client); native GetUserFlagBits(client);
/**
* Returns whether a user can target another user.
* This is a helper function for CanAdminTarget.
*
* @param client Player's index.
* @param target Target player's index.
* @return True if target is targettable by the player, false otherwise.
* @error Invalid or unconnected player indexers.
*/
native bool:CanUserTarget(client, target);
/** /**
* Logs a generic message to the HL2 logs. * Logs a generic message to the HL2 logs.
* *