diff options
author | ScureX <47725553+ScureX@users.noreply.github.com> | 2022-08-14 11:37:18 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2022-08-14 14:57:57 +0200 |
commit | 8b26d4a857937094e36a692c85501406e69aed0e (patch) | |
tree | 54df4a7e775373fd5c2886885bc02d83c870d2bc | |
parent | 9c9b57691498f080bdca4b70859f75f3f9e8b422 (diff) | |
download | NorthstarLauncher-1.9.4-rc1.tar.gz NorthstarLauncher-1.9.4-rc1.zip |
Hot reload banlist on player join (#233)v1.9.4-rc1v1.9.4
* added banlist hotreload
* fix formatting
* didnt append, cleared whole file oopsie
* unfuckedunban not rewriting file
* fixed not checking for new line
-rw-r--r-- | NorthstarDedicatedTest/bansystem.cpp | 25 | ||||
-rw-r--r-- | NorthstarDedicatedTest/bansystem.h | 1 |
2 files changed, 24 insertions, 2 deletions
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp index 88c7d042..b96e69e3 100644 --- a/NorthstarDedicatedTest/bansystem.cpp +++ b/NorthstarDedicatedTest/bansystem.cpp @@ -44,8 +44,24 @@ void ServerBanSystem::OpenBanlist() enabledModsStream.close(); } - // open write stream for banlist - m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary | std::ofstream::app); + // open write stream for banlist // dont do this to allow for all time access + // m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary | std::ofstream::app); +} + +void ServerBanSystem::ReloadBanlist() +{ + std::ifstream fsBanlist(GetNorthstarPrefix() + "/banlist.txt"); + + if (!fsBanlist.fail()) + { + std::string line; + // since we wanna use this as the reload func we need to clear the list + m_vBannedUids.clear(); + while (std::getline(fsBanlist, line)) + m_vBannedUids.push_back(strtoull(line.c_str(), nullptr, 10)); + + fsBanlist.close(); + } } void ServerBanSystem::ClearBanlist() @@ -55,6 +71,7 @@ void ServerBanSystem::ClearBanlist() // reopen the file, don't provide std::ofstream::app so it clears on open m_sBanlistStream.close(); m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary); + m_sBanlistStream.close(); } void ServerBanSystem::BanUID(uint64_t uid) @@ -64,11 +81,13 @@ void ServerBanSystem::BanUID(uint64_t uid) std::string content((std::istreambuf_iterator<char>(fsBanlist)), (std::istreambuf_iterator<char>())); fsBanlist.close(); + m_sBanlistStream.open(GetNorthstarPrefix() + "/banlist.txt", std::ofstream::out | std::ofstream::binary | std::ofstream::app); if (content.back() != '\n') m_sBanlistStream << std::endl; m_vBannedUids.push_back(uid); m_sBanlistStream << std::to_string(uid) << std::endl; + m_sBanlistStream.close(); spdlog::info("{} was banned", uid); } @@ -148,11 +167,13 @@ void ServerBanSystem::UnbanUID(uint64_t uid) for (std::string updatedLine : banlistText) m_sBanlistStream << updatedLine << std::endl; + m_sBanlistStream.close(); spdlog::info("{} was unbanned", uid); } bool ServerBanSystem::IsUIDAllowed(uint64_t uid) { + ReloadBanlist(); // Reload to have up to date list on join return std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid) == m_vBannedUids.end(); } diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h index 0f618843..e78094bf 100644 --- a/NorthstarDedicatedTest/bansystem.h +++ b/NorthstarDedicatedTest/bansystem.h @@ -9,6 +9,7 @@ class ServerBanSystem public: void OpenBanlist(); + void ReloadBanlist(); void ClearBanlist(); void BanUID(uint64_t uid); void UnbanUID(uint64_t uid); |