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
This commit is contained in:
hg
2020-05-16 08:41:17 -04:00
parent 26176f44fe
commit a9a3e46aa2
4 changed files with 19 additions and 11 deletions
+17 -6
View File
@@ -9608,7 +9608,7 @@ std::vector<ExpeditionLockoutTimer> 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<uint64_t>(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<uint32_t>(strtoul(row[1], nullptr, 10));
ExpeditionLockoutTimer lockout{ row[2], row[3], expire_time, original_duration };
AddExpeditionLockout(lockout);
AddExpeditionLockout(lockout, false, false);
}
}
SendExpeditionLockoutTimers();