diff options
Diffstat (limited to 'NorthstarDLL')
-rw-r--r-- | NorthstarDLL/bansystem.cpp | 25 | ||||
-rw-r--r-- | NorthstarDLL/bansystem.h | 1 |
2 files changed, 24 insertions, 2 deletions
diff --git a/NorthstarDLL/bansystem.cpp b/NorthstarDLL/bansystem.cpp index 4a5ef30b..922077d5 100644 --- a/NorthstarDLL/bansystem.cpp +++ b/NorthstarDLL/bansystem.cpp @@ -46,8 +46,24 @@ void ServerBanSystem::OpenBanlist() banlistStream.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() @@ -57,6 +73,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) @@ -66,11 +83,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); } @@ -150,11 +169,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/NorthstarDLL/bansystem.h b/NorthstarDLL/bansystem.h index fd38c04e..6f180126 100644 --- a/NorthstarDLL/bansystem.h +++ b/NorthstarDLL/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); |