From 2c5cd635526b45d585f663d9b7f7b49507408ffc Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 1 Oct 2007 18:41:39 +0000 Subject: [PATCH] added IsClientInKickQueue() to deal with a bot issue --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401515 --- core/PlayerManager.cpp | 12 ++++++++++++ core/PlayerManager.h | 3 +++ core/smn_player.cpp | 21 +++++++++++++++++++++ plugins/include/clients.inc | 13 ++++++++++++- 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 0f7c7640..c74e7daa 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -805,6 +805,7 @@ CPlayer::CPlayer() m_TempAdmin = false; m_Info = NULL; m_bAdminCheckSignalled = false; + m_bIsInKickQueue = false; m_LastPassword.clear(); m_LangId = LANGUAGE_ENGLISH; } @@ -876,6 +877,7 @@ void CPlayer::Disconnect() m_Info = NULL; m_bAdminCheckSignalled = false; m_UserId = -1; + m_bIsInKickQueue = false; } void CPlayer::SetName(const char *name) @@ -1082,3 +1084,13 @@ int CPlayer::GetUserId() return m_UserId; } + +bool CPlayer::IsInKickQueue() +{ + return m_bIsInKickQueue; +} + +void CPlayer::MarkAsBeingKicked() +{ + m_bIsInKickQueue = true; +} diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 983f3cd5..61039d53 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -68,6 +68,8 @@ public: public: void NotifyPostAdminChecks(); void DoBasicAdminChecks(); + bool IsInKickQueue(); + void MarkAsBeingKicked(); private: void Initialize(const char *name, const char *ip, edict_t *pEntity); void Connect(); @@ -81,6 +83,7 @@ private: bool m_IsConnected; bool m_IsInGame; bool m_IsAuthorized; + bool m_bIsInKickQueue; String m_Name; String m_Ip; String m_IpNoPort; diff --git a/core/smn_player.cpp b/core/smn_player.cpp index a82f71db..8b1da987 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -1002,6 +1002,8 @@ static cell_t KickClient(IPluginContext *pContext, const cell_t *params) return pContext->ThrowNativeError("Client %d is not connected", client); } + pPlayer->MarkAsBeingKicked(); + if (pPlayer->IsFakeClient()) { char kickcmd[40]; @@ -1091,6 +1093,24 @@ static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *param return 1; } +static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); + + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + return pPlayer->IsInKickQueue() ? 1 : 0; +} + REGISTER_NATIVES(playernatives) { {"AddUserFlags", AddUserFlags}, @@ -1140,6 +1160,7 @@ REGISTER_NATIVES(playernatives) {"KickClient", KickClient}, {"RunAdminCacheChecks", RunAdminCacheChecks}, {"NotifyPostAdminCheck", NotifyPostAdminCheck}, + {"IsClientInKickQueue", IsClientInKickQueue}, {NULL, NULL} }; diff --git a/plugins/include/clients.inc b/plugins/include/clients.inc index 5c09e215..9a8ba68a 100644 --- a/plugins/include/clients.inc +++ b/plugins/include/clients.inc @@ -205,11 +205,22 @@ native bool:IsClientConnected(client); /** * Returns if a certain player has entered the game. * - * @param client Player index. + * @param client Player index (index does not have to be connected). * @return True if player has entered the game, false otherwise. + * @error Invalid client index. */ native bool:IsClientInGame(client); +/** + * Returns if a client is in the "kick queue" (i.e. the client will be kicked + * shortly and thus they should not appear as valid). + * + * @param client Player index (must be connected). + * @return True if in the kick queue, false otherwise. + * @error Invalid client index. + */ +native bool:IsClientInKickQueue(client); + /** * Backwards compatibility stock - use IsClientInGame * @deprecated Renamed to IsClientInGame