feat(PlayerDB): notify when player is online (#1386)

This commit is contained in:
Andreas Maerten 2023-06-06 13:37:45 +02:00 committed by GitHub
parent 70efa40afe
commit 1b389d44a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 11 deletions

View File

@ -51,11 +51,12 @@ namespace big
bool block_join = false;
int block_join_reason = 1;
bool is_modder = false;
bool notify_online = false;
std::unordered_set<int> infractions;
std::optional<CommandAccessLevel> command_access_level = std::nullopt;
PlayerOnlineStatus online_state = PlayerOnlineStatus::UNKNOWN;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(persistent_player, name, rockstar_id, block_join, block_join_reason, is_modder, infractions, command_access_level)
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(persistent_player, name, rockstar_id, block_join, block_join_reason, is_modder, notify_online, infractions, command_access_level)
};
};

View File

@ -137,12 +137,6 @@ namespace big
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::start_update_loop()
{
if (!g.player_db.update_player_online_states)
@ -168,7 +162,6 @@ namespace big
void player_database_service::update_player_states()
{
invalidate_player_states();
const auto player_count = m_players.size();
std::vector<std::vector<rage::rlGamerHandle>> gamer_handle_buckets;
@ -198,9 +191,17 @@ namespace big
{
if (const auto& it = m_players.find(bucket[i].m_rockstar_id); it != m_players.end())
{
it->second->online_state = PlayerOnlineStatus::OFFLINE;
if (online[i] == 1)
{
if (it->second->online_state == PlayerOnlineStatus::OFFLINE && it->second->notify_online)
{
g_notification_service->push_success("Player DB", std::format("{} is now online!", it->second->name));
}
it->second->online_state = PlayerOnlineStatus::ONLINE;
continue;
}
it->second->online_state = PlayerOnlineStatus::OFFLINE;
}
}
}

View File

@ -49,7 +49,6 @@ namespace big
void start_update_loop();
void update_player_states();
void invalidate_player_states();
};
inline player_database_service* g_player_database_service;

View File

@ -96,7 +96,8 @@ namespace big
if (ImGui::InputScalar("RID"_T.data(), ImGuiDataType_S64, &current_player->rockstar_id)
|| ImGui::Checkbox("IS_MODDER"_T.data(), &current_player->is_modder)
|| ImGui::Checkbox("BLOCK_JOIN"_T.data(), &current_player->block_join))
|| ImGui::Checkbox("BLOCK_JOIN"_T.data(), &current_player->block_join)
|| ImGui::Checkbox("Notify When Online", &current_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);