aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Handlers
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2020-01-02 14:19:35 +0100
committerShauren <shauren.trinity@gmail.com>2022-10-04 00:19:38 +0200
commit9b924522d0549dd67b10e2cbdfc20297dd21e182 (patch)
treef0fcdf96902b7c497c1bc65db83621a8dfadf43a /src/server/game/Handlers
parenta131542855d23022714a97640be1c8d68a741c31 (diff)
Core/Instances: Delete InstanceSaveMgr and replace most of its uses with new InstanceLockMgr
Diffstat (limited to 'src/server/game/Handlers')
-rw-r--r--src/server/game/Handlers/CalendarHandler.cpp63
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp4
-rw-r--r--src/server/game/Handlers/MiscHandler.cpp23
-rw-r--r--src/server/game/Handlers/MovementHandler.cpp25
4 files changed, 49 insertions, 66 deletions
diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp
index f7ec9de1d99..f4831d15b29 100644
--- a/src/server/game/Handlers/CalendarHandler.cpp
+++ b/src/server/game/Handlers/CalendarHandler.cpp
@@ -22,7 +22,7 @@ SMSG_CALENDAR_EVENT_INVITE_NOTES [ ObjectGuid(InviteGuid), bool(ClearPend
?CMSG_CALENDAR_EVENT_INVITE_NOTES [ ObjectGuid(Guid), uint64(EventID), uint64(InviteID), uint64(ModeratorID), std::string(Notes) ]
SMSG_CALENDAR_EVENT_INVITE_NOTES_ALERT [ uint64(EventID), std::string(Notes) ]
SMSG_CALENDAR_EVENT_INVITE_STATUS_ALERT [ uint64(EventID), uint32(Date), uint32(Flags), uint8(Status) ]
-SMSG_CALENDAR_RAID_LOCKOUT_UPDATED SendCalendarRaidLockoutUpdated(InstanceSave const* save)
+SMSG_CALENDAR_RAID_LOCKOUT_UPDATED SendCalendarRaidLockoutUpdated(InstanceLock const* save)
@todo
@@ -44,7 +44,6 @@ Copied events should probably have a new owner
#include "Guild.h"
#include "GuildMgr.h"
#include "InstanceLockMgr.h"
-#include "InstanceSaveMgr.h"
#include "Log.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
@@ -98,7 +97,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPackets::Calendar::CalendarGet
lockoutInfo.MapID = lock->GetMapId();
lockoutInfo.DifficultyID = lock->GetDifficultyId();
- lockoutInfo.ExpireTime = int32(std::chrono::duration_cast<Seconds>(lock->GetEffectiveExpiryTime() - GameTime::GetSystemTime()).count());
+ lockoutInfo.ExpireTime = int32(std::max(std::chrono::duration_cast<Seconds>(lock->GetEffectiveExpiryTime() - GameTime::GetSystemTime()).count(), SI64LIT(0)));
lockoutInfo.InstanceID = lock->GetInstanceId();
packet.RaidLockouts.push_back(lockoutInfo);
@@ -550,20 +549,23 @@ void WorldSession::HandleSetSavedInstanceExtend(WorldPackets::Calendar::SetSaved
{
TC_LOG_DEBUG("network", "CMSG_SET_SAVED_INSTANCE_EXTEND - MapId: %u, Difficulty: %u, ToggleExtend: %s", setSavedInstanceExtend.MapID, setSavedInstanceExtend.DifficultyID, setSavedInstanceExtend.Extend ? "On" : "Off");
- if (Player* player = GetPlayer())
- {
- InstancePlayerBind* instanceBind = player->GetBoundInstance(setSavedInstanceExtend.MapID, Difficulty(setSavedInstanceExtend.DifficultyID), setSavedInstanceExtend.Extend); // include expired instances if we are toggling extend on
- if (!instanceBind || !instanceBind->save || !instanceBind->perm)
- return;
+ // cannot modify locks currently in use
+ if (_player->GetMapId() == uint32(setSavedInstanceExtend.MapID))
+ return;
- BindExtensionState newState;
- if (!setSavedInstanceExtend.Extend || instanceBind->extendState == EXTEND_STATE_EXPIRED)
- newState = EXTEND_STATE_NORMAL;
- else
- newState = EXTEND_STATE_EXTENDED;
+ std::pair<InstanceResetTimePoint, InstanceResetTimePoint> expiryTimes = sInstanceLockMgr.UpdateInstanceLockExtensionForPlayer(_player->GetGUID(),
+ { uint32(setSavedInstanceExtend.MapID), Difficulty(setSavedInstanceExtend.DifficultyID) }, setSavedInstanceExtend.Extend);
- player->BindToInstance(instanceBind->save, true, newState, false);
- }
+ if (expiryTimes.first == InstanceResetTimePoint::min())
+ return;
+
+ WorldPackets::Calendar::CalendarRaidLockoutUpdated calendarRaidLockoutUpdated;
+ calendarRaidLockoutUpdated.ServerTime = GameTime::GetGameTime();
+ calendarRaidLockoutUpdated.MapID = setSavedInstanceExtend.MapID;
+ calendarRaidLockoutUpdated.DifficultyID = setSavedInstanceExtend.DifficultyID;
+ calendarRaidLockoutUpdated.OldTimeRemaining = std::max(std::chrono::duration_cast<Seconds>(expiryTimes.first - GameTime::GetSystemTime()).count(), SI64LIT(0));
+ calendarRaidLockoutUpdated.NewTimeRemaining = std::max(std::chrono::duration_cast<Seconds>(expiryTimes.second - GameTime::GetSystemTime()).count(), SI64LIT(0));
+ SendPacket(calendarRaidLockoutUpdated.Write());
}
// ----------------------------------- SEND ------------------------------------
@@ -575,39 +577,10 @@ void WorldSession::SendCalendarRaidLockoutAdded(InstanceLock const* lock)
calendarRaidLockoutAdded.ServerTime = uint32(GameTime::GetGameTime());
calendarRaidLockoutAdded.MapID = int32(lock->GetMapId());
calendarRaidLockoutAdded.DifficultyID = lock->GetDifficultyId();
- calendarRaidLockoutAdded.TimeRemaining = int32(std::chrono::duration_cast<Seconds>(lock->GetExpiryTime() - GameTime::GetSystemTime()).count());
+ calendarRaidLockoutAdded.TimeRemaining = int32(std::chrono::duration_cast<Seconds>(lock->GetEffectiveExpiryTime() - GameTime::GetSystemTime()).count());
SendPacket(calendarRaidLockoutAdded.Write());
}
-void WorldSession::SendCalendarRaidLockoutUpdated(InstanceSave const* save)
-{
- if (!save)
- return;
-
- ObjectGuid guid = _player->GetGUID();
- TC_LOG_DEBUG("network", "SMSG_CALENDAR_RAID_LOCKOUT_UPDATED [%s] Map: %u, Difficulty %u",
- guid.ToString().c_str(), save->GetMapId(), static_cast<uint32>(save->GetDifficultyID()));
-
- time_t currTime = GameTime::GetGameTime();
-
- WorldPackets::Calendar::CalendarRaidLockoutUpdated packet;
- packet.DifficultyID = save->GetDifficultyID();
- packet.MapID = save->GetMapId();
- packet.NewTimeRemaining = 0; // FIXME
- packet.OldTimeRemaining = save->GetResetTime() - currTime;
-
- SendPacket(packet.Write());
-}
-
-void WorldSession::SendCalendarRaidLockoutRemoved(InstanceSave const* save)
-{
- WorldPackets::Calendar::CalendarRaidLockoutRemoved calendarRaidLockoutRemoved;
- calendarRaidLockoutRemoved.InstanceID = save->GetInstanceId();
- calendarRaidLockoutRemoved.MapID = int32(save->GetMapId());
- calendarRaidLockoutRemoved.DifficultyID = save->GetDifficultyID();
- SendPacket(calendarRaidLockoutRemoved.Write());
-}
-
void WorldSession::SendCalendarRaidLockoutRemoved(InstanceLock const* lock)
{
WorldPackets::Calendar::CalendarRaidLockoutRemoved calendarRaidLockoutRemoved;
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index b1810319895..993d47cabc9 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -96,10 +96,6 @@ bool LoginQueryHolder::Initialize()
stmt->setUInt64(0, lowGuid);
res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_GROUP, stmt);
- stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_INSTANCE);
- stmt->setUInt64(0, lowGuid);
- res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_BOUND_INSTANCES, stmt);
-
stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_AURAS);
stmt->setUInt64(0, lowGuid);
res &= SetPreparedQuery(PLAYER_LOGIN_QUERY_LOAD_AURAS, stmt);
diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp
index fa65c980f93..1bcf20acb93 100644
--- a/src/server/game/Handlers/MiscHandler.cpp
+++ b/src/server/game/Handlers/MiscHandler.cpp
@@ -35,8 +35,8 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
+#include "InstanceLockMgr.h"
#include "InstancePackets.h"
-#include "InstanceSaveMgr.h"
#include "InstanceScript.h"
#include "Language.h"
#include "Log.h"
@@ -644,18 +644,25 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPackets::AreaTrigger::AreaTrigge
if (!teleported)
{
WorldSafeLocsEntry const* entranceLocation = nullptr;
- InstanceSave* instanceSave = player->GetInstanceSave(at->target_mapId);
- if (instanceSave)
+ MapEntry const* mapEntry = sMapStore.AssertEntry(at->target_mapId);
+ if (mapEntry->Instanceable())
{
// Check if we can contact the instancescript of the instance for an updated entrance location
- if (Map* map = sMapMgr->FindMap(at->target_mapId, player->GetInstanceSave(at->target_mapId)->GetInstanceId()))
- if (InstanceMap* instanceMap = map->ToInstanceMap())
- if (InstanceScript* instanceScript = instanceMap->GetInstanceScript())
- entranceLocation = sObjectMgr->GetWorldSafeLoc(instanceScript->GetEntranceLocation());
+ if (uint32 targetInstanceId = sMapMgr->FindInstanceIdForPlayer(at->target_mapId, _player))
+ if (Map* map = sMapMgr->FindMap(at->target_mapId, targetInstanceId))
+ if (InstanceMap* instanceMap = map->ToInstanceMap())
+ if (InstanceScript* instanceScript = instanceMap->GetInstanceScript())
+ entranceLocation = sObjectMgr->GetWorldSafeLoc(instanceScript->GetEntranceLocation());
// Finally check with the instancesave for an entrance location if we did not get a valid one from the instancescript
if (!entranceLocation)
- entranceLocation = sObjectMgr->GetWorldSafeLoc(instanceSave->GetEntranceLocation());
+ {
+ Group* group = player->GetGroup();
+ Difficulty difficulty = group ? group->GetDifficultyID(mapEntry) : player->GetDifficultyID(mapEntry);
+ ObjectGuid instanceOwnerGuid = group ? group->GetRecentInstanceOwner(at->target_mapId) : player->GetGUID();
+ if (InstanceLock const* instanceLock = sInstanceLockMgr.FindActiveInstanceLock(instanceOwnerGuid, { mapEntry, sDB2Manager.GetDownscaledMapDifficultyData(at->target_mapId, difficulty) }))
+ entranceLocation = sObjectMgr->GetWorldSafeLoc(instanceLock->GetData()->EntranceWorldSafeLocId);
+ }
}
if (entranceLocation)
diff --git a/src/server/game/Handlers/MovementHandler.cpp b/src/server/game/Handlers/MovementHandler.cpp
index 0c027ea5f33..b28f83e03dc 100644
--- a/src/server/game/Handlers/MovementHandler.cpp
+++ b/src/server/game/Handlers/MovementHandler.cpp
@@ -22,8 +22,8 @@
#include "FlightPathMovementGenerator.h"
#include "GameTime.h"
#include "Garrison.h"
+#include "InstanceLockMgr.h"
#include "InstancePackets.h"
-#include "InstanceSaveMgr.h"
#include "Log.h"
#include "Map.h"
#include "MapManager.h"
@@ -193,17 +193,24 @@ void WorldSession::HandleMoveWorldportAck()
if (mEntry->IsDungeon())
{
// check if this instance has a reset time and send it to player if so
- Difficulty diff = newMap->GetDifficultyID();
- if (MapDifficultyEntry const* mapDiff = sDB2Manager.GetMapDifficultyData(mEntry->ID, diff))
+ MapDb2Entries entries{ mEntry->ID, newMap->GetDifficultyID() };
+ if (entries.MapDifficulty->HasResetSchedule())
{
- if (mapDiff->GetRaidDuration())
+ WorldPackets::Instance::RaidInstanceMessage raidInstanceMessage;
+ raidInstanceMessage.Type = RAID_INSTANCE_WELCOME;
+ raidInstanceMessage.MapID = mEntry->ID;
+ raidInstanceMessage.DifficultyID = newMap->GetDifficultyID();
+ if (InstanceLock const* playerLock = sInstanceLockMgr.FindActiveInstanceLock(GetPlayer()->GetGUID(), entries))
{
- if (time_t timeReset = sInstanceSaveMgr->GetResetTimeFor(mEntry->ID, diff))
- {
- uint32 timeleft = uint32(timeReset - GameTime::GetGameTime());
- player->SendInstanceResetWarning(mEntry->ID, diff, timeleft, true);
- }
+ raidInstanceMessage.Locked = !playerLock->IsExpired();
+ raidInstanceMessage.Extended = playerLock->IsExtended();
+ }
+ else
+ {
+ raidInstanceMessage.Locked = false;
+ raidInstanceMessage.Extended = false;
}
+ SendPacket(raidInstanceMessage.Write());
}
// check if instance is valid