From a9a3e46aa2e19825afe1e72ef8d85c04980dbfa8 Mon Sep 17 00:00:00 2001 From: hg <4683435+hgtw@users.noreply.github.com> Date: Sat, 16 May 2020 08:41:17 -0400 Subject: [PATCH] Send client lockout update in lockout methods Add optional client update argument to client lockout methods This is better than requiring callers to manually send the update --- zone/client.cpp | 23 +++++++++++++++++------ zone/client.h | 4 ++-- zone/expedition.cpp | 2 -- zone/lua_client.cpp | 1 - 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/zone/client.cpp b/zone/client.cpp index 27252d2c3..032254ee3 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -9608,7 +9608,7 @@ std::vector Client::GetExpeditionLockouts(const std::str return lockouts; } -void Client::AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db) +void Client::AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db, bool update_client) { // todo: support for account based lockouts like live AoC expeditions auto it = std::find_if(m_expedition_lockouts.begin(), m_expedition_lockouts.end(), @@ -9625,9 +9625,15 @@ void Client::AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool up m_expedition_lockouts.emplace_back(lockout); } - if (update_db) { // for quest api + if (update_db) // for quest api + { ExpeditionDatabase::InsertCharacterLockouts(CharacterID(), { lockout }, true); } + + if (update_client) + { + SendExpeditionLockoutTimers(); + } } void Client::AddNewExpeditionLockout( @@ -9637,11 +9643,10 @@ void Client::AddNewExpeditionLockout( auto expire_time = static_cast(std::chrono::system_clock::to_time_t(expire_at)); ExpeditionLockoutTimer lockout{ expedition_name, event_name, expire_time, seconds }; AddExpeditionLockout(lockout, true); - SendExpeditionLockoutTimers(); } void Client::RemoveExpeditionLockout( - const std::string& expedition_name, const std::string& event_name, bool update_db) + const std::string& expedition_name, const std::string& event_name, bool update_db, bool update_client) { m_expedition_lockouts.erase(std::remove_if(m_expedition_lockouts.begin(), m_expedition_lockouts.end(), [&](const ExpeditionLockoutTimer& lockout) { @@ -9649,9 +9654,15 @@ void Client::RemoveExpeditionLockout( } ), m_expedition_lockouts.end()); - if (update_db) { // for quest api + if (update_db) // for quest api + { ExpeditionDatabase::DeleteCharacterLockout(CharacterID(), expedition_name, event_name); } + + if (update_client) + { + SendExpeditionLockoutTimers(); + } } void Client::RemoveAllExpeditionLockouts(std::string expedition_name) @@ -9703,7 +9714,7 @@ void Client::LoadAllExpeditionLockouts() auto expire_time = strtoull(row[0], nullptr, 10); auto original_duration = static_cast(strtoul(row[1], nullptr, 10)); ExpeditionLockoutTimer lockout{ row[2], row[3], expire_time, original_duration }; - AddExpeditionLockout(lockout); + AddExpeditionLockout(lockout, false, false); } } SendExpeditionLockoutTimers(); diff --git a/zone/client.h b/zone/client.h index c7f7b78e1..415de3584 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1113,7 +1113,7 @@ public: Client* client, const std::string& client_name, uint16_t chat_type, uint32_t string_id, const std::initializer_list& parameters = {}); - void AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db = false); + void AddExpeditionLockout(const ExpeditionLockoutTimer& lockout, bool update_db = false, bool update_client = true); void AddNewExpeditionLockout(const std::string& expedition_name, const std::string& event_name, uint32_t duration); Expedition* CreateExpedition( std::string zone_name, uint32 version, uint32 duration, std::string expedition_name, @@ -1128,7 +1128,7 @@ public: bool HasExpeditionLockout(const std::string& expedition_name, const std::string& event_name, bool include_expired = false); bool IsInExpedition() const { return m_expedition_id != 0; } void RemoveAllExpeditionLockouts(std::string expedition_name = {}); - void RemoveExpeditionLockout(const std::string& expedition_name, const std::string& event_name, bool update_db = false); + void RemoveExpeditionLockout(const std::string& expedition_name, const std::string& event_name, bool update_db = false, bool update_client = true); void SendExpeditionLockoutTimers(); void SetExpeditionID(uint32 expedition_id) { m_expedition_id = expedition_id; }; void SetPendingExpeditionInvite(ExpeditionInvite&& invite) { m_pending_expedition_invite = invite; } diff --git a/zone/expedition.cpp b/zone/expedition.cpp index 7a9ce5b00..c800c8d78 100644 --- a/zone/expedition.cpp +++ b/zone/expedition.cpp @@ -1192,7 +1192,6 @@ void Expedition::ProcessLockoutUpdate( { member_client->RemoveExpeditionLockout(m_expedition_name, event_name); } - member_client->SendExpeditionLockoutTimers(); } } @@ -1214,7 +1213,6 @@ void Expedition::ProcessLockoutUpdate( } else { client->RemoveExpeditionLockout(m_expedition_name, event_name); } - client->SendExpeditionLockoutTimers(); } } diff --git a/zone/lua_client.cpp b/zone/lua_client.cpp index 404831301..a99b1afa2 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -1709,7 +1709,6 @@ void Lua_Client::RemoveAllExpeditionLockouts(std::string expedition_name) { void Lua_Client::RemoveExpeditionLockout(std::string expedition_name, std::string event_name) { Lua_Safe_Call_Void(); self->RemoveExpeditionLockout(expedition_name, event_name, true); - self->SendExpeditionLockoutTimers(); } bool Lua_Client::HasExpeditionLockout(std::string expedition_name, std::string event_name) {