From b13cc071a9c1679cbfe575041bf3a150793b4491 Mon Sep 17 00:00:00 2001 From: Amos Date: Thu, 22 Jun 2023 09:09:38 +0200 Subject: [PATCH] Improve ban commands The ban commands have the 'sv_' prefix removed. CBaseEntity::InputKill expects 'kickid' to be present, it uses this to kick the player once the entity has been destroyed. Not doing so could lead into a crash or other undesired behavior. --- r5dev/common/callback.cpp | 70 ++++++++++++++++++++++----------- r5dev/common/global.cpp | 10 ++--- r5dev/networksystem/bansystem.h | 8 ++++ 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/r5dev/common/callback.cpp b/r5dev/common/callback.cpp index 59770feb..62b90557 100644 --- a/r5dev/common/callback.cpp +++ b/r5dev/common/callback.cpp @@ -109,17 +109,59 @@ void ToggleBrowser_f(const CCommand& args) /* ===================== Host_Kick_f + + helper function for + bansystem ===================== */ -void Host_Kick_f(const CCommand& args) +void _Author_Client_f(const CCommand& args, EKickType type) { if (args.ArgC() < 2) { return; } - g_pBanSystem->KickPlayerByName(args.Arg(1), - args.ArgC() > 2 ? args.Arg(2) : nullptr); + const char* szReason = args.ArgC() > 2 ? args.Arg(2) : nullptr; + + switch(type) + { + case KICK_NAME: + { + g_pBanSystem->KickPlayerByName(args.Arg(1), szReason); + break; + } + case KICK_ID: + { + g_pBanSystem->KickPlayerById(args.Arg(1), szReason); + break; + } + case BAN_NAME: + { + g_pBanSystem->BanPlayerByName(args.Arg(1), szReason); + break; + } + case BAN_ID: + { + g_pBanSystem->BanPlayerById(args.Arg(1), szReason); + break; + } + default: + { + // Code bug. + Assert(0); + } + } +} + + +/* +===================== +Host_Kick_f +===================== +*/ +void Host_Kick_f(const CCommand& args) +{ + _Author_Client_f(args, EKickType::KICK_NAME); } /* @@ -129,13 +171,7 @@ Host_KickID_f */ void Host_KickID_f(const CCommand& args) { - if (args.ArgC() < 2) // Do we at least have 2 arguments? - { - return; - } - - g_pBanSystem->KickPlayerById(args.Arg(1), - args.ArgC() > 2 ? args.Arg(2) : nullptr); + _Author_Client_f(args, EKickType::KICK_ID); } /* @@ -145,13 +181,7 @@ Host_Ban_f */ void Host_Ban_f(const CCommand& args) { - if (args.ArgC() < 2) - { - return; - } - - g_pBanSystem->BanPlayerByName(args.Arg(1), - args.ArgC() > 2 ? args.Arg(2) : nullptr); + _Author_Client_f(args, EKickType::BAN_NAME); } /* @@ -161,11 +191,7 @@ Host_BanID_f */ void Host_BanID_f(const CCommand& args) { - if (args.ArgC() < 2) - return; - - g_pBanSystem->BanPlayerById(args.Arg(1), - args.ArgC() > 2 ? args.Arg(2) : nullptr); + _Author_Client_f(args, EKickType::BAN_ID); } /* diff --git a/r5dev/common/global.cpp b/r5dev/common/global.cpp index 61deb117..a5b5c97c 100644 --- a/r5dev/common/global.cpp +++ b/r5dev/common/global.cpp @@ -606,11 +606,11 @@ void ConCommand_StaticInit(void) // SERVER DLL | #ifndef CLIENT_DLL ConCommand::StaticCreate("script", "Run input code as SERVER script on the VM.", nullptr, FCVAR_GAMEDLL | FCVAR_CHEAT, SQVM_ServerScript_f, nullptr); - ConCommand::StaticCreate("sv_kick", "Kick a client from the server by user name.", "sv_kick \"\"", FCVAR_RELEASE, Host_Kick_f, nullptr); - ConCommand::StaticCreate("sv_kickid", "Kick a client from the server by handle, nucleus id or ip address.", "sv_kickid \"\"/\"/\"", FCVAR_RELEASE, Host_KickID_f, nullptr); - ConCommand::StaticCreate("sv_ban", "Bans a client from the server by user name.", "sv_ban ", FCVAR_RELEASE, Host_Ban_f, nullptr); - ConCommand::StaticCreate("sv_banid", "Bans a client from the server by handle, nucleus id or ip address.", "sv_banid \"\"/\"/\"", FCVAR_RELEASE, Host_BanID_f, nullptr); - ConCommand::StaticCreate("sv_unban", "Unbans a client from the server by nucleus id or ip address.", "sv_unban \"\"/\"\"", FCVAR_RELEASE, Host_Unban_f, nullptr); + ConCommand::StaticCreate("kick", "Kick a client from the server by user name.", "kick \"\"", FCVAR_RELEASE, Host_Kick_f, nullptr); + ConCommand::StaticCreate("kickid", "Kick a client from the server by handle, nucleus id or ip address.", "kickid \"\"/\"/\"", FCVAR_RELEASE, Host_KickID_f, nullptr); + ConCommand::StaticCreate("ban", "Bans a client from the server by user name.", "ban ", FCVAR_RELEASE, Host_Ban_f, nullptr); + ConCommand::StaticCreate("banid", "Bans a client from the server by handle, nucleus id or ip address.", "banid \"\"/\"/\"", FCVAR_RELEASE, Host_BanID_f, nullptr); + ConCommand::StaticCreate("unban", "Unbans a client from the server by nucleus id or ip address.", "unban \"\"/\"\"", FCVAR_RELEASE, Host_Unban_f, nullptr); ConCommand::StaticCreate("sv_reloadbanlist", "Reloads the banned list.", nullptr, FCVAR_RELEASE, Host_ReloadBanList_f, nullptr); ConCommand::StaticCreate("sv_addbot", "Creates a bot on the server.", nullptr, FCVAR_RELEASE, CC_CreateFakePlayer_f, nullptr); ConCommand::StaticCreate("navmesh_hotswap", "Hot swap the NavMesh for all hulls.", nullptr, FCVAR_DEVELOPMENTONLY, Detour_HotSwap_f, nullptr); diff --git a/r5dev/networksystem/bansystem.h b/r5dev/networksystem/bansystem.h index 0820bf01..aad59916 100644 --- a/r5dev/networksystem/bansystem.h +++ b/r5dev/networksystem/bansystem.h @@ -2,6 +2,14 @@ typedef vector> BannedVec_t; +enum EKickType +{ + KICK_NAME = 0, + KICK_ID, + BAN_NAME, + BAN_ID +}; + class CBanSystem { public: