aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-01-02 03:06:04 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2022-01-02 03:06:04 +0000
commit5514ff036dbdbf7f4000934223a0d21bf0b9085d (patch)
treef0320ef7f2ccd029bc04339d6f4b63e4ffdab7e8
parent4ad3342f6ce8ac4e9976f5eab5410c58b420a6a4 (diff)
downloadNorthstarLauncher-5514ff036dbdbf7f4000934223a0d21bf0b9085d.tar.gz
NorthstarLauncher-5514ff036dbdbf7f4000934223a0d21bf0b9085d.zip
initial work for ban system
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj2
-rw-r--r--NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters6
-rw-r--r--NorthstarDedicatedTest/bansystem.cpp58
-rw-r--r--NorthstarDedicatedTest/bansystem.h17
-rw-r--r--NorthstarDedicatedTest/miscserverscript.h3
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp7
6 files changed, 90 insertions, 3 deletions
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index 67e9126f..bd0d9eb6 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -176,6 +176,7 @@
</PreBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
+ <ClInclude Include="bansystem.h" />
<ClInclude Include="chatcommand.h" />
<ClInclude Include="clientauthhooks.h" />
<ClInclude Include="concommand.h" />
@@ -612,6 +613,7 @@
<ClInclude Include="squirrel.h" />
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="bansystem.cpp" />
<ClCompile Include="chatcommand.cpp" />
<ClCompile Include="clientauthhooks.cpp" />
<ClCompile Include="concommand.cpp" />
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index 6e379a71..8d6bc246 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -1425,6 +1425,9 @@
<ClInclude Include="rpakfilesystem.h">
<Filter>Header Files\Shared</Filter>
</ClInclude>
+ <ClInclude Include="bansystem.h">
+ <Filter>Header Files\Server\Authentication</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
@@ -1538,6 +1541,9 @@
<ClCompile Include="rpakfilesystem.cpp">
<Filter>Source Files\Shared</Filter>
</ClCompile>
+ <ClCompile Include="bansystem.cpp">
+ <Filter>Source Files\Server\Authentication</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="include\spdlog\fmt\bundled\LICENSE.rst">
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
new file mode 100644
index 00000000..16c25b6b
--- /dev/null
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -0,0 +1,58 @@
+#pragma once
+#include "pch.h"
+#include "bansystem.h"
+#include "serverauthentication.h"
+#include "concommand.h"
+#include <filesystem>
+
+const char* BANLIST_PATH = "R2Northstar/banlist.txt";
+
+ServerBanSystem* g_ServerBanSystem;
+
+void ServerBanSystem::OpenBanlist()
+{
+ std::filesystem::create_directories(BANLIST_PATH);
+
+ std::ifstream enabledModsStream(BANLIST_PATH);
+ std::stringstream enabledModsStringStream;
+
+ if (!enabledModsStream.fail())
+ {
+ std::string line;
+ while (std::getline(enabledModsStream, line))
+ m_vBannedUids.push_back(strtoll(line.c_str(), nullptr, 10));
+
+ enabledModsStream.close();
+ }
+
+ // open write stream for banlist
+ m_sBanlistStream.open(BANLIST_PATH, std::ios::in | std::ios::binary);
+}
+
+void ServerBanSystem::BanUID(uint64_t uid)
+{
+ m_vBannedUids.push_back(uid);
+
+ m_sBanlistStream << std::to_string(uid) << std::endl;
+}
+
+bool ServerBanSystem::IsUIDAllowed(uint64_t uid)
+{
+ return std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid) == m_vBannedUids.end();
+}
+
+void BanPlayerCommand(const CCommand& args)
+{
+ if (args.ArgC() < 2)
+ return;
+
+
+}
+
+void InitialiseBanSystem(HMODULE baseAddress)
+{
+ g_ServerBanSystem = new ServerBanSystem;
+ g_ServerBanSystem->OpenBanlist();
+
+ RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL);
+} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h
new file mode 100644
index 00000000..ea715ea2
--- /dev/null
+++ b/NorthstarDedicatedTest/bansystem.h
@@ -0,0 +1,17 @@
+#pragma once
+
+class ServerBanSystem
+{
+private:
+ std::ofstream m_sBanlistStream;
+ std::vector<uint64_t> m_vBannedUids;
+
+public:
+ void OpenBanlist();
+ void BanUID(uint64_t uid);
+ bool IsUIDAllowed(uint64_t uid);
+};
+
+extern ServerBanSystem* g_ServerBanSystem;
+
+void InitialiseBanSystem(HMODULE baseAddress); \ No newline at end of file
diff --git a/NorthstarDedicatedTest/miscserverscript.h b/NorthstarDedicatedTest/miscserverscript.h
index b3e0580a..8197e502 100644
--- a/NorthstarDedicatedTest/miscserverscript.h
+++ b/NorthstarDedicatedTest/miscserverscript.h
@@ -1 +1,2 @@
-void InitialiseMiscServerScriptCommand(HMODULE baseAddress); \ No newline at end of file
+void InitialiseMiscServerScriptCommand(HMODULE baseAddress);
+void* GetPlayerByIndex(int playerIndex); \ No newline at end of file
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index c4208130..0fdb8664 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -5,6 +5,7 @@
#include "masterserver.h"
#include "httplib.h"
#include "gameutils.h"
+#include "bansystem.h"
#include <fstream>
#include <filesystem>
#include <thread>
@@ -116,8 +117,10 @@ void ServerAuthenticationManager::StopPlayerAuthServer()
bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, char* authToken)
{
- std::string strUid = std::to_string(uid);
+ if (!g_ServerBanSystem->IsUIDAllowed(uid))
+ return false;
+ std::string strUid = std::to_string(uid);
std::lock_guard<std::mutex> guard(m_authDataMutex);
bool authFail = true;
@@ -221,7 +224,7 @@ void ServerAuthenticationManager::WritePersistentData(void* player)
// store these in vars so we can use them in CBaseClient::Connect
// this is fine because ptrs won't decay by the time we use this, just don't use it outside of cbaseclient::connect
char* nextPlayerToken;
-int64_t nextPlayerUid;
+uint64_t nextPlayerUid;
void* CBaseServer__ConnectClientHook(void* server, void* a2, void* a3, uint32_t a4, uint32_t a5, int32_t a6, void* a7, void* a8, char* serverFilter, void* a10, char a11, void* a12, char a13, char a14, int64_t uid, uint32_t a16, uint32_t a17)
{