Player database improvements (#1705)
* feat(protections): add per-player sync block options * feat(player_database): improve player tracker * fix(rapid_fire): remove unnecessary log statement * fix(player_database): default state should be UNKNOWN, not INVALID
This commit is contained in:
@ -47,8 +47,10 @@ namespace big
|
||||
ImGui::SameLine();
|
||||
components::button("JOIN_SESSION_INFO"_T, [] {
|
||||
rage::rlSessionInfo info;
|
||||
g_pointers->m_gta.m_decode_session_info(&info, base64, nullptr);
|
||||
session::join_session(info);
|
||||
if (g_pointers->m_gta.m_decode_session_info(&info, base64, nullptr))
|
||||
session::join_session(info);
|
||||
else
|
||||
g_notification_service->push_error("Join", "Session info is invalid");
|
||||
});
|
||||
|
||||
components::button("COPY_SESSION_INFO"_T, [] {
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "core/data/command_access_levels.hpp"
|
||||
#include "core/data/infractions.hpp"
|
||||
#include "fiber_pool.hpp"
|
||||
#include "gta/enums.hpp"
|
||||
#include "pointers.hpp"
|
||||
#include "services/api/api_service.hpp"
|
||||
#include "services/player_database/player_database_service.hpp"
|
||||
@ -17,6 +18,18 @@ namespace big
|
||||
bool notes_dirty = false;
|
||||
std::shared_ptr<persistent_player> current_player;
|
||||
|
||||
ImVec4 get_player_color(persistent_player& player)
|
||||
{
|
||||
if (player.session_type == GSType::Unknown)
|
||||
return ImVec4(.5f, .5f, .5f, 1.0f);
|
||||
else if (player.session_type == GSType::Invalid)
|
||||
return ImVec4(1.f, 0.f, 0.f, 1.f);
|
||||
else if (!player_database_service::is_joinable_session(player.session_type))
|
||||
return ImVec4(1.f, 1.f, 0.f, 1.f);
|
||||
else
|
||||
return ImVec4(0.f, 1.f, 0.f, 1.f);
|
||||
}
|
||||
|
||||
void draw_player_db_entry(std::shared_ptr<persistent_player> player, const std::string& lower_search)
|
||||
{
|
||||
std::string name = player->name;
|
||||
@ -28,15 +41,9 @@ namespace big
|
||||
|
||||
float circle_size = 7.5f;
|
||||
auto cursor_pos = ImGui::GetCursorScreenPos();
|
||||
auto plyr_state = player->online_state;
|
||||
|
||||
//render status circle
|
||||
ImGui::GetWindowDrawList()->AddCircleFilled(ImVec2(cursor_pos.x + 4.f + circle_size, cursor_pos.y + 4.f + circle_size),
|
||||
circle_size,
|
||||
ImColor(plyr_state == PlayerOnlineStatus::ONLINE ? ImVec4(0.f, 1.f, 0.f, 1.f) :
|
||||
plyr_state == PlayerOnlineStatus::OFFLINE ? ImVec4(1.f, 0.f, 0.f, 1.f) :
|
||||
plyr_state == PlayerOnlineStatus::UNKNOWN ? ImVec4(.5f, .5f, .5f, 1.0f) :
|
||||
ImVec4(.5f, .5f, .5f, 1.0f)));
|
||||
ImGui::GetWindowDrawList()->AddCircleFilled(ImVec2(cursor_pos.x + 4.f + circle_size, cursor_pos.y + 4.f + circle_size), circle_size, ImColor(get_player_color(*player)));
|
||||
|
||||
//we need some padding
|
||||
ImVec2 cursor = ImGui::GetCursorPos();
|
||||
@ -57,6 +64,9 @@ namespace big
|
||||
strncpy(note_buffer, current_player->notes.data(), sizeof(note_buffer));
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
ImGui::SetTooltip(player_database_service::get_session_type_str(player->session_type));
|
||||
|
||||
ImGui::PopID();
|
||||
}
|
||||
}
|
||||
@ -76,13 +86,20 @@ namespace big
|
||||
|
||||
for (auto& player : item_arr | std::ranges::views::values)
|
||||
{
|
||||
if (player->online_state == PlayerOnlineStatus::ONLINE)
|
||||
if (player_database_service::is_joinable_session(player->session_type))
|
||||
draw_player_db_entry(player, lower_search);
|
||||
}
|
||||
|
||||
for (auto& player : item_arr | std::ranges::views::values)
|
||||
{
|
||||
if (player->online_state != PlayerOnlineStatus::ONLINE)
|
||||
if (!player_database_service::is_joinable_session(player->session_type) && player->session_type != GSType::Invalid
|
||||
&& player->session_type != GSType::Unknown)
|
||||
draw_player_db_entry(player, lower_search);
|
||||
}
|
||||
|
||||
for (auto& player : item_arr | std::ranges::views::values)
|
||||
{
|
||||
if (player->session_type == GSType::Invalid || player->session_type == GSType::Unknown)
|
||||
draw_player_db_entry(player, lower_search);
|
||||
}
|
||||
}
|
||||
@ -107,7 +124,7 @@ namespace big
|
||||
if (ImGui::InputScalar("RID"_T.data(), ImGuiDataType_S64, ¤t_player->rockstar_id)
|
||||
|| ImGui::Checkbox("IS_MODDER"_T.data(), ¤t_player->is_modder)
|
||||
|| ImGui::Checkbox("BLOCK_JOIN"_T.data(), ¤t_player->block_join)
|
||||
|| ImGui::Checkbox("Notify When Online", ¤t_player->notify_online))
|
||||
|| ImGui::Checkbox("Track Player", ¤t_player->notify_online))
|
||||
{
|
||||
if (current_player->rockstar_id != selected->rockstar_id)
|
||||
g_player_database_service->update_rockstar_id(selected->rockstar_id, current_player->rockstar_id);
|
||||
@ -212,10 +229,28 @@ namespace big
|
||||
|
||||
if (ImGui::Button("REMOVE_ALL"_T.data()))
|
||||
{
|
||||
g_player_database_service->set_selected(nullptr);
|
||||
g_player_database_service->get_players().clear();
|
||||
g_player_database_service->get_sorted_players().clear();
|
||||
g_player_database_service->save();
|
||||
ImGui::OpenPopup("##removeall");
|
||||
}
|
||||
|
||||
if (ImGui::BeginPopupModal("##removeall"))
|
||||
{
|
||||
ImGui::Text("Are you sure?");
|
||||
|
||||
if (ImGui::Button("Yes"))
|
||||
{
|
||||
g_player_database_service->set_selected(nullptr);
|
||||
g_player_database_service->get_players().clear();
|
||||
g_player_database_service->get_sorted_players().clear();
|
||||
g_player_database_service->save();
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("No"))
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
@ -224,8 +259,18 @@ namespace big
|
||||
g_player_database_service->update_player_states();
|
||||
});
|
||||
|
||||
if (components::command_checkbox<"player_db_auto_update_states">())
|
||||
g_player_database_service->start_update_loop();
|
||||
if (ImGui::TreeNode("Player Tracking"))
|
||||
{
|
||||
if (components::command_checkbox<"player_db_auto_update_states">("Enable"))
|
||||
g_player_database_service->start_update_loop();
|
||||
ImGui::Checkbox("Notify When Online", &g.player_db.notify_when_online);
|
||||
ImGui::Checkbox("Notify When Joinable", &g.player_db.notify_when_joinable);
|
||||
ImGui::Checkbox("Notify When Unjoinable", &g.player_db.notify_when_unjoinable);
|
||||
ImGui::Checkbox("Notify When Offline", &g.player_db.notify_when_offline);
|
||||
ImGui::Checkbox("Notify On Session Type Change", &g.player_db.notify_on_session_type_change);
|
||||
ImGui::Checkbox("Notify On Session Change", &g.player_db.notify_on_session_change);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
components::sub_title("NEW_ENTRY"_T);
|
||||
@ -244,7 +289,7 @@ namespace big
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("SEARCH"_T.data()))
|
||||
{
|
||||
g_thread_pool->push([]{
|
||||
g_thread_pool->push([] {
|
||||
if (!g_api_service->get_rid_from_username(new_name, *(uint64_t*)&new_rockstar_id))
|
||||
{
|
||||
g_notification_service->push_error("New Player DB Entry", std::format("No user '{}' called could be found.", new_name));
|
||||
|
Reference in New Issue
Block a user