aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NorthstarDedicatedTest/bansystem.cpp16
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp11
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h3
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 <filesystem>
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<std::mutex> 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;