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 d92c0e330d
commit a1b5b210dd
4 changed files with 19 additions and 11 deletions

View File

@ -9619,7 +9619,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(),
@ -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<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) {
@ -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<uint32_t>(strtoul(row[1], nullptr, 10));
ExpeditionLockoutTimer lockout{ row[2], row[3], expire_time, original_duration };
AddExpeditionLockout(lockout);
AddExpeditionLockout(lockout, false, false);
}
}
SendExpeditionLockoutTimers();

View File

@ -1114,7 +1114,7 @@ public:
Client* client, const std::string& client_name, uint16_t chat_type,
uint32_t string_id, const std::initializer_list<std::string>& 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; }

View File

@ -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();
}
}

View File

@ -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) {