mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-19 13:28:25 +00:00
Let world dispatch expedition expire warnings
This depends on C++14 remaining enabled for chrono literals
This commit is contained in:
@@ -43,6 +43,7 @@ Expedition::Expedition(
|
||||
m_duration(duration)
|
||||
{
|
||||
m_expire_time = m_start_time + m_duration;
|
||||
m_warning_cooldown_timer.Enable();
|
||||
}
|
||||
|
||||
void Expedition::SendZonesExpeditionDeleted()
|
||||
@@ -64,6 +65,16 @@ void Expedition::SendZonesDurationUpdate()
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
void Expedition::SendZonesExpireWarning(uint32_t minutes_remaining)
|
||||
{
|
||||
uint32_t pack_size = sizeof(ServerExpeditionExpireWarning_Struct);
|
||||
auto pack = std::unique_ptr<ServerPacket>(new ServerPacket(ServerOP_ExpeditionExpireWarning, pack_size));
|
||||
auto buf = reinterpret_cast<ServerExpeditionExpireWarning_Struct*>(pack->pBuffer);
|
||||
buf->expedition_id = GetID();
|
||||
buf->minutes_remaining = minutes_remaining;
|
||||
zoneserver_list.SendPacket(pack.get());
|
||||
}
|
||||
|
||||
void Expedition::UpdateDzSecondsRemaining(uint32_t seconds_remaining)
|
||||
{
|
||||
auto now = std::chrono::system_clock::now();
|
||||
@@ -88,6 +99,28 @@ void Expedition::UpdateDzSecondsRemaining(uint32_t seconds_remaining)
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::system_clock::duration Expedition::GetRemainingDuration() const
|
||||
{
|
||||
return m_expire_time - std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
void Expedition::CheckExpireWarning()
|
||||
{
|
||||
if (m_warning_cooldown_timer.Check(false))
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
auto remaining = GetRemainingDuration();
|
||||
if ((remaining > 14min && remaining < 15min) ||
|
||||
(remaining > 4min && remaining < 5min) ||
|
||||
(remaining > 0min && remaining < 1min))
|
||||
{
|
||||
int minutes = std::chrono::duration_cast<std::chrono::minutes>(remaining).count() + 1;
|
||||
SendZonesExpireWarning(minutes);
|
||||
m_warning_cooldown_timer.Start(70000); // 1 minute 10 seconds
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExpeditionCache::LoadActiveExpeditions()
|
||||
{
|
||||
BenchTimer benchmark;
|
||||
@@ -205,6 +238,10 @@ void ExpeditionCache::Process()
|
||||
|
||||
it->SetPendingDelete(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
it->CheckExpireWarning();
|
||||
}
|
||||
|
||||
it = is_deleted ? m_expeditions.erase(it) : it + 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user