aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-08-25 00:24:18 +0200
committerGitHub <noreply@github.com>2022-08-24 23:24:18 +0100
commite289eaa1f7a77de79bcc640b055f8d28cf1d66ea (patch)
tree38e0a4ce97fca9d9e054f7cdce8f4b24a466e25e
parent1fa0c550770612f1873a5304dc0ee0ba2811f8fd (diff)
downloadNorthstarLauncher-e289eaa1f7a77de79bcc640b055f8d28cf1d66ea.tar.gz
NorthstarLauncher-e289eaa1f7a77de79bcc640b055f8d28cf1d66ea.zip
Update refactor (#250)
* Add PR template * Update CI folder location * Delete startup args txt files * Add editorconfig file (#246) * Add editorconfig file It's a cross-editor compatible config file that defines certain editor behaviour (e.g. adding/removing newline at end of file) It is supported by major editors like Visual Studio (Code) and by version control providers like GitHub. Should end the constant adding/removing of final newline in PRs * More settings - unicode by default - trim newlines - use tabs for indentation (ugh) * Ignore folder rename (#245) * Hot reload banlist on player join (#233) * added banlist hotreload * fix formatting * didnt append, cleared whole file oopsie * unfuckedunban not rewriting file * fixed not checking for new line Co-authored-by: ScureX <47725553+ScureX@users.noreply.github.com>
-rw-r--r--.editorconfig11
-rw-r--r--.git-blame-ignore-revs3
-rw-r--r--NorthstarDLL/bansystem.cpp25
-rw-r--r--NorthstarDLL/bansystem.h1
4 files changed, 38 insertions, 2 deletions
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 00000000..bc423183
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,11 @@
+# For more info on `.editorconfig` file see https://EditorConfig.org
+
+# top-most EditorConfig file
+root = true
+
+# Newline ending every file
+[*]
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+indent_style = tab
diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs
index 6838b387..10640d70 100644
--- a/.git-blame-ignore-revs
+++ b/.git-blame-ignore-revs
@@ -2,3 +2,6 @@
# Format commit
75bf194b2fca06de805a7bc025c6dd8379250fa5
+
+# Folder rename
+f9bc3c9d1834cb8bd5f872b749b057c33e8b0102
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);