From bd81530a2a92d8613cffacee313964d157a02099 Mon Sep 17 00:00:00 2001 From: r4dish Date: Mon, 17 Jun 2024 22:57:52 +0300 Subject: [PATCH] Core/Misc: Update instance enter times only when it's really needed. (cherry picked from commit c6906948f7352eee52174434c4626ecf98eb8eab) --- src/server/game/Entities/Player/Player.cpp | 37 +++++++++++++++------- src/server/game/Entities/Player/Player.h | 3 +- src/server/game/Maps/Map.cpp | 2 +- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index ccf45f8de0..28ddb36cd5 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -1097,17 +1097,6 @@ void Player::Update(uint32 p_time) UpdateEnchantTime(p_time); UpdateHomebindTime(p_time); - if (!_instanceResetTimes.empty()) - { - for (InstanceTimeMap::iterator itr = _instanceResetTimes.begin(); itr != _instanceResetTimes.end();) - { - if (itr->second < now) - _instanceResetTimes.erase(itr++); - else - ++itr; - } - } - Pet* pet = GetPet(); if (pet && !pet->IsWithinDistInMap(this, GetMap()->GetVisibilityRange()) && !pet->isPossessed()) //if (pet && !pet->IsWithinDistInMap(this, GetMap()->GetVisibilityDistance()) && (GetCharmGUID() && (pet->GetGUID() != GetCharmGUID()))) @@ -18263,6 +18252,8 @@ bool Player::LoadFromDB(ObjectGuid guid, CharacterDatabaseQueryHolder const& hol SetUpdateFieldValue(m_values.ModifyValue(&Player::m_activePlayerData).ModifyValue(&UF::ActivePlayerData::YesterdayHonorableKills), fields.yesterdayKills); _LoadInstanceTimeRestrictions(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_INSTANCE_LOCK_TIMES)); + UpdateInstanceEnterTimes(); + _LoadBGData(holder.GetPreparedResult(PLAYER_LOGIN_QUERY_LOAD_BG_DATA)); GetSession()->SetPlayer(this); @@ -20174,10 +20165,16 @@ bool Player::CheckInstanceValidity(bool /*isLogin*/) return true; } -bool Player::CheckInstanceCount(uint32 instanceId) const +bool Player::UpdateAndCheckInstanceCount(uint32 instanceId) { + UpdateInstanceEnterTimes(); + if (_instanceResetTimes.size() < sWorld->getIntConfig(CONFIG_MAX_INSTANCES_PER_HOUR)) return true; + + if (instanceId == 0) + return false; + return _instanceResetTimes.find(instanceId) != _instanceResetTimes.end(); } @@ -20187,6 +20184,22 @@ void Player::AddInstanceEnterTime(uint32 instanceId, time_t enterTime) _instanceResetTimes.insert(InstanceTimeMap::value_type(instanceId, enterTime + HOUR)); } +void Player::UpdateInstanceEnterTimes() +{ + if (_instanceResetTimes.empty()) + return; + + time_t now = GameTime::GetGameTime(); + + for (InstanceTimeMap::iterator itr = _instanceResetTimes.begin(); itr != _instanceResetTimes.end();) + { + if (itr->second < now) + itr = _instanceResetTimes.erase(itr); + else + ++itr; + } +} + WorldSafeLocsEntry const* Player::GetInstanceEntrance(uint32 targetMapId) { WorldSafeLocsEntry const* entranceLocation = nullptr; diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 32804ae5c0..dd34189b58 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2781,8 +2781,9 @@ class TC_GAME_API Player final : public Unit, public GridObject void SendRaidInfo(); bool Satisfy(AccessRequirement const* ar, uint32 target_map, TransferAbortParams* params = nullptr, bool report = false); bool CheckInstanceValidity(bool /*isLogin*/); - bool CheckInstanceCount(uint32 instanceId) const; + bool UpdateAndCheckInstanceCount(uint32 instanceId); void AddInstanceEnterTime(uint32 instanceId, time_t enterTime); + void UpdateInstanceEnterTimes(); WorldSafeLocsEntry const* GetInstanceEntrance(uint32 targetMapId); // last used pet number (for BG's) diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index c1f205a981..585bdfa7dd 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1836,7 +1836,7 @@ TransferAbortParams Map::PlayerCannotEnter(uint32 mapid, Player* player) return denyReason; // players are only allowed to enter 10 instances per hour - if (!entry->GetFlags2().HasFlag(MapFlags2::IgnoreInstanceFarmLimit) && entry->IsDungeon() && !player->CheckInstanceCount(instanceIdToCheck) && !player->isDead()) + if (!entry->GetFlags2().HasFlag(MapFlags2::IgnoreInstanceFarmLimit) && entry->IsDungeon() && !player->UpdateAndCheckInstanceCount(instanceIdToCheck) && !player->isDead()) return TRANSFER_ABORT_TOO_MANY_INSTANCES; }