From 6f58bb30d4f36d861d7a34dec7da1481de1a0106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=98=E4=B9=8B=E9=9F=B3?= <639821869@qq.com> Date: Fri, 27 Mar 2026 06:41:49 +0800 Subject: [PATCH] Add unban ConCommand Completion (#907) Add unban Concommand Completion --- primedev/server/auth/bansystem.cpp | 39 +++++++++++++++++++++++++++++- primedev/server/auth/bansystem.h | 1 + 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/primedev/server/auth/bansystem.cpp b/primedev/server/auth/bansystem.cpp index 20c07844..a81432be 100644 --- a/primedev/server/auth/bansystem.cpp +++ b/primedev/server/auth/bansystem.cpp @@ -184,6 +184,11 @@ bool ServerBanSystem::IsUIDAllowed(uint64_t uid) return std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid) == m_vBannedUids.end(); } +const std::vector& ServerBanSystem::GetBannedUids() const +{ + return m_vBannedUids; +} + void ConCommand_ban(const CCommand& args) { if (args.ArgC() < 2) @@ -257,13 +262,45 @@ int ConCommand_banCompletion(const char* const partial, char commands[COMMAND_CO return numCompletions; } +int ConCommand_unbanCompletion(const char* const partial, char commands[COMMAND_COMPLETION_MAXITEMS][COMMAND_COMPLETION_ITEM_LENGTH]) +{ + const char* space = strchr(partial, ' '); + const char* cmdName = partial; + const char* query = partial + (space == nullptr ? 0 : space - partial) + 1; + + const size_t queryLength = strlen(query); + const size_t cmdLength = strlen(cmdName) - queryLength; + + g_pBanSystem->ReloadBanlist(); + + int numCompletions = 0; + for (uint64_t bannedUid : g_pBanSystem->GetBannedUids()) + { + if (numCompletions >= COMMAND_COMPLETION_MAXITEMS - 2) + break; + + std::string uid = std::to_string(bannedUid); + if (strncmp(query, uid.c_str(), queryLength)) + continue; + + strncpy(commands[numCompletions], cmdName, cmdLength); + strncpy_s( + commands[numCompletions++] + cmdLength, + COMMAND_COMPLETION_ITEM_LENGTH, + uid.c_str(), + COMMAND_COMPLETION_ITEM_LENGTH - cmdLength); + } + + return numCompletions; +} + ON_DLL_LOAD_RELIESON("engine.dll", BanSystem, ConCommand, (CModule module)) { g_pBanSystem = new ServerBanSystem; g_pBanSystem->OpenBanlist(); RegisterConCommand("ban", ConCommand_ban, "bans a given player by uid or name", FCVAR_GAMEDLL, ConCommand_banCompletion); - RegisterConCommand("unban", ConCommand_unban, "unbans a given player by uid", FCVAR_GAMEDLL); + RegisterConCommand("unban", ConCommand_unban, "unbans a given player by uid", FCVAR_GAMEDLL, ConCommand_unbanCompletion); RegisterConCommand("clearbanlist", ConCommand_clearbanlist, "clears all uids on the banlist", FCVAR_GAMEDLL); } diff --git a/primedev/server/auth/bansystem.h b/primedev/server/auth/bansystem.h index d6ac5a4f..fb5328e0 100644 --- a/primedev/server/auth/bansystem.h +++ b/primedev/server/auth/bansystem.h @@ -14,6 +14,7 @@ public: void BanUID(uint64_t uid); void UnbanUID(uint64_t uid); bool IsUIDAllowed(uint64_t uid); + const std::vector& GetBannedUids() const; }; extern ServerBanSystem* g_pBanSystem;