aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NorthstarDedicatedTest/bansystem.cpp15
-rw-r--r--NorthstarDedicatedTest/bansystem.h1
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp1
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp35
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h6
5 files changed, 57 insertions, 1 deletions
diff --git a/NorthstarDedicatedTest/bansystem.cpp b/NorthstarDedicatedTest/bansystem.cpp
index 182506e8..610c20e4 100644
--- a/NorthstarDedicatedTest/bansystem.cpp
+++ b/NorthstarDedicatedTest/bansystem.cpp
@@ -28,6 +28,15 @@ void ServerBanSystem::OpenBanlist()
m_sBanlistStream.open(BANLIST_PATH, std::ofstream::out | std::ofstream::binary | std::ofstream::app);
}
+void ServerBanSystem::ClearBanlist()
+{
+ m_vBannedUids.clear();
+
+ // reopen the file, don't provide std::ofstream::app so it clears on open
+ m_sBanlistStream.close();
+ m_sBanlistStream.open(BANLIST_PATH, std::ofstream::out | std::ofstream::binary);
+}
+
void ServerBanSystem::BanUID(uint64_t uid)
{
m_vBannedUids.push_back(uid);
@@ -80,6 +89,11 @@ void UnbanPlayerCommand(const CCommand& args)
g_ServerBanSystem->UnbanUID(strtoll(args.Arg(1), nullptr, 10));
}
+void ClearBanlistCommand(const CCommand& args)
+{
+ g_ServerBanSystem->ClearBanlist();
+}
+
void InitialiseBanSystem(HMODULE baseAddress)
{
g_ServerBanSystem = new ServerBanSystem;
@@ -87,4 +101,5 @@ void InitialiseBanSystem(HMODULE baseAddress)
RegisterConCommand("ban", BanPlayerCommand, "bans a given player by uid or name", FCVAR_GAMEDLL);
RegisterConCommand("unban", UnbanPlayerCommand, "unbans a given player by uid", FCVAR_NONE);
+ RegisterConCommand("clearbanlist", ClearBanlistCommand, "clears all uids on the banlist", FCVAR_NONE);
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/bansystem.h b/NorthstarDedicatedTest/bansystem.h
index a1646356..8ce05308 100644
--- a/NorthstarDedicatedTest/bansystem.h
+++ b/NorthstarDedicatedTest/bansystem.h
@@ -9,6 +9,7 @@ private:
public:
void OpenBanlist();
+ void ClearBanlist();
void BanUID(uint64_t uid);
void UnbanUID(uint64_t uid);
bool IsUIDAllowed(uint64_t uid);
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index cc1b0b7d..c5a914e5 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -118,6 +118,7 @@ bool InitialiseNorthstar()
AddDllLoadCallback("server.dll", InitialiseServerSquirrel);
AddDllLoadCallback("engine.dll", InitialiseBanSystem);
AddDllLoadCallback("engine.dll", InitialiseServerAuthentication);
+ AddDllLoadCallback("server.dll", InitialiseServerAuthenticationServerDLL);
AddDllLoadCallback("engine.dll", InitialiseSharedMasterServer);
AddDllLoadCallback("server.dll", InitialiseMiscServerScriptCommand);
AddDllLoadCallback("server.dll", InitialiseMiscServerFixes);
diff --git a/NorthstarDedicatedTest/serverauthentication.cpp b/NorthstarDedicatedTest/serverauthentication.cpp
index 33a57c6a..da84280c 100644
--- a/NorthstarDedicatedTest/serverauthentication.cpp
+++ b/NorthstarDedicatedTest/serverauthentication.cpp
@@ -6,6 +6,7 @@
#include "httplib.h"
#include "gameutils.h"
#include "bansystem.h"
+#include "miscserverscript.h"
#include <fstream>
#include <filesystem>
#include <thread>
@@ -37,6 +38,10 @@ CBaseClient__SendServerInfoType CBaseClient__SendServerInfo;
typedef bool(*ProcessConnectionlessPacketType)(void* a1, netpacket_t* packet);
ProcessConnectionlessPacketType ProcessConnectionlessPacket;
+typedef void(*CServerGameDLL__OnRecievedSayTextMessageType)(void* self, unsigned int senderClientIndex, const char* message, char unknown);
+CServerGameDLL__OnRecievedSayTextMessageType CServerGameDLL__OnRecievedSayTextMessage;
+
+
// global vars
ServerAuthenticationManager* g_ServerAuthenticationManager;
@@ -48,6 +53,7 @@ ConVar* CVar_sv_quota_stringcmdspersecond;
ConVar* Cvar_net_chan_limit_mode;
ConVar* Cvar_net_chan_limit_msec_per_sec;
ConVar* Cvar_sv_querylimit_per_sec;
+ConVar* Cvar_sv_max_chat_messages_per_sec;
void ServerAuthenticationManager::StartPlayerAuthServer()
{
@@ -425,6 +431,28 @@ bool ProcessConnectionlessPacketHook(void* a1, netpacket_t* packet)
return ProcessConnectionlessPacket(a1, packet);
}
+void CServerGameDLL__OnRecievedSayTextMessageHook(void* self, unsigned int senderClientIndex, const char* message, char unknown)
+{
+ void* sender = GetPlayerByIndex(senderClientIndex - 1); // senderClientIndex starts at 1
+
+ // check chat ratelimits
+ if (Plat_FloatTime() - g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastSayTextLimitStart >= 1.0)
+ {
+ g_ServerAuthenticationManager->m_additionalPlayerData[sender].lastSayTextLimitStart = Plat_FloatTime();
+ g_ServerAuthenticationManager->m_additionalPlayerData[sender].sayTextLimitCount = 0;
+ }
+
+ if (g_ServerAuthenticationManager->m_additionalPlayerData[sender].sayTextLimitCount >= Cvar_sv_max_chat_messages_per_sec->m_nValue)
+ return;
+
+ g_ServerAuthenticationManager->m_additionalPlayerData[sender].sayTextLimitCount++;
+
+ // todo: could censor messages here if we have a banned word list, we do not currently have one of these
+ // could possibly make this call a script codecallback, or smth
+
+ CServerGameDLL__OnRecievedSayTextMessage(self, senderClientIndex, message, unknown);
+}
+
void InitialiseServerAuthentication(HMODULE baseAddress)
{
g_ServerAuthenticationManager = new ServerAuthenticationManager;
@@ -439,6 +467,7 @@ void InitialiseServerAuthentication(HMODULE baseAddress)
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, "");
+ Cvar_sv_max_chat_messages_per_sec = RegisterConVar("sv_max_chat_messages_per_sec", "5", FCVAR_GAMEDLL, "");
HookEnabler hook;
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x114430, &CBaseServer__ConnectClientHook, reinterpret_cast<LPVOID*>(&CBaseServer__ConnectClient));
@@ -493,4 +522,10 @@ void InitialiseServerAuthentication(HMODULE baseAddress)
*((char*)ptr + 13) = (char)0x90;
*((char*)ptr + 14) = (char)0x90;
}
+}
+
+void InitialiseServerAuthenticationServerDLL(HMODULE baseAddress)
+{
+ HookEnabler hook;
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x1595C0, &CServerGameDLL__OnRecievedSayTextMessageHook, reinterpret_cast<LPVOID*>(&CServerGameDLL__OnRecievedSayTextMessage));
} \ No newline at end of file
diff --git a/NorthstarDedicatedTest/serverauthentication.h b/NorthstarDedicatedTest/serverauthentication.h
index 8b346f1d..6702eb3d 100644
--- a/NorthstarDedicatedTest/serverauthentication.h
+++ b/NorthstarDedicatedTest/serverauthentication.h
@@ -23,7 +23,10 @@ struct AdditionalPlayerData
int numClientCommandsInQuota = 0;
double lastNetChanProcessingLimitStart = -1.0;
- double netChanProcessingLimitTime = 0;
+ double netChanProcessingLimitTime = 0.0;
+
+ double lastSayTextLimitStart = -1.0;
+ int sayTextLimitCount = 0;
};
#pragma once
@@ -98,6 +101,7 @@ typedef void(*CBaseClient__DisconnectType)(void* self, uint32_t unknownButAlways
extern CBaseClient__DisconnectType CBaseClient__Disconnect;
void InitialiseServerAuthentication(HMODULE baseAddress);
+void InitialiseServerAuthenticationServerDLL(HMODULE baseAddress);
extern ServerAuthenticationManager* g_ServerAuthenticationManager;
extern ConVar* Cvar_ns_player_auth_port; \ No newline at end of file