From 6b23570bebb2270a7e73f0c777679502242cd037 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 30 Apr 2023 01:29:54 +0200 Subject: [PATCH] Ban system bug fix and improvements * Format the ip as '[ip]:port' in all logging calls for consistency. * Fixed a bug causing the IP to be send up as full instead of base only to master server (should always be base only). * Temporarily uncommented the plugin callback logic. --- r5dev/engine/server/server.cpp | 26 +++++++++++++++++--------- r5dev/engine/server/sv_main.cpp | 20 +++++++++++++------- r5dev/engine/server/sv_main.h | 2 +- 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/r5dev/engine/server/server.cpp b/r5dev/engine/server/server.cpp index eea1192f..c4836380 100644 --- a/r5dev/engine/server/server.cpp +++ b/r5dev/engine/server/server.cpp @@ -98,15 +98,19 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge) pChallenge->netAdr.ToString(pszAddresBuffer, sizeof(pszAddresBuffer), true); const bool bEnableLogging = sv_showconnecting->GetBool(); + const int nPort = int(ntohs(pChallenge->netAdr.GetPort())); + if (bEnableLogging) - DevMsg(eDLL_T::SERVER, "Processing connectionless challenge for '%s' ('%llu')\n", pszAddresBuffer, nNucleusID); + DevMsg(eDLL_T::SERVER, "Processing connectionless challenge for '[%s]:%i' ('%llu')\n", + pszAddresBuffer, nPort, nNucleusID); // Only proceed connection if the client's name is valid and UTF-8 encoded. if (!VALID_CHARSTAR(pszPersonaName) || !IsValidUTF8(pszPersonaName) || !IsValidPersonaName(pszPersonaName)) { pServer->RejectConnection(pServer->m_Socket, &pChallenge->netAdr, "#Valve_Reject_Invalid_Name"); if (bEnableLogging) - Warning(eDLL_T::SERVER, "Connection rejected for '%s' ('%llu' has an invalid name!)\n", pszAddresBuffer, nNucleusID); + Warning(eDLL_T::SERVER, "Connection rejected for '[%s]:%i' ('%llu' has an invalid name!)\n", + pszAddresBuffer, nPort, nNucleusID); return nullptr; } @@ -117,7 +121,8 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge) { pServer->RejectConnection(pServer->m_Socket, &pChallenge->netAdr, "#Valve_Reject_Banned"); if (bEnableLogging) - Warning(eDLL_T::SERVER, "Connection rejected for '%s' ('%llu' is banned from this server!)\n", pszAddresBuffer, nNucleusID); + Warning(eDLL_T::SERVER, "Connection rejected for '[%s]:%i' ('%llu' is banned from this server!)\n", + pszAddresBuffer, nPort, nNucleusID); return nullptr; } @@ -125,15 +130,18 @@ CClient* CServer::ConnectClient(CServer* pServer, user_creds_s* pChallenge) CClient* pClient = v_CServer_ConnectClient(pServer, pChallenge); - for (auto& callback : !g_pPluginSystem->GetConnectClientCallbacks()) - { - if (!callback(pServer, pClient, pChallenge)) - return nullptr; - } + //for (auto& callback : !g_pPluginSystem->GetConnectClientCallbacks()) + //{ + // if (!callback(pServer, pClient, pChallenge)) + // { + // pClient->Disconnect(REP_MARK_BAD, "#Valve_Reject_Banned"); + // return nullptr; + // } + //} if (pClient && sv_globalBanlist->GetBool()) { - std::thread th(SV_IsClientBanned, pClient, string(pszAddresBuffer), nNucleusID, string(pszPersonaName)); + std::thread th(SV_IsClientBanned, pClient, string(pszAddresBuffer), nNucleusID, string(pszPersonaName), nPort); th.detach(); } diff --git a/r5dev/engine/server/sv_main.cpp b/r5dev/engine/server/sv_main.cpp index a69fa7b8..534038f3 100644 --- a/r5dev/engine/server/sv_main.cpp +++ b/r5dev/engine/server/sv_main.cpp @@ -18,7 +18,8 @@ //----------------------------------------------------------------------------- // Purpose: checks if particular client is banned on the comp server //----------------------------------------------------------------------------- -void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t nNucleusID, const string& svPersonaName) +void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, + const uint64_t nNucleusID, const string& svPersonaName, const int nPort) { Assert(pClient != nullptr); @@ -29,7 +30,7 @@ void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t { if (!ThreadInMainThread()) { - g_TaskScheduler->Dispatch([pClient, svError, svIPAddr, nNucleusID] + g_TaskScheduler->Dispatch([pClient, svError, svIPAddr, nNucleusID, nPort] { // Make sure client isn't already disconnected, // and that if there is a valid netchannel, that @@ -38,9 +39,11 @@ void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t CNetChan* pChan = pClient->GetNetChan(); if (pChan && pClient->GetNucleusID() == nNucleusID) { + int nUserID = pClient->GetUserID(); + pClient->Disconnect(Reputation_t::REP_MARK_BAD, svError.c_str()); - Warning(eDLL_T::SERVER, "Removed client '%s' ('%llu' is banned globally!)\n", - svIPAddr.c_str(), nNucleusID); + Warning(eDLL_T::SERVER, "Removed client '[%s]:%i' from slot #%i ('%llu' is banned globally!)\n", + svIPAddr.c_str(), nPort, nUserID, nNucleusID); } }, 0); } @@ -86,7 +89,7 @@ void SV_CheckForBan(const BannedVec_t* pBannedVec /*= nullptr*/) if (!pClient->IsConnected()) continue; - const char* szIPAddr = pNetChan->GetAddress(); + const char* szIPAddr = pNetChan->GetAddress(true); const uint64_t nNucleusID = pClient->GetNucleusID(); if (!pBannedVec) @@ -97,9 +100,12 @@ void SV_CheckForBan(const BannedVec_t* pBannedVec /*= nullptr*/) { if (it.second == pClient->GetNucleusID()) { + const int nUserID = pClient->GetUserID(); + const int nPort = pNetChan->GetPort(); + pClient->Disconnect(Reputation_t::REP_MARK_BAD, "%s", it.first.c_str()); - Warning(eDLL_T::SERVER, "Removed client '%s' from slot '%i' ('%llu' is banned globally!)\n", - szIPAddr, c, nNucleusID); + Warning(eDLL_T::SERVER, "Removed client '[%s]:%i' from slot #%i ('%llu' is banned globally!)\n", + szIPAddr, nPort, nUserID, nNucleusID); } } } diff --git a/r5dev/engine/server/sv_main.h b/r5dev/engine/server/sv_main.h index a2861b3d..aaec41f4 100644 --- a/r5dev/engine/server/sv_main.h +++ b/r5dev/engine/server/sv_main.h @@ -33,7 +33,7 @@ inline bool* s_bIsDedicated = nullptr; void SV_InitGameDLL(); void SV_ShutdownGameDLL(); bool SV_ActivateServer(); -void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t nNucleusID, const string& svPersonaName); +void SV_IsClientBanned(CClient* pClient, const string& svIPAddr, const uint64_t nNucleusID, const string& svPersonaName, const int nPort); void SV_CheckForBan(const BannedVec_t* pBannedVec = nullptr); ///////////////////////////////////////////////////////////////////////////////