feat(player_db): add player online status (#983)
This commit is contained in:
parent
c798bbe7c9
commit
60b61cbce2
@ -5,6 +5,13 @@
|
|||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
|
enum class PlayerOnlineStatus
|
||||||
|
{
|
||||||
|
UNKNOWN,
|
||||||
|
OFFLINE,
|
||||||
|
ONLINE
|
||||||
|
};
|
||||||
|
|
||||||
struct persistent_player
|
struct persistent_player
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -14,6 +21,7 @@ namespace big
|
|||||||
bool is_modder = false;
|
bool is_modder = false;
|
||||||
std::unordered_set<int> infractions;
|
std::unordered_set<int> infractions;
|
||||||
std::optional<CommandAccessLevel> command_access_level = std::nullopt;
|
std::optional<CommandAccessLevel> command_access_level = std::nullopt;
|
||||||
|
PlayerOnlineStatus online_state = PlayerOnlineStatus::UNKNOWN;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void to_json(nlohmann::json& j, const persistent_player& player)
|
static void to_json(nlohmann::json& j, const persistent_player& player)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "player_database_service.hpp"
|
#include "player_database_service.hpp"
|
||||||
#include "file_manager.hpp"
|
#include "file_manager.hpp"
|
||||||
|
#include "util/session.hpp"
|
||||||
|
#include "pointers.hpp"
|
||||||
|
|
||||||
namespace big
|
namespace big
|
||||||
{
|
{
|
||||||
@ -95,4 +97,39 @@ namespace big
|
|||||||
{
|
{
|
||||||
return m_selected;
|
return m_selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void player_database_service::invalidate_player_states()
|
||||||
|
{
|
||||||
|
for (auto& item : m_players)
|
||||||
|
item.second.online_state = PlayerOnlineStatus::UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
void player_database_service::update_player_states()
|
||||||
|
{
|
||||||
|
invalidate_player_states();
|
||||||
|
|
||||||
|
//fetch current stat for each player.. this will need some time.
|
||||||
|
for (auto& item : m_players)
|
||||||
|
{
|
||||||
|
auto& player = item.second;
|
||||||
|
rage::rlGamerHandle player_handle(player.rockstar_id);
|
||||||
|
rage::rlSessionByGamerTaskResult result;
|
||||||
|
bool success = false;
|
||||||
|
rage::rlTaskStatus state{};
|
||||||
|
|
||||||
|
if (g_pointers->m_start_get_session_by_gamer_handle(0, &player_handle, 1, &result, 1, &success, &state))
|
||||||
|
{
|
||||||
|
while (state.status == 1)
|
||||||
|
script::get_current()->yield();
|
||||||
|
|
||||||
|
if (state.status == 3 && success)
|
||||||
|
{
|
||||||
|
player.online_state = PlayerOnlineStatus::ONLINE;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player.online_state = PlayerOnlineStatus::OFFLINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -25,6 +25,9 @@ namespace big
|
|||||||
|
|
||||||
void set_selected(persistent_player* selected);
|
void set_selected(persistent_player* selected);
|
||||||
persistent_player* get_selected();
|
persistent_player* get_selected();
|
||||||
|
|
||||||
|
void update_player_states();
|
||||||
|
void invalidate_player_states();
|
||||||
};
|
};
|
||||||
|
|
||||||
inline player_database_service* g_player_database_service;
|
inline player_database_service* g_player_database_service;
|
||||||
|
@ -40,6 +40,27 @@ namespace big
|
|||||||
{
|
{
|
||||||
ImGui::PushID(item.first);
|
ImGui::PushID(item.first);
|
||||||
|
|
||||||
|
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)
|
||||||
|
));
|
||||||
|
|
||||||
|
//we need some padding
|
||||||
|
ImVec2 cursor = ImGui::GetCursorPos();
|
||||||
|
ImGui::SetCursorPos(ImVec2(cursor.x + 25.f, cursor.y));
|
||||||
|
|
||||||
if (components::selectable(player.name, &player == g_player_database_service->get_selected()))
|
if (components::selectable(player.name, &player == g_player_database_service->get_selected()))
|
||||||
{
|
{
|
||||||
g_player_database_service->set_selected(&player);
|
g_player_database_service->set_selected(&player);
|
||||||
@ -169,6 +190,13 @@ namespace big
|
|||||||
g_player_database_service->save();
|
g_player_database_service->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
components::button("RELOAD_PLYR_ONLINE_STATES"_T, []
|
||||||
|
{
|
||||||
|
g_player_database_service->update_player_states();
|
||||||
|
});
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
components::sub_title("NEW_ENTRY"_T);
|
components::sub_title("NEW_ENTRY"_T);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user