From f4449bad9969c142b165776e06c5a758f3e8225b Mon Sep 17 00:00:00 2001 From: "R.K" Date: Mon, 6 May 2024 11:51:33 -0700 Subject: [PATCH] PlayerDB Delete Untrusted Players (#3053) --- .../player_database_service.cpp | 27 +++++++++++++++++ .../player_database_service.hpp | 1 + src/views/network/view_player_database.cpp | 29 +++++++++++++++++-- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/services/player_database/player_database_service.cpp b/src/services/player_database/player_database_service.cpp index 2a90e800..f894009e 100644 --- a/src/services/player_database/player_database_service.cpp +++ b/src/services/player_database/player_database_service.cpp @@ -219,6 +219,33 @@ namespace big return player; } + void player_database_service::remove_untrusted_players() + { + for (auto it = m_players.begin(); it != m_players.end();) + { + if (!it->second->is_trusted) + { + it = m_players.erase(it); + } + else + { + ++it; + } + } + + for (auto it = m_sorted_players.begin(); it != m_sorted_players.end();) + { + if (!it->second->is_trusted) + { + it = m_sorted_players.erase(it); + } + else + { + ++it; + } + } + } + std::shared_ptr player_database_service::get_player_by_rockstar_id(uint64_t rockstar_id) { if (m_players.contains(rockstar_id)) diff --git a/src/services/player_database/player_database_service.hpp b/src/services/player_database/player_database_service.hpp index 1a7114e4..f8407740 100644 --- a/src/services/player_database/player_database_service.hpp +++ b/src/services/player_database/player_database_service.hpp @@ -47,6 +47,7 @@ namespace big std::map>& get_sorted_players(); std::shared_ptr get_player_by_rockstar_id(uint64_t rockstar_id); std::shared_ptr get_or_create_player(player_ptr player); + void remove_untrusted_players(); void update_rockstar_id(uint64_t old, uint64_t _new); void remove_rockstar_id(uint64_t rockstar_id); diff --git a/src/views/network/view_player_database.cpp b/src/views/network/view_player_database.cpp index fc5736a6..6a4847e6 100644 --- a/src/views/network/view_player_database.cpp +++ b/src/views/network/view_player_database.cpp @@ -281,6 +281,33 @@ namespace big ImGui::EndChild(); } + if (ImGui::Button("REMOVE_UNTRUSTED"_T.data())) + { + ImGui::OpenPopup("##removeuntrusted"); + } + + if (ImGui::BeginPopupModal("##removeuntrusted")) + { + ImGui::Text("VIEW_NET_PLAYER_DB_ARE_YOU_SURE"_T.data()); + + if (ImGui::Button("YES"_T.data())) + { + g_player_database_service->set_selected(nullptr); + g_player_database_service->remove_untrusted_players(); + g_player_database_service->save(); + ImGui::CloseCurrentPopup(); + } + ImGui::SameLine(); + if (ImGui::Button("NO"_T.data())) + { + ImGui::CloseCurrentPopup(); + } + + ImGui::EndPopup(); + } + + ImGui::SameLine(); + if (ImGui::Button("REMOVE_ALL"_T.data())) { ImGui::OpenPopup("##removeall"); @@ -307,8 +334,6 @@ namespace big ImGui::EndPopup(); } - ImGui::SameLine(); - components::button("RELOAD_PLYR_ONLINE_STATES"_T, [] { g_player_database_service->update_player_states(); });