From ae09372cc79053f5515529e403402494ffa6dfe4 Mon Sep 17 00:00:00 2001 From: IcePixelx <41352111+PixieCore@users.noreply.github.com> Date: Sun, 9 Jan 2022 14:35:43 +0100 Subject: [PATCH] Pylon system changes. --- r5dev/engine/host_state.cpp | 100 +++++++++++++++++++++---------- r5dev/public/bansystem.cpp | 18 +++--- r5dev/public/include/bansystem.h | 6 +- r5dev/server/server.cpp | 36 +++-------- 4 files changed, 91 insertions(+), 69 deletions(-) diff --git a/r5dev/engine/host_state.cpp b/r5dev/engine/host_state.cpp index 4ebcb622..10adbac6 100644 --- a/r5dev/engine/host_state.cpp +++ b/r5dev/engine/host_state.cpp @@ -31,7 +31,6 @@ void KeepAliveToPylon() // BUG BUG: Checksum is null on dedi // ADDITIONAL NOTES: seems to be related to scripts, this also happens when the listen server is started but the client from the same process never connects. // Checksum only gets set on the server if the client from its own process connects to it. - std::to_string(*g_nRemoteFunctionCallsChecksum), std::string(), g_szNetKey.c_str() } @@ -39,6 +38,66 @@ void KeepAliveToPylon() } } + +//----------------------------------------------------------------------------- +// Purpose: Check refuse list and kill netchan connection. +//----------------------------------------------------------------------------- +void BanListCheck() +{ + if (g_pBanSystem->IsRefuseListValid()) + { + for (int i = 0; i < g_pBanSystem->vsvrefuseList.size(); i++) // Loop through vector. + { + for (int c = 0; c < MAX_PLAYERS; c++) // Loop through all possible client instances. + { + CClient* client = g_pClient->GetClientInstance(c); // Get client instance. + if (!client) + { + continue; + } + + if (!client->GetNetChan()) // Netchan valid? + { + continue; + } + + if (g_pClient->m_iOriginID != g_pBanSystem->vsvrefuseList[i].second) // See if nucleus id matches entry. + { + continue; + } + + std::string finalIpAddress = std::string(); + ADDRESS ipAddressField = ADDRESS(((std::uintptr_t)client->GetNetChan()) + 0x1AC0); // Get client ip from netchan. + if (ipAddressField && ipAddressField.GetValue() != 0x0) + { + std::stringstream ss; + ss << std::to_string(ipAddressField.GetValue()) << "." + << std::to_string(ipAddressField.Offset(0x1).GetValue()) << "." + << std::to_string(ipAddressField.Offset(0x2).GetValue()) << "." + << std::to_string(ipAddressField.Offset(0x3).GetValue()); + + finalIpAddress = ss.str(); + } + + DevMsg(eDLL_T::SERVER, "\n"); + DevMsg(eDLL_T::SERVER, "______________________________________________________________\n"); + DevMsg(eDLL_T::SERVER, "] PYLON NOTICE -----------------------------------------------\n"); + DevMsg(eDLL_T::SERVER, "] OriginID : | '%lld' IS GETTING DISCONNECTED.\n", g_pClient->m_iOriginID); + if (finalIpAddress.empty()) + DevMsg(eDLL_T::SERVER, "] IP-ADDR : | CLIENT MODIFIED PACKET.\n"); + else + DevMsg(eDLL_T::SERVER, "] IP-ADDR : | '%s'\n", finalIpAddress.c_str()); + DevMsg(eDLL_T::SERVER, "--------------------------------------------------------------\n"); + DevMsg(eDLL_T::SERVER, "\n"); + + g_pBanSystem->AddEntry(finalIpAddress, g_pClient->m_iOriginID); // Add local entry to reserve a non needed request. + g_pBanSystem->Save(); // Save list. + NET_DisconnectClient(g_pClient, c, g_pBanSystem->vsvrefuseList[i].first.c_str(), 0, 1); // Disconnect client. + } + } + } +} + //----------------------------------------------------------------------------- // Purpose: state machine's main processing loop //----------------------------------------------------------------------------- @@ -91,6 +150,15 @@ void HCHostState_FrameUpdate(void* rcx, void* rdx, float time) } }); + static std::thread BanlistThread([]() + { + while (true) + { + BanListCheck(); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + } + }); + if (net_userandomkey->m_pParent->m_iValue == 1) { HNET_GenerateKey(); @@ -117,36 +185,6 @@ void HCHostState_FrameUpdate(void* rcx, void* rdx, float time) Cbuf_ExecuteFn(); oldState = g_pHostState->m_iCurrentState; - if (g_pBanSystem->IsRefuseListValid()) - { - for (int i = 0; i < g_pBanSystem->vsvrefuseList.size(); i++) // Loop through vector. - { - for (int c = 0; c < MAX_PLAYERS; c++) // Loop through all possible client instances. - { - CClient* client = g_pClient->GetClientInstance(c); // Get client instance. - if (!client) - { - continue; - } - - if (!client->GetNetChan()) // Netchan valid? - { - continue; - } - - int clientID = g_pClient->m_iUserID + 1; // Get UserID + 1. - if (clientID != g_pBanSystem->vsvrefuseList[i].second) // See if they match. - { - continue; - } - - NET_DisconnectClient(g_pClient, c, g_pBanSystem->vsvrefuseList[i].first.c_str(), 0, 1); - g_pBanSystem->DeleteConnectionRefuse(clientID); - break; - } - } - } - switch (g_pHostState->m_iCurrentState) { case HostStates_t::HS_NEW_GAME: diff --git a/r5dev/public/bansystem.cpp b/r5dev/public/bansystem.cpp index 88f203cf..e5012cdb 100644 --- a/r5dev/public/bansystem.cpp +++ b/r5dev/public/bansystem.cpp @@ -81,7 +81,11 @@ void CBanSystem::AddEntry(std::string svIpAddress, std::int64_t nOriginID) { if (!svIpAddress.empty() && nOriginID > 0) // Check if args are valid. { - vsvBanList.push_back(std::make_pair(svIpAddress, nOriginID)); // Push it back into the vector. + auto it = std::find(vsvBanList.begin(), vsvBanList.end(), std::make_pair(svIpAddress, nOriginID)); // Check if we have this entry already. + if (it == vsvBanList.end()) // We don't have that entry? + { + vsvBanList.push_back(std::make_pair(svIpAddress, nOriginID)); // Add it. + } } } @@ -102,19 +106,19 @@ void CBanSystem::DeleteEntry(std::string svIpAddress, std::int64_t nOriginID) //----------------------------------------------------------------------------- // Purpose: adds a connect refuse entry to the refuselist //----------------------------------------------------------------------------- -void CBanSystem::AddConnectionRefuse(std::string svError, int nUserID) +void CBanSystem::AddConnectionRefuse(std::string svError, std::int64_t nOriginID) { if (vsvrefuseList.empty()) { - vsvrefuseList.push_back(std::make_pair(svError, nUserID)); + vsvrefuseList.push_back(std::make_pair(svError, nOriginID)); } else { for (int i = 0; i < vsvrefuseList.size(); i++) // Loop through vector. { - if (vsvrefuseList[i].second != nUserID) // Do any entries match our vector? + if (vsvrefuseList[i].second != nOriginID) // Do any entries match our vector? { - vsvrefuseList.push_back(std::make_pair(svError, nUserID)); // Push it back into the vector. + vsvrefuseList.push_back(std::make_pair(svError, nOriginID)); // Push it back into the vector. } } } @@ -123,11 +127,11 @@ void CBanSystem::AddConnectionRefuse(std::string svError, int nUserID) //----------------------------------------------------------------------------- // Purpose: deletes an entry in the refuselist //----------------------------------------------------------------------------- -void CBanSystem::DeleteConnectionRefuse(int nUserID) +void CBanSystem::DeleteConnectionRefuse(std::int64_t nOriginID) { for (int i = 0; i < vsvrefuseList.size(); i++) // Loop through vector. { - if (vsvrefuseList[i].second == nUserID) // Do any entries match our vector? + if (vsvrefuseList[i].second == nOriginID) // Do any entries match our vector? { vsvrefuseList.erase(vsvrefuseList.begin() + i); // If so erase that vector element. } diff --git a/r5dev/public/include/bansystem.h b/r5dev/public/include/bansystem.h index c293ad63..1e8e595e 100644 --- a/r5dev/public/include/bansystem.h +++ b/r5dev/public/include/bansystem.h @@ -10,13 +10,13 @@ public: void Save(); void AddEntry(std::string svIpAddress, std::int64_t nOriginID); void DeleteEntry(std::string svIpAddress, std::int64_t nOriginID); - void AddConnectionRefuse(std::string svError, int nUserID); - void DeleteConnectionRefuse(int nUserID); + void AddConnectionRefuse(std::string svError, std::int64_t nOriginID); + void DeleteConnectionRefuse(std::int64_t nUserID); bool IsBanned(std::string svIpAddress, std::int64_t nOriginID); bool IsRefuseListValid(); bool IsBanListValid(); - std::vector> vsvrefuseList = {};; + std::vector> vsvrefuseList = {};; private: std::vector> vsvBanList = {}; }; diff --git a/r5dev/server/server.cpp b/r5dev/server/server.cpp index 02f42d66..7f8e9aec 100644 --- a/r5dev/server/server.cpp +++ b/r5dev/server/server.cpp @@ -12,36 +12,16 @@ void IsClientBanned(R5Net::Client* pR5net, const std::string svIPAddr, std::int64_t nNucleusID) { std::string svError = std::string(); - bool bCompBanned = pR5net && pR5net->GetClientIsBanned(svIPAddr, nNucleusID, svError); + bool bCompBanned = pR5net->GetClientIsBanned(svIPAddr, nNucleusID, svError); if (bCompBanned) { - while (bCompBanned) - { - std::this_thread::sleep_for(std::chrono::milliseconds(500)); - for (int i = 0; i < MAX_PLAYERS; i++) // Loop through all possible client instances. - { - CClient* pClient = g_pClient->GetClientInstance(i); // Get client instance. - if (!pClient) // Client instance valid? - { - continue; - } - - if (!pClient->GetNetChan()) // Netchan valid? - { - continue; - } - - std::int64_t nOriginID = pClient->m_iOriginID; // Get originID. - if (nOriginID != nNucleusID) // See if they match. - { - continue; - } - - g_pBanSystem->AddConnectionRefuse(svError, pClient->m_iUserID + 1); // Add to the vector. - bCompBanned = false; - break; - } - } + DevMsg(eDLL_T::SERVER, "\n"); + DevMsg(eDLL_T::SERVER, "______________________________________________________________\n"); + DevMsg(eDLL_T::SERVER, "] PYLON NOTICE -------------------------------------\n"); + DevMsg(eDLL_T::SERVER, "] OriginID : | '%lld' IS PYLON BANNED.\n", nNucleusID); + DevMsg(eDLL_T::SERVER, "--------------------------------------------------------------\n"); + DevMsg(eDLL_T::SERVER, "\n"); + g_pBanSystem->AddConnectionRefuse(svError, nNucleusID); // Add to the vector. } }