aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NorthstarDedicatedTest/dllmain.cpp1
-rw-r--r--NorthstarDedicatedTest/serverauthentication.cpp35
-rw-r--r--NorthstarDedicatedTest/serverauthentication.h6
3 files changed, 41 insertions, 1 deletions
diff --git a/NorthstarDedicatedTest/dllmain.cpp b/NorthstarDedicatedTest/dllmain.cpp
index 6ae24292..c7cfce8b 100644
--- a/NorthstarDedicatedTest/dllmain.cpp
+++ b/NorthstarDedicatedTest/dllmain.cpp
@@ -119,6 +119,7 @@ void 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 e0ac5d57..1093ff7f 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