Core/Misc: Update instance enter times only when it's really needed.

(cherry picked from commit c6906948f7352eee52174434c4626ecf98eb8eab)
This commit is contained in:
r4dish
2026-06-01 16:10:34 +02:00
committed by Shauren
parent 9cd5d47014
commit bd81530a2a
3 changed files with 28 additions and 14 deletions
+25 -12
View File
@@ -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;
+2 -1
View File
@@ -2781,8 +2781,9 @@ class TC_GAME_API Player final : public Unit, public GridObject<Player>
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)
+1 -1
View File
@@ -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;
}