From f2e55278780b2c22067f69672ec5d9d23e40ca9d Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 01:20:02 +0000
Subject: setup for rpak filesystem hooks
---
.../NorthstarDedicatedTest.vcxproj | 2 +
.../NorthstarDedicatedTest.vcxproj.filters | 6 +++
NorthstarDedicatedTest/dllmain.cpp | 9 +++++
NorthstarDedicatedTest/masterserver.h | 2 -
NorthstarDedicatedTest/rpakfilesystem.cpp | 44 ++++++++++++++++++++++
NorthstarDedicatedTest/rpakfilesystem.h | 4 ++
6 files changed, 65 insertions(+), 2 deletions(-)
create mode 100644 NorthstarDedicatedTest/rpakfilesystem.cpp
create mode 100644 NorthstarDedicatedTest/rpakfilesystem.h
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
index 03481a2c..67e9126f 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj
@@ -598,6 +598,7 @@
+
@@ -640,6 +641,7 @@
+
diff --git a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
index e4ddd92c..6e379a71 100644
--- a/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
+++ b/NorthstarDedicatedTest/NorthstarDedicatedTest.vcxproj.filters
@@ -1422,6 +1422,9 @@
Header Files\include\libcurl
+
+ Header Files\Shared
+
@@ -1532,6 +1535,9 @@
Source Files\Server
+
+ Source Files\Shared
+
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 78edb297..6acd4798 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -25,6 +25,7 @@
#include "scriptmainmenupromos.h"
#include "miscclientfixes.h"
#include "miscserverfixes.h"
+#include "rpakfilesystem.h"
#include "memalloc.h"
bool initialised = false;
@@ -66,6 +67,13 @@ void WaitForDebugger(HMODULE baseAddress)
// in the future this will be called from launcher instead of dllmain
void InitialiseNorthstar()
{
+ if (initialised)
+ {
+ spdlog::error("Called InitialiseNorthstar more than once!");
+ return;
+ }
+ initialised = true;
+
InitialiseLogging();
// apply initial hooks
@@ -116,6 +124,7 @@ void InitialiseNorthstar()
AddDllLoadCallback("engine.dll", InitialisePlaylistHooks);
AddDllLoadCallback("filesystem_stdio.dll", InitialiseFilesystem);
+ AddDllLoadCallback("engine.dll", InitialiseEngineRpakFilesystem);
AddDllLoadCallback("engine.dll", InitialiseKeyValues);
// mod manager after everything else
diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h
index 1c57904b..b4d0d476 100644
--- a/NorthstarDedicatedTest/masterserver.h
+++ b/NorthstarDedicatedTest/masterserver.h
@@ -1,6 +1,5 @@
#pragma once
#include "convar.h"
-#include "httplib.h"
#include
struct RemoteModInfo
@@ -67,7 +66,6 @@ class MasterServerManager
private:
bool m_requestingServerList = false;
bool m_authenticatingWithGameServer = false;
- httplib::Client* m_httpClient = nullptr;
public:
char m_ownServerId[33];
diff --git a/NorthstarDedicatedTest/rpakfilesystem.cpp b/NorthstarDedicatedTest/rpakfilesystem.cpp
new file mode 100644
index 00000000..006a57c5
--- /dev/null
+++ b/NorthstarDedicatedTest/rpakfilesystem.cpp
@@ -0,0 +1,44 @@
+#include "pch.h"
+#include "rpakfilesystem.h"
+#include "hookutils.h"
+#include "modmanager.h"
+
+typedef void*(*LoadCommonPaksForMapType)(char* map);
+LoadCommonPaksForMapType LoadCommonPaksForMap;
+
+typedef void*(*LoadPakSyncType)(char* path, void* unknownSingleton, int flags);
+typedef void*(*LoadPakAsyncType)(char* path, void* unknownSingleton, int flags, void* callback0, void* callback1);
+
+// there are more i'm just too lazy to add
+struct PakLoadFuncs
+{
+ void* unknown[2];
+ LoadPakSyncType func2;
+ LoadPakAsyncType LoadPakAsync;
+};
+
+PakLoadFuncs* g_pakLoadApi;
+void** pUnknownPakLoadSingleton;
+
+void LoadPakAsync(char* path)
+{
+ g_pakLoadApi->LoadPakAsync(path, *pUnknownPakLoadSingleton, 2, nullptr, nullptr);
+}
+
+void LoadCommonPaksForMapHook(char* map)
+{
+ LoadCommonPaksForMap(map);
+
+ // for sp => mp conversions, load the sp rpaks
+ if (!strcmp(map, "mp_skyway_v1") || !strcmp(map, "mp_crashsite") || !strcmp(map, "mp_hub_timeshift"))
+ map[0] = 's';
+}
+
+void InitialiseEngineRpakFilesystem(HMODULE baseAddress)
+{
+ g_pakLoadApi = (PakLoadFuncs*)((char*)baseAddress + 0x5BED78);
+ pUnknownPakLoadSingleton = (void**)((char*)baseAddress + 0x7C5E20);
+
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x15AD20, &LoadCommonPaksForMapHook, reinterpret_cast(&LoadCommonPaksForMap));
+}
\ No newline at end of file
diff --git a/NorthstarDedicatedTest/rpakfilesystem.h b/NorthstarDedicatedTest/rpakfilesystem.h
new file mode 100644
index 00000000..a9cc9a93
--- /dev/null
+++ b/NorthstarDedicatedTest/rpakfilesystem.h
@@ -0,0 +1,4 @@
+#pragma once
+
+void InitialiseEngineRpakFilesystem(HMODULE baseAddress);
+void LoadPakAsync(char* path);
\ No newline at end of file
--
cgit v1.2.3
From 4ad3342f6ce8ac4e9976f5eab5410c58b420a6a4 Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 01:28:48 +0000
Subject: don't enforce netchan limits during level transitions, change how
limit mode workss
---
NorthstarDedicatedTest/serverauthentication.cpp | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index 32eb67fc..c4208130 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -142,6 +142,9 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid,
if (authFail)
{
+ // set persistent data as ready, we use 0x3 internally to mark the client as using local persistence
+ *((char*)player + 0x4a0) = (char)0x3;
+
if (!CVar_ns_auth_allow_insecure->m_nValue) // no auth data and insecure connections aren't allowed, so dc the client
return false;
@@ -167,9 +170,6 @@ bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid,
pdataStream.read((char*)player + 0x4FA, length);
pdataStream.close();
-
- // set persistent data as ready, we use 0x3 internally to mark the client as using local persistence
- *((char*)player + 0x4a0) = (char)0x3;
}
return true; // auth successful, client stays on
@@ -329,8 +329,8 @@ char __fastcall CNetChan___ProcessMessagesHook(void* self, void* buf)
double startTime = Plat_FloatTime();
char ret = CNetChan___ProcessMessages(self, buf);
- // check processing limit
- if (Cvar_net_chan_limit_mode->m_nValue != 0)
+ // check processing limits, unless we're in a level transition
+ if (g_pHostState->m_iCurrentState == HostState_t::HS_RUN)
{
// player that sent the message
void* sender = *(void**)((char*)self + 368);
@@ -346,19 +346,14 @@ char __fastcall CNetChan___ProcessMessagesHook(void* self, void* buf)
g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastNetChanProcessingLimitStart = startTime;
g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime = 0.0;
}
-
g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime += (Plat_FloatTime() * 1000) - (startTime * 1000);
- int32_t limit = Cvar_net_chan_limit_msec_per_sec->m_nValue;
- if (g_pHostState->m_iCurrentState != HostState_t::HS_RUN)
- limit *= 2; // give clients more headroom in these states, as alot of clients will tend to time out here
-
- if (g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime >= limit)
+ if (g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime >= Cvar_net_chan_limit_msec_per_sec->m_nValue)
{
spdlog::warn("Client {} hit netchan processing limit with {}ms of processing time this second (max is {})", (char*)sender + 0x16, g_ServerAuthenticationManager->m_additionalPlayerData[sender].netChanProcessingLimitTime, Cvar_net_chan_limit_msec_per_sec->m_nValue);
- // mode 1 = kick, mode 2 = log without kicking
- if (Cvar_net_chan_limit_mode->m_nValue == 1)
+ // nonzero = kick, 0 = warn
+ if (Cvar_net_chan_limit_mode->m_nValue)
{
CBaseClient__Disconnect(sender, 1, "Exceeded net channel processing limit");
return false;
@@ -434,7 +429,7 @@ void InitialiseServerAuthentication(HMODULE baseAddress)
// literally just stolen from a fix valve used in csgo
CVar_sv_quota_stringcmdspersecond = RegisterConVar("sv_quota_stringcmdspersecond", "60", FCVAR_GAMEDLL, "How many string commands per second clients are allowed to submit, 0 to disallow all string commands");
// https://blog.counter-strike.net/index.php/2019/07/24922/ but different because idk how to check what current tick number is
- Cvar_net_chan_limit_mode = RegisterConVar("net_chan_limit_mode", "0", FCVAR_GAMEDLL, "The mode for netchan processing limits: 0 = none, 1 = kick, 2 = log");
+ Cvar_net_chan_limit_mode = RegisterConVar("net_chan_limit_mode", "0", FCVAR_GAMEDLL, "The mode for netchan processing limits: 0 = log, 1 = kick");
Cvar_net_chan_limit_msec_per_sec = RegisterConVar("net_chan_limit_msec_per_sec", "0", FCVAR_GAMEDLL, "Netchannel processing is limited to so many milliseconds, abort connection if exceeding budget");
Cvar_ns_player_auth_port = RegisterConVar("ns_player_auth_port", "8081", FCVAR_GAMEDLL, "");
Cvar_sv_querylimit_per_sec = RegisterConVar("sv_querylimit_per_sec", "15", FCVAR_GAMEDLL, "");
--
cgit v1.2.3
From 5514ff036dbdbf7f4000934223a0d21bf0b9085d Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 03:06:04 +0000
Subject: initial work for ban system
---
.../NorthstarDedicatedTest.vcxproj | 2 +
.../NorthstarDedicatedTest.vcxproj.filters | 6 +++
NorthstarDedicatedTest/bansystem.cpp | 58 ++++++++++++++++++++++
NorthstarDedicatedTest/bansystem.h | 17 +++++++
NorthstarDedicatedTest/miscserverscript.h | 3 +-
NorthstarDedicatedTest/serverauthentication.cpp | 7 ++-
6 files changed, 90 insertions(+), 3 deletions(-)
create mode 100644 NorthstarDedicatedTest/bansystem.cpp
create mode 100644 NorthstarDedicatedTest/bansystem.h
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 @@
+
@@ -612,6 +613,7 @@
+
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 @@
Header Files\Shared
+
+ Header Files\Server\Authentication
+
@@ -1538,6 +1541,9 @@
Source Files\Shared
+
+ Source Files\Server\Authentication
+
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
+
+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 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
#include
#include
@@ -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 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)
{
--
cgit v1.2.3
From 67e73b19be90c51cfb4c5efbbbb6f220ba1c688d Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 03:08:29 +0000
Subject: Update bansystem.h
---
NorthstarDedicatedTest/bansystem.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h
index ea715ea2..b316fc6f 100644
--- a/NorthstarDedicatedTest/bansystem.h
+++ b/NorthstarDedicatedTest/bansystem.h
@@ -1,4 +1,5 @@
#pragma once
+#include
class ServerBanSystem
{
--
cgit v1.2.3
From 8d7e759d520915f897bec4b4542f128cc6ad95e5 Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 03:12:26 +0000
Subject: remove logging for overwriting max_players
---
NorthstarDedicatedTest/playlist.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/NorthstarDedicatedTest/playlist.cpp b/NorthstarDedicatedTest/playlist.cpp
index 01a2de6a..59a13a26 100644
--- a/NorthstarDedicatedTest/playlist.cpp
+++ b/NorthstarDedicatedTest/playlist.cpp
@@ -72,8 +72,6 @@ int GetCurrentGamemodeMaxPlayersHook()
return GetCurrentGamemodeMaxPlayers();
int maxPlayers = atoi(maxPlayersStr);
- spdlog::info("Overwrote max_players to {}", maxPlayers);
-
return maxPlayers;
}
--
cgit v1.2.3
From 89d16c9a8a65e3b4872947c58df1ffd97fc63a4b Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 03:15:05 +0000
Subject: add the ability to disable spewfunc logging
---
NorthstarDedicatedTest/dllmain.cpp | 4 +++-
NorthstarDedicatedTest/logging.cpp | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 6acd4798..6ae24292 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -26,6 +26,7 @@
#include "miscclientfixes.h"
#include "miscserverfixes.h"
#include "rpakfilesystem.h"
+#include "bansystem.h"
#include "memalloc.h"
bool initialised = false;
@@ -85,7 +86,6 @@ void InitialiseNorthstar()
AddDllLoadCallback("engine.dll", WaitForDebugger);
AddDllLoadCallback("engine.dll", InitialiseEngineGameUtilFunctions);
AddDllLoadCallback("server.dll", InitialiseServerGameUtilFunctions);
- AddDllLoadCallback("engine.dll", InitialiseEngineSpewFuncHooks);
// dedi patches
{
@@ -115,7 +115,9 @@ void InitialiseNorthstar()
AddDllLoadCallback("client.dll", InitialiseMiscClientFixes);
}
+ AddDllLoadCallback("engine.dll", InitialiseEngineSpewFuncHooks);
AddDllLoadCallback("server.dll", InitialiseServerSquirrel);
+ AddDllLoadCallback("engine.dll", InitialiseBanSystem);
AddDllLoadCallback("engine.dll", InitialiseServerAuthentication);
AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer);
AddDllLoadCallback("server.dll", InitialiseMiscServerScriptCommand);
diff --git a/NorthstarDedicatedTest/logging.cpp b/NorthstarDedicatedTest/logging.cpp
index 7791299d..e13a9150 100644
--- a/NorthstarDedicatedTest/logging.cpp
+++ b/NorthstarDedicatedTest/logging.cpp
@@ -202,6 +202,8 @@ void InitialiseLogging()
spdlog::default_logger()->sinks().push_back(std::make_shared(stream.str(), false));
}
+ConVar* Cvar_spewlog_enable;
+
enum SpewType_t
{
SPEW_MESSAGE = 0,
@@ -217,6 +219,9 @@ EngineSpewFuncType EngineSpewFunc;
void EngineSpewFuncHook(void* engineServer, SpewType_t type, const char* format, va_list args)
{
+ if (!Cvar_spewlog_enable->m_nValue)
+ return;
+
const char* typeStr;
switch (type)
{
@@ -326,4 +331,6 @@ void InitialiseEngineSpewFuncHooks(HMODULE baseAddress)
{
HookEnabler hook;
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x11CA80, EngineSpewFuncHook, reinterpret_cast(&EngineSpewFunc));
+
+ Cvar_spewlog_enable = RegisterConVar("spewlog_enable", "1", FCVAR_NONE, "Enables/disables whether the engine spewfunc should be logged");
}
\ No newline at end of file
--
cgit v1.2.3
From ed0f27914710b75a246645380e167dad071adaa7 Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 03:52:39 +0000
Subject: add disconnects to ban system
---
NorthstarDedicatedTest/bansystem.cpp | 16 ++++++++++++----
NorthstarDedicatedTest/serverauthentication.cpp | 11 +++++++----
NorthstarDedicatedTest/serverauthentication.h | 3 +++
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
index 16c25b6b..40813f17 100644
--- a/NorthstarDedicatedTest/bansystem.cpp
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -3,6 +3,7 @@
#include "bansystem.h"
#include "serverauthentication.h"
#include "concommand.h"
+#include "miscserverscript.h"
#include
const char* BANLIST_PATH = "R2Northstar/banlist.txt";
@@ -11,8 +12,6 @@ ServerBanSystem* g_ServerBanSystem;
void ServerBanSystem::OpenBanlist()
{
- std::filesystem::create_directories(BANLIST_PATH);
-
std::ifstream enabledModsStream(BANLIST_PATH);
std::stringstream enabledModsStringStream;
@@ -26,13 +25,12 @@ void ServerBanSystem::OpenBanlist()
}
// open write stream for banlist
- m_sBanlistStream.open(BANLIST_PATH, std::ios::in | std::ios::binary);
+ m_sBanlistStream.open(BANLIST_PATH, std::ofstream::out | std::ofstream::binary | std::ofstream::app);
}
void ServerBanSystem::BanUID(uint64_t uid)
{
m_vBannedUids.push_back(uid);
-
m_sBanlistStream << std::to_string(uid) << std::endl;
}
@@ -46,7 +44,17 @@ void BanPlayerCommand(const CCommand& args)
if (args.ArgC() < 2)
return;
+ for (int i = 0; i < 32; i++)
+ {
+ void* player = GetPlayerByIndex(i);
+ if (!strcmp((char*)player + 0x16, args.Arg(1)) || strcmp((char*)player + 0xF500, args.Arg(1)))
+ {
+ g_ServerBanSystem->BanUID(strtoll((char*)player + 0xF500, nullptr, 10));
+ CBaseClient__Disconnect(player, 1, "Banned from server");
+ break;
+ }
+ }
}
void InitialiseBanSystem(HMODULE baseAddress)
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index 0fdb8664..e0ac5d57 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -23,7 +23,6 @@ CBaseClient__ConnectType CBaseClient__Connect;
typedef void(*CBaseClient__ActivatePlayerType)(void* self);
CBaseClient__ActivatePlayerType CBaseClient__ActivatePlayer;
-typedef void(*CBaseClient__DisconnectType)(void* self, uint32_t unknownButAlways1, const char* reason, ...);
CBaseClient__DisconnectType CBaseClient__Disconnect;
typedef char(*CGameClient__ExecuteStringCommandType)(void* self, uint32_t unknown, const char* pCommandString);
@@ -117,9 +116,6 @@ void ServerAuthenticationManager::StopPlayerAuthServer()
bool ServerAuthenticationManager::AuthenticatePlayer(void* player, int64_t uid, char* authToken)
{
- if (!g_ServerBanSystem->IsUIDAllowed(uid))
- return false;
-
std::string strUid = std::to_string(uid);
std::lock_guard guard(m_authDataMutex);
@@ -240,6 +236,13 @@ char CBaseClient__ConnectHook(void* self, char* name, __int64 netchan_ptr_arg, c
// try to auth player, dc if it fails
// we connect irregardless of auth, because returning bad from this function can fuck client state p bad
char ret = CBaseClient__Connect(self, name, netchan_ptr_arg, b_fake_player_arg, a5, Buffer, a7);
+
+ if (!g_ServerBanSystem->IsUIDAllowed(nextPlayerUid))
+ {
+ CBaseClient__Disconnect(self, 1, "Banned from server");
+ return ret;
+ }
+
if (strlen(name) >= 64) // fix for name overflow bug
CBaseClient__Disconnect(self, 1, "Invalid name");
else if (!g_ServerAuthenticationManager->AuthenticatePlayer(self, nextPlayerUid, nextPlayerToken) && g_MasterServerManager->m_bRequireClientAuth)
diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h
index a8863b2f..8b346f1d 100644
--- a/NorthstarDedicatedTest/serverauthentication.h
+++ b/NorthstarDedicatedTest/serverauthentication.h
@@ -94,6 +94,9 @@ public:
void WritePersistentData(void* player);
};
+typedef void(*CBaseClient__DisconnectType)(void* self, uint32_t unknownButAlways1, const char* reason, ...);
+extern CBaseClient__DisconnectType CBaseClient__Disconnect;
+
void InitialiseServerAuthentication(HMODULE baseAddress);
extern ServerAuthenticationManager* g_ServerAuthenticationManager;
--
cgit v1.2.3
From 49acb6d831919022745b68f474b65c19f4e62bcd Mon Sep 17 00:00:00 2001
From: BobTheBob <32057864+BobTheBob9@users.noreply.github.com>
Date: Sun, 2 Jan 2022 04:07:42 +0000
Subject: add unban command
---
NorthstarDedicatedTest/bansystem.cpp | 24 ++++++++++++++++++++++++
NorthstarDedicatedTest/bansystem.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
index 40813f17..182506e8 100644
--- a/NorthstarDedicatedTest/bansystem.cpp
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -32,6 +32,19 @@ void ServerBanSystem::BanUID(uint64_t uid)
{
m_vBannedUids.push_back(uid);
m_sBanlistStream << std::to_string(uid) << std::endl;
+ spdlog::info("{} was banned", uid);
+}
+
+void ServerBanSystem::UnbanUID(uint64_t uid)
+{
+ auto findResult = std::find(m_vBannedUids.begin(), m_vBannedUids.end(), uid);
+ if (findResult == m_vBannedUids.end())
+ return;
+
+ m_vBannedUids.erase(findResult);
+ spdlog::info("{} was unbanned", uid);
+ // todo: this needs to erase from the banlist file
+ // atm unsure how to do this aside from just clearing and fully rewriting the file
}
bool ServerBanSystem::IsUIDAllowed(uint64_t uid)
@@ -44,6 +57,7 @@ void BanPlayerCommand(const CCommand& args)
if (args.ArgC() < 2)
return;
+ // assuming maxplayers 32
for (int i = 0; i < 32; i++)
{
void* player = GetPlayerByIndex(i);
@@ -57,10 +71,20 @@ void BanPlayerCommand(const CCommand& args)
}
}
+void UnbanPlayerCommand(const CCommand& args)
+{
+ if (args.ArgC() < 2)
+ return;
+
+ // assumedly the player being unbanned here wasn't already connected, so don't need to iterate over players or anything
+ g_ServerBanSystem->UnbanUID(strtoll(args.Arg(1), nullptr, 10));
+}
+
void InitialiseBanSystem(HMODULE baseAddress)
{
g_ServerBanSystem = new ServerBanSystem;
g_ServerBanSystem->OpenBanlist();
RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL);
+ RegisterConCommand("unban", UnbanPlayerCommand, "unbans a given player by uid", FCVAR_NONE);
}
\ No newline at end of file
diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h
index b316fc6f..a1646356 100644
--- a/NorthstarDedicatedTest/bansystem.h
+++ b/NorthstarDedicatedTest/bansystem.h
@@ -10,6 +10,7 @@ private:
public:
void OpenBanlist();
void BanUID(uint64_t uid);
+ void UnbanUID(uint64_t uid);
bool IsUIDAllowed(uint64_t uid);
};
--
cgit v1.2.3