aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorScureX <47725553+ScureX@users.noreply.github.com>2022-08-10 22:30:52 +0200
committerGitHub <noreply@github.com>2022-08-10 22:30:52 +0200
commit7fca4bd954f26176fda449d72722d1db4dbe4a9d (patch)
tree7d75b1b882789ef7b4e170e40d03adefc753d988 /NorthstarDedicatedTest
parent5e7668c2cd7ef9d017536f1e2e4ec89708f5b74f (diff)
downloadNorthstarLauncher-7fca4bd954f26176fda449d72722d1db4dbe4a9d.tar.gz
NorthstarLauncher-7fca4bd954f26176fda449d72722d1db4dbe4a9d.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
Diffstat (limited to 'NorthstarDedicatedTest')
-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);