aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScureX <47725553+ScureX@users.noreply.github.com>2022-08-10 22:30:52 +0200
committerGeckoEidechse <gecko.eidechse+git@pm.me>2022-08-14 14:57:44 +0200
commit2ece286b9ddcc8f7abb25ba7733a0b8cc7c2a3d1 (patch)
treeca442fd4b88becce3eca76e92fc76699d4b40f82
parentc0e8e576df16171da6f0e68cbfa18123e8d1e7e0 (diff)
downloadNorthstarLauncher-2ece286b9ddcc8f7abb25ba7733a0b8cc7c2a3d1.tar.gz
NorthstarLauncher-2ece286b9ddcc8f7abb25ba7733a0b8cc7c2a3d1.zip
Allow comments and newlines in `banlist.txt` (#227)
* added support for comments and newlines * added checking if line is empty earlier * Fix formatting * check if last char is \n
-rw-r--r--NorthstarDedicatedTest/bansystem.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
index 9333d844..8cb56b3f 100644
--- a/NorthstarDedicatedTest/bansystem.cpp
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -7,6 +7,7 @@
#include "configurables.h"
const char* BANLIST_PATH_SUFFIX = "/banlist.txt";
+const char BANLIST_COMMENT_CHAR = '#';
ServerBanSystem* g_ServerBanSystem;
@@ -19,7 +20,25 @@ void ServerBanSystem::OpenBanlist()
{
std::string line;
while (std::getline(enabledModsStream, line))
- m_vBannedUids.push_back(strtoull(line.c_str(), nullptr, 10));
+ {
+ // ignore line if first char is # or line is empty
+ if (line == "" || line.front() == BANLIST_COMMENT_CHAR)
+ continue;
+
+ // remove tabs which shouldnt be there but maybe someone did the funny
+ line.erase(std::remove(line.begin(), line.end(), '\t'), line.end());
+ // remove spaces to allow for spaces before uids
+ line.erase(std::remove(line.begin(), line.end(), ' '), line.end());
+
+ // check if line is empty to allow for newlines in the file
+ if (line == "")
+ continue;
+
+ // for inline comments like: 123123123 #banned for unfunny
+ std::string uid = line.substr(0, line.find(BANLIST_COMMENT_CHAR));
+
+ m_vBannedUids.push_back(strtoull(uid.c_str(), nullptr, 10));
+ }
enabledModsStream.close();
}
@@ -39,6 +58,14 @@ void ServerBanSystem::ClearBanlist()
void ServerBanSystem::BanUID(uint64_t uid)
{
+ // checking if last char is \n to make sure uids arent getting fucked
+ std::ifstream fsBanlist(GetNorthstarPrefix() + "/banlist.txt");
+ std::string content((std::istreambuf_iterator<char>(fsBanlist)), (std::istreambuf_iterator<char>()));
+ fsBanlist.close();
+
+ if (content.back() != '\n')
+ m_sBanlistStream << std::endl;
+
m_vBannedUids.push_back(uid);
m_sBanlistStream << std::to_string(uid) << std::endl;
spdlog::info("{} was banned", uid);