Improve persona name validations

Move all server convars out of the EbisuSDK lib, the min/max name len are now parameterized. This also makes it possible to use the code on the client if ever needed.
This commit is contained in:
Kawe Mazidjatari 2023-07-19 02:16:06 +02:00
parent dccb897c27
commit 6bb622314e
3 changed files with 21 additions and 11 deletions

View File

@ -1,5 +1,4 @@
#include "core/stdafx.h"
#include "tier1/cvar.h"
#include "ebisusdk/EbisuSDK.h"
#include "engine/server/sv_main.h"
@ -44,17 +43,12 @@ bool IsOriginInitialized()
// Input : *pszName -
// Output : true on success, false on failure
//-----------------------------------------------------------------------------
bool IsValidPersonaName(const char* pszName)
bool IsValidPersonaName(const char* pszName, int nMinLen, int nMaxLen)
{
if (!sv_validatePersonaName->GetBool())
{
return true;
}
size_t len = strlen(pszName);
if (len < sv_minPersonaNameLength->GetInt() ||
len > sv_maxPersonaNameLength->GetInt())
if (len < nMinLen ||
len > nMaxLen)
{
return false;
}

View File

@ -19,7 +19,7 @@ inline bool* g_EbisuProfileInit = nullptr;
///////////////////////////////////////////////////////////////////////////////
void HEbisuSDK_Init();
bool IsOriginInitialized();
bool IsValidPersonaName(const char* pszName);
bool IsValidPersonaName(const char* pszName, int nMinLen, int nMaxLen);
///////////////////////////////////////////////////////////////////////////////
class VEbisuSDK : public IDetour

View File

@ -105,8 +105,24 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge)
DevMsg(eDLL_T::SERVER, "Processing connectionless challenge for '[%s]:%i' ('%llu')\n",
pszAddresBuffer, nPort, nNucleusID);
bool bValidName = false;
if (VALID_CHARSTAR(pszPersonaName) &&
V_IsValidUTF8(pszPersonaName))
{
if (sv_validatePersonaName->GetBool() &&
!IsValidPersonaName(pszPersonaName, sv_minPersonaNameLength->GetInt(), sv_maxPersonaNameLength->GetInt()))
{
bValidName = false;
}
else
{
bValidName = true;
}
}
// Only proceed connection if the client's name is valid and UTF-8 encoded.
if (!VALID_CHARSTAR(pszPersonaName) || !V_IsValidUTF8(pszPersonaName) || !IsValidPersonaName(pszPersonaName))
if (!bValidName)
{
pServer->RejectConnection(pServer->m_Socket, &pChallenge->netAdr, "#Valve_Reject_Invalid_Name");
if (bEnableLogging)