From 5514ff036dbdbf7f4000934223a0d21bf0b9085d Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 2 Jan 2022 03:06:04 +0000 Subject: initial work for ban system --- NorthstarDedicatedTest/bansystem.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 NorthstarDedicatedTest/bansystem.h (limited to 'NorthstarDedicatedTest/bansystem.h') diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h new file mode 100644 index 00000000..ea715ea2 --- /dev/null +++ b/NorthstarDedicatedTest/bansystem.h @@ -0,0 +1,17 @@ +#pragma once + +class ServerBanSystem +{ +private: + std::ofstream m_sBanlistStream; + std::vector m_vBannedUids; + +public: + void OpenBanlist(); + void BanUID(uint64_t uid); + bool IsUIDAllowed(uint64_t uid); +}; + +extern ServerBanSystem* g_ServerBanSystem; + +void InitialiseBanSystem(HMODULE baseAddress); \ No newline at end of file -- cgit v1.2.3 From 67e73b19be90c51cfb4c5efbbbb6f220ba1c688d Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 2 Jan 2022 03:08:29 +0000 Subject: Update bansystem.h --- NorthstarDedicatedTest/bansystem.h | 1 + 1 file changed, 1 insertion(+) (limited to 'NorthstarDedicatedTest/bansystem.h') diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h index ea715ea2..b316fc6f 100644 --- a/NorthstarDedicatedTest/bansystem.h +++ b/NorthstarDedicatedTest/bansystem.h @@ -1,4 +1,5 @@ #pragma once +#include class ServerBanSystem { -- cgit v1.2.3 From 49acb6d831919022745b68f474b65c19f4e62bcd Mon Sep 17 00:00:00 2001 From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com> Date: Sun, 2 Jan 2022 04:07:42 +0000 Subject: add unban command --- NorthstarDedicatedTest/bansystem.cpp | 24 ++++++++++++++++++++++++ NorthstarDedicatedTest/bansystem.h | 1 + 2 files changed, 25 insertions(+) (limited to 'NorthstarDedicatedTest/bansystem.h') diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp index 40813f17..182506e8 100644 --- a/NorthstarDedicatedTest/bansystem.cpp +++ b/NorthstarDedicatedTest/bansystem.cpp @@ -32,6 +32,19 @@ void ServerBanSystem::BanUID(uint64_t uid) { m_vBannedUids.push_back(uid); m_sBanlistStream << std::to_string(uid) << std::endl; + spdlog::info("{} was banned", uid); +} + +void ServerBanSystem::UnbanUID(uint64_t uid) +{ + auto findResult = std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid); + if (findResult == m_vBannedUids.end()) + return; + + m_vBannedUids.erase(findResult); + spdlog::info("{} was unbanned", uid); + // todo: this needs to erase from the banlist file + // atm unsure how to do this aside from just clearing and fully rewriting the file } bool ServerBanSystem::IsUIDAllowed(uint64_t uid) @@ -44,6 +57,7 @@ void BanPlayerCommand(const CCommand& args) if (args.ArgC() < 2) return; + // assuming maxplayers 32 for (int i = 0; i < 32; i++) { void* player = GetPlayerByIndex(i); @@ -57,10 +71,20 @@ void BanPlayerCommand(const CCommand& args) } } +void UnbanPlayerCommand(const CCommand& args) +{ + if (args.ArgC() < 2) + return; + + // assumedly the player being unbanned here wasn't already connected, so don't need to iterate over players or anything + g_ServerBanSystem->UnbanUID(strtoll(args.Arg(1), nullptr, 10)); +} + void InitialiseBanSystem(HMODULE baseAddress) { g_ServerBanSystem = new ServerBanSystem; g_ServerBanSystem->OpenBanlist(); RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL); + RegisterConCommand("unban", UnbanPlayerCommand, "unbans a given player by uid", FCVAR_NONE); } \ No newline at end of file diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h index b316fc6f..a1646356 100644 --- a/NorthstarDedicatedTest/bansystem.h +++ b/NorthstarDedicatedTest/bansystem.h @@ -10,6 +10,7 @@ private: public: void OpenBanlist(); void BanUID(uint64_t uid); + void UnbanUID(uint64_t uid); bool IsUIDAllowed(uint64_t uid); }; -- cgit v1.2.3