From a1b5b210ddda12c182586e233d31b7629dc6b1ca 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 14f0dcc5c..5621d344a 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -9619,7 +9619,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(), @@ -9636,9 +9636,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( @@ -9648,11 +9654,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) { @@ -9660,9 +9665,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) @@ -9714,7 +9725,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 58b0e8643..b08b21a83 100644 --- a/zone/client.h +++ b/zone/client.h @@ -1114,7 +1114,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, @@ -1129,7 +1129,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 c1e87cafc..e55658d24 100644 --- a/zone/lua_client.cpp +++ b/zone/lua_client.cpp @@ -1724,7 +1724,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) {