aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2021-01-19 22:48:46 +0100
committerShauren <shauren.trinity@gmail.com>2022-10-04 00:19:38 +0200
commitab12e77cf72bcd361a380c8d1ed37d12fe0e1bbb (patch)
treecfda9c15ec15003ee32c2aa466af7afb4901bec9 /src/server/scripts/Commands
parent4ce1c6cdf419b52b889ad9dac7fb69d0059a1fe6 (diff)
Core/Commands: Restore instance management commands
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_instance.cpp177
1 files changed, 75 insertions, 102 deletions
diff --git a/src/server/scripts/Commands/cs_instance.cpp b/src/server/scripts/Commands/cs_instance.cpp
index 210f23ebae4..5eb1cb14940 100644
--- a/src/server/scripts/Commands/cs_instance.cpp
+++ b/src/server/scripts/Commands/cs_instance.cpp
@@ -28,12 +28,15 @@ EndScriptData */
#include "DB2Stores.h"
#include "GameTime.h"
#include "Group.h"
+#include "InstanceLockMgr.h"
#include "InstanceScript.h"
#include "Language.h"
#include "Map.h"
#include "MapManager.h"
#include "Player.h"
#include "RBAC.h"
+#include "Util.h"
+#include "World.h"
#include "WorldSession.h"
#include <sstream>
@@ -51,7 +54,6 @@ public:
{ "listbinds", HandleInstanceListBindsCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_LISTBINDS, Console::No },
{ "unbind", HandleInstanceUnbindCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_UNBIND, Console::No },
{ "stats", HandleInstanceStatsCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_STATS, Console::Yes },
- { "savedata", HandleInstanceSaveDataCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_SAVEDATA, Console::No },
{ "setbossstate", HandleInstanceSetBossStateCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_SET_BOSS_STATE, Console::Yes },
{ "getbossstate", HandleInstanceGetBossStateCommand, rbac::RBAC_PERM_COMMAND_INSTANCE_GET_BOSS_STATE, Console::Yes },
};
@@ -64,89 +66,81 @@ public:
return commandTable;
}
- static bool HandleInstanceListBindsCommand(ChatHandler* /*handler*/)
+ static bool HandleInstanceListBindsCommand(ChatHandler* handler)
{
- //Player* player = handler->getSelectedPlayer();
- //if (!player)
- // player = handler->GetSession()->GetPlayer();
-
- //uint32 counter = 0;
- //for (DifficultyEntry const* difficulty : sDifficultyStore)
- //{
- // auto binds = player->GetBoundInstances(Difficulty(difficulty->ID));
- // if (binds != player->m_boundInstances.end())
- // {
- // for (auto const& [mapId, bind] : binds->second)
- // {
- // InstanceSave* save = bind.save;
- // std::string timeleft = secsToTimeString(save->GetResetTime() - GameTime::GetGameTime(), TimeFormat::ShortText);
- // handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, mapId, save->GetInstanceId(), bind.perm ? "yes" : "no", bind.extendState == EXTEND_STATE_EXPIRED ? "expired" : bind.extendState == EXTEND_STATE_EXTENDED ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
- // counter++;
- // }
- // }
- //}
- //handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_PLAYER_BINDS, counter);
-
- //counter = 0;
- //if (Group* group = player->GetGroup())
- //{
- // for (DifficultyEntry const* difficulty : sDifficultyStore)
- // {
- // auto binds = group->GetBoundInstances(Difficulty(difficulty->ID));
- // if (binds != group->GetBoundInstanceEnd())
- // {
- // for (auto const& [mapId, bind] : binds->second)
- // {
- // InstanceSave* save = bind.save;
- // std::string timeleft = secsToTimeString(save->GetResetTime() - GameTime::GetGameTime(), TimeFormat::ShortText);
- // handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO, mapId, save->GetInstanceId(), bind.perm ? "yes" : "no", "-", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
- // counter++;
- // }
- // }
- // }
- //}
- //handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_GROUP_BINDS, counter);
+ Player* player = handler->getSelectedPlayer();
+ if (!player)
+ player = handler->GetSession()->GetPlayer();
+
+ InstanceResetTimePoint now = GameTime::GetTime<InstanceResetTimePoint::clock>();
+ std::vector<InstanceLock const*> instanceLocks = sInstanceLockMgr.GetInstanceLocksForPlayer(player->GetGUID());
+ for (InstanceLock const* instanceLock : instanceLocks)
+ {
+ MapDb2Entries entries{ instanceLock->GetMapId(), instanceLock->GetDifficultyId() };
+ std::string timeleft = !instanceLock->IsExpired() ? secsToTimeString(std::chrono::duration_cast<Seconds>(instanceLock->GetEffectiveExpiryTime() - now).count()) : "-";
+ handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_INFO,
+ entries.Map->ID, entries.Map->MapName[sWorld->GetDefaultDbcLocale()],
+ uint32(entries.MapDifficulty->DifficultyID), sDifficultyStore.AssertEntry(entries.MapDifficulty->DifficultyID)->Name[sWorld->GetDefaultDbcLocale()],
+ instanceLock->GetInstanceId(),
+ handler->GetTrinityString(instanceLock->IsExpired() ? LANG_YES : LANG_NO),
+ handler->GetTrinityString(instanceLock->IsExtended() ? LANG_YES : LANG_NO),
+ timeleft.c_str());
+ }
+ handler->PSendSysMessage(LANG_COMMAND_LIST_BIND_PLAYER_BINDS, uint32(instanceLocks.size()));
return true;
}
- static bool HandleInstanceUnbindCommand(ChatHandler* /*handler*/, Variant<uint32, EXACT_SEQUENCE("all")> /*mapArg*/, Optional<uint8> /*difficultyArg*/)
+ static bool HandleInstanceUnbindCommand(ChatHandler* handler, Variant<uint32, EXACT_SEQUENCE("all")> mapArg, Optional<uint32> difficultyArg)
{
- //Player* player = handler->getSelectedPlayer();
- //if (!player)
- // player = handler->GetSession()->GetPlayer();
-
- //uint16 counter = 0;
- //uint32 mapId = 0;
-
- //if (mapArg.holds_alternative<uint32>())
- //{
- // mapId = mapArg.get<uint32>();
- // if (!mapId)
- // return false;
- //}
-
- //for (DifficultyEntry const* difficulty : sDifficultyStore)
- //{
- // auto binds = player->GetBoundInstances(Difficulty(difficulty->ID));
- // if (binds != player->m_boundInstances.end())
- // {
- // for (auto itr = binds->second.begin(); itr != binds->second.end();)
- // {
- // InstanceSave const* save = itr->second.save;
- // if (itr->first != player->GetMapId() && (!mapId || mapId == itr->first) && (!difficultyArg || difficultyArg == save->GetDifficultyID()))
- // {
- // std::string timeleft = secsToTimeString(save->GetResetTime() - GameTime::GetGameTime(), TimeFormat::ShortText);
- // handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_UNBINDING, itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficultyID(), save->CanReset() ? "yes" : "no", timeleft.c_str());
- // player->UnbindInstance(itr, binds);
- // counter++;
- // }
- // else
- // ++itr;
- // }
- // }
- //}
- //handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_UNBOUND, counter);
+ Player* player = handler->getSelectedPlayer();
+ if (!player)
+ player = handler->GetSession()->GetPlayer();
+
+ Optional<uint32> mapId;
+ Optional<Difficulty> difficulty;
+
+ if (mapArg.holds_alternative<uint32>())
+ mapId = mapArg.get<uint32>();
+
+ if (difficultyArg && sDifficultyStore.LookupEntry(*difficultyArg))
+ difficulty = Difficulty(*difficultyArg);
+
+ std::vector<InstanceLock const*> locksReset;
+ std::vector<InstanceLock const*> locksNotReset;
+
+ sInstanceLockMgr.ResetInstanceLocksForPlayer(player->GetGUID(), mapId, difficulty, &locksReset, &locksNotReset);
+
+ InstanceResetTimePoint now = GameTime::GetTime<InstanceResetTimePoint::clock>();
+ for (InstanceLock const* instanceLock : locksReset)
+ {
+ MapDb2Entries entries{ instanceLock->GetMapId(), instanceLock->GetDifficultyId() };
+ std::string timeleft = !instanceLock->IsExpired() ? secsToTimeString(std::chrono::duration_cast<Seconds>(instanceLock->GetEffectiveExpiryTime() - now).count()) : "-";
+ handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_UNBINDING,
+ entries.Map->ID, entries.Map->MapName[sWorld->GetDefaultDbcLocale()],
+ uint32(entries.MapDifficulty->DifficultyID), sDifficultyStore.AssertEntry(entries.MapDifficulty->DifficultyID)->Name[sWorld->GetDefaultDbcLocale()],
+ instanceLock->GetInstanceId(),
+ handler->GetTrinityString(instanceLock->IsExpired() ? LANG_YES : LANG_NO),
+ handler->GetTrinityString(instanceLock->IsExtended() ? LANG_YES : LANG_NO),
+ timeleft.c_str());
+ }
+
+ handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_UNBOUND, uint32(locksReset.size()));
+
+ for (InstanceLock const* instanceLock : locksNotReset)
+ {
+ MapDb2Entries entries{ instanceLock->GetMapId(), instanceLock->GetDifficultyId() };
+ std::string timeleft = !instanceLock->IsExpired() ? secsToTimeString(std::chrono::duration_cast<Seconds>(instanceLock->GetEffectiveExpiryTime() - now).count()) : "-";
+ handler->PSendSysMessage(LANG_COMMAND_INST_UNBIND_FAILED,
+ entries.Map->ID, entries.Map->MapName[sWorld->GetDefaultDbcLocale()],
+ uint32(entries.MapDifficulty->DifficultyID), sDifficultyStore.AssertEntry(entries.MapDifficulty->DifficultyID)->Name[sWorld->GetDefaultDbcLocale()],
+ instanceLock->GetInstanceId(),
+ handler->GetTrinityString(instanceLock->IsExpired() ? LANG_YES : LANG_NO),
+ handler->GetTrinityString(instanceLock->IsExtended() ? LANG_YES : LANG_NO),
+ timeleft.c_str());
+ }
+
+ player->SendRaidInfo();
return true;
}
@@ -155,32 +149,11 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_INST_STAT_LOADED_INST, sMapMgr->GetNumInstances());
handler->PSendSysMessage(LANG_COMMAND_INST_STAT_PLAYERS_IN, sMapMgr->GetNumPlayersInInstances());
- //handler->PSendSysMessage(LANG_COMMAND_INST_STAT_SAVES, sInstanceSaveMgr->GetNumInstanceSaves());
- //handler->PSendSysMessage(LANG_COMMAND_INST_STAT_PLAYERSBOUND, sInstanceSaveMgr->GetNumBoundPlayersTotal());
- //handler->PSendSysMessage(LANG_COMMAND_INST_STAT_GROUPSBOUND, sInstanceSaveMgr->GetNumBoundGroupsTotal());
- return true;
- }
+ InstanceLocksStatistics statistics = sInstanceLockMgr.GetStatistics();
- static bool HandleInstanceSaveDataCommand(ChatHandler* handler)
- {
- //Player* player = handler->GetSession()->GetPlayer();
- //InstanceMap* map = player->GetMap()->ToInstanceMap();
- //if (!map)
- //{
- // handler->PSendSysMessage(LANG_NOT_DUNGEON);
- // handler->SetSentErrorMessage(true);
- // return false;
- //}
-
- //if (!map->GetInstanceScript())
- //{
- // handler->PSendSysMessage(LANG_NO_INSTANCE_DATA);
- // handler->SetSentErrorMessage(true);
- // return false;
- //}
-
- //map->GetInstanceScript()->SaveToDB();
+ handler->PSendSysMessage(LANG_COMMAND_INST_STAT_SAVES, statistics.InstanceCount);
+ handler->PSendSysMessage(LANG_COMMAND_INST_STAT_PLAYERSBOUND, statistics.PlayerCount);
return true;
}