Skip to content

Commit

Permalink
PlayerDB Delete Untrusted Players (#3053)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkwapisz committed May 6, 2024
1 parent d75bebd commit f4449ba
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/services/player_database/player_database_service.cpp
Expand Up @@ -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<persistent_player> player_database_service::get_player_by_rockstar_id(uint64_t rockstar_id)
{
if (m_players.contains(rockstar_id))
Expand Down
1 change: 1 addition & 0 deletions src/services/player_database/player_database_service.hpp
Expand Up @@ -47,6 +47,7 @@ namespace big
std::map<std::string, std::shared_ptr<persistent_player>>& get_sorted_players();
std::shared_ptr<persistent_player> get_player_by_rockstar_id(uint64_t rockstar_id);
std::shared_ptr<persistent_player> 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);

Expand Down
29 changes: 27 additions & 2 deletions src/views/network/view_player_database.cpp
Expand Up @@ -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");
Expand All @@ -307,8 +334,6 @@ namespace big
ImGui::EndPopup();
}

ImGui::SameLine();

components::button("RELOAD_PLYR_ONLINE_STATES"_T, [] {
g_player_database_service->update_player_states();
});
Expand Down

0 comments on commit f4449ba

Please sign in to comment.