From aa3896d52af7b24ec0abfb2b43a4fb6fb3c29a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Sat, 26 Jun 2021 16:41:05 +0200 Subject: [PATCH] =?UTF-8?q?fix(Core):=20Undefined=20symbols=20ArenaSpectat?= =?UTF-8?q?or::HandleSpectatorSpectateC=E2=80=A6=20(#6580)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/game/Accounts/AccountMgr.cpp | 1 - .../game/ArenaSpectator/ArenaSpectator.cpp | 191 ++++++++++++++++++ .../game/ArenaSpectator/ArenaSpectator.h | 3 + src/server/scripts/Commands/cs_spectator.cpp | 181 +---------------- 4 files changed, 197 insertions(+), 179 deletions(-) create mode 100644 src/server/game/ArenaSpectator/ArenaSpectator.cpp diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 3d3ce4249..1fa260750 100644 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -5,7 +5,6 @@ */ #include "AccountMgr.h" -#include "CryptoHash.h" #include "DatabaseEnv.h" #include "ObjectAccessor.h" #include "Player.h" diff --git a/src/server/game/ArenaSpectator/ArenaSpectator.cpp b/src/server/game/ArenaSpectator/ArenaSpectator.cpp new file mode 100644 index 000000000..04fcf7b77 --- /dev/null +++ b/src/server/game/ArenaSpectator/ArenaSpectator.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ + +#include "ArenaSpectator.h" +#include "BattlegroundMgr.h" +#include "Chat.h" +#include "LFGMgr.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "Player.h" +#include "ScriptMgr.h" +#include "World.h" + +namespace ArenaSpectator +{ + bool HandleSpectatorSpectateCommand(ChatHandler* handler, char const* args) + { + Player* player = handler->GetSession()->GetPlayer(); + std::list errors; + if (!*args) + { + handler->SendSysMessage("Missing player name."); + return true; + } + if (player->IsSpectator()) + { + if (player->FindMap() && player->FindMap()->IsBattleArena()) + { + HandleSpectatorWatchCommand(handler, args); + return true; + } + handler->PSendSysMessage("You are already spectacting arena."); + return true; + } + if (player->getClass() == CLASS_DEATH_KNIGHT && player->GetMapId() == 609) + { + handler->PSendSysMessage("Death Knights can't spectate before finishing questline."); + return true; + } + + std::string name = std::string(args); + Player* spectate = ObjectAccessor::FindPlayerByName(name); + if (!spectate) + { + handler->SendSysMessage("Requested player not found."); + return true; + } + if (spectate->IsSpectator()) + { + handler->SendSysMessage("Requested player is a spectator."); + return true; + } + if (!spectate->FindMap() || !spectate->FindMap()->IsBattleArena()) + { + handler->SendSysMessage("Requested player is not in arena."); + return true; + } + BattlegroundMap* bgmap = ((BattlegroundMap*)spectate->FindMap()); + if (!bgmap->GetBG() || bgmap->GetBG()->GetStatus() == STATUS_WAIT_LEAVE) + { + handler->SendSysMessage("This arena battle has finished."); + return true; + } + + if (player->IsBeingTeleported() || !player->IsInWorld()) + errors.push_back("Can't use while being teleported."); + if (!player->FindMap() || player->FindMap()->Instanceable()) + errors.push_back("Can't use while in instance, bg or arena."); + if (player->GetVehicle()) + errors.push_back("Can't be on a vehicle."); + if (player->IsInCombat()) + errors.push_back("Can't be in combat."); + if (player->isUsingLfg()) + errors.push_back("Can't spectate while using LFG system."); + if (player->InBattlegroundQueue()) + errors.push_back("Can't be queued for arena or bg."); + if (player->GetGroup()) + errors.push_back("Can't be in a group."); + if (player->HasUnitState(UNIT_STATE_ISOLATED)) + errors.push_back("Can't be isolated."); + if (player->m_mover != player) + errors.push_back("You must control yourself."); + if (player->IsInFlight()) + errors.push_back("Can't be in flight."); + if (player->IsMounted()) + errors.push_back("Dismount before spectating."); + if (!player->IsAlive()) + errors.push_back("Must be alive."); + if (!player->m_Controlled.empty()) + errors.push_back("Can't be controlling creatures."); + + const Unit::VisibleAuraMap* va = player->GetVisibleAuras(); + for (Unit::VisibleAuraMap::const_iterator itr = va->begin(); itr != va->end(); ++itr) + if (Aura* aura = itr->second->GetBase()) + if (!itr->second->IsPositive() && !aura->IsPermanent() && aura->GetDuration() < HOUR * IN_MILLISECONDS) + { + switch (aura->GetSpellInfo()->Id) + { + case lfg::LFG_SPELL_DUNGEON_DESERTER: + case lfg::LFG_SPELL_DUNGEON_COOLDOWN: + case 26013: // bg deserter + case 57724: // sated + case 57723: // exhaustion + case 25771: // forbearance + case 15007: // resurrection sickness + case 24755: // Tricked or Treated (z eventu) + continue; + } + + errors.push_back("Can't have negative auras."); + break; + } + + if (uint32 inviteInstanceId = player->GetPendingSpectatorInviteInstanceId()) + { + if (Battleground* tbg = sBattlegroundMgr->GetBattleground(inviteInstanceId)) + tbg->RemoveToBeTeleported(player->GetGUID()); + player->SetPendingSpectatorInviteInstanceId(0); + } + + bool bgPreparation = false; + if ((!handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS) || + (handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_WAIT_JOIN && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS)) + { + bgPreparation = true; + handler->SendSysMessage("Arena is not in progress yet. You will be invited as soon as it starts."); + bgmap->GetBG()->AddToBeTeleported(player->GetGUID(), spectate->GetGUID()); + player->SetPendingSpectatorInviteInstanceId(spectate->GetBattlegroundId()); + } + + if (!errors.empty()) + { + handler->PSendSysMessage("To spectate, please fix the following:"); + for (std::list::const_iterator itr = errors.begin(); itr != errors.end(); ++itr) + handler->PSendSysMessage("- %s", (*itr).c_str()); + + return true; + } + + if (bgPreparation) + return true; + + player->SetPendingSpectatorForBG(spectate->GetBattlegroundId()); + player->SetBattlegroundId(spectate->GetBattlegroundId(), spectate->GetBattlegroundTypeId(), PLAYER_MAX_BATTLEGROUND_QUEUES, false, false, TEAM_NEUTRAL); + player->SetEntryPoint(); + float z = spectate->GetMapId() == 618 ? std::max(28.27f, spectate->GetPositionZ() + 0.25f) : spectate->GetPositionZ() + 0.25f; + player->TeleportTo(spectate->GetMapId(), spectate->GetPositionX(), spectate->GetPositionY(), z, spectate->GetOrientation(), TELE_TO_GM_MODE); + return true; + } + + bool HandleSpectatorWatchCommand(ChatHandler* handler, char const* args) + { + if (!*args) + return true; + + Player* player = handler->GetSession()->GetPlayer(); + if (!player->IsSpectator()) + return true; + + if (!player->FindMap() || !player->FindMap()->IsBattleArena()) + return true; + + Battleground* bg = ((BattlegroundMap*)player->FindMap())->GetBG(); + if (!bg || bg->GetStatus() != STATUS_IN_PROGRESS) + return true; + + std::string name = std::string(args); + Player* spectate = ObjectAccessor::FindPlayerByName(name); + if (!spectate || !spectate->IsAlive() || spectate->IsSpectator() || spectate->GetGUID() == player->GetGUID() || !spectate->IsInWorld() || !spectate->FindMap() || spectate->IsBeingTeleported() || spectate->FindMap() != player->FindMap() || !bg->IsPlayerInBattleground(spectate->GetGUID())) + return true; + + if (WorldObject* o = player->GetViewpoint()) + if (Unit* u = o->ToUnit()) + { + u->RemoveAurasByType(SPELL_AURA_BIND_SIGHT, player->GetGUID()); + player->RemoveAurasDueToSpell(SPECTATOR_SPELL_BINDSIGHT, player->GetGUID(), (1 << EFFECT_1)); + + if (u->GetGUID() == spectate->GetGUID()) + return true; + } + + if (player->GetGuidValue(PLAYER_FARSIGHT) || player->m_seer != player) // pussywizard: below this point we must not have a viewpoint! + return true; + + if (player->HaveAtClient(spectate)) + player->CastSpell(spectate, SPECTATOR_SPELL_BINDSIGHT, true); + + return true; + } +} diff --git a/src/server/game/ArenaSpectator/ArenaSpectator.h b/src/server/game/ArenaSpectator/ArenaSpectator.h index 64d3f76c9..433e7af63 100644 --- a/src/server/game/ArenaSpectator/ArenaSpectator.h +++ b/src/server/game/ArenaSpectator/ArenaSpectator.h @@ -1,3 +1,6 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ #ifndef AZEROTHCORE_ARENASPECTATOR_H #define AZEROTHCORE_ARENASPECTATOR_H diff --git a/src/server/scripts/Commands/cs_spectator.cpp b/src/server/scripts/Commands/cs_spectator.cpp index 8b4dd6795..980f421bc 100644 --- a/src/server/scripts/Commands/cs_spectator.cpp +++ b/src/server/scripts/Commands/cs_spectator.cpp @@ -1,11 +1,11 @@ +/* + * Copyright (C) 2016+ AzerothCore , released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3 + */ #include "AccountMgr.h" #include "ArenaSpectator.h" #include "BattlegroundMgr.h" #include "Chat.h" -#include "LFGMgr.h" -#include "ObjectMgr.h" -#include "Opcodes.h" #include "Player.h" #include "ScriptMgr.h" #include "World.h" @@ -73,181 +73,6 @@ public: } }; -bool ArenaSpectator::HandleSpectatorSpectateCommand(ChatHandler* handler, char const* args) -{ - Player* player = handler->GetSession()->GetPlayer(); - std::list errors; - if (!*args) - { - handler->SendSysMessage("Missing player name."); - return true; - } - if (player->IsSpectator()) - { - if (player->FindMap() && player->FindMap()->IsBattleArena()) - { - HandleSpectatorWatchCommand(handler, args); - return true; - } - handler->PSendSysMessage("You are already spectacting arena."); - return true; - } - if (player->getClass() == CLASS_DEATH_KNIGHT && player->GetMapId() == 609) - { - handler->PSendSysMessage("Death Knights can't spectate before finishing questline."); - return true; - } - - std::string name = std::string(args); - Player* spectate = ObjectAccessor::FindPlayerByName(name); - if (!spectate) - { - handler->SendSysMessage("Requested player not found."); - return true; - } - if (spectate->IsSpectator()) - { - handler->SendSysMessage("Requested player is a spectator."); - return true; - } - if (!spectate->FindMap() || !spectate->FindMap()->IsBattleArena()) - { - handler->SendSysMessage("Requested player is not in arena."); - return true; - } - BattlegroundMap* bgmap = ((BattlegroundMap*)spectate->FindMap()); - if (!bgmap->GetBG() || bgmap->GetBG()->GetStatus() == STATUS_WAIT_LEAVE) - { - handler->SendSysMessage("This arena battle has finished."); - return true; - } - - if (player->IsBeingTeleported() || !player->IsInWorld()) - errors.push_back("Can't use while being teleported."); - if (!player->FindMap() || player->FindMap()->Instanceable()) - errors.push_back("Can't use while in instance, bg or arena."); - if (player->GetVehicle()) - errors.push_back("Can't be on a vehicle."); - if (player->IsInCombat()) - errors.push_back("Can't be in combat."); - if (player->isUsingLfg()) - errors.push_back("Can't spectate while using LFG system."); - if (player->InBattlegroundQueue()) - errors.push_back("Can't be queued for arena or bg."); - if (player->GetGroup()) - errors.push_back("Can't be in a group."); - if (player->HasUnitState(UNIT_STATE_ISOLATED)) - errors.push_back("Can't be isolated."); - if (player->m_mover != player) - errors.push_back("You must control yourself."); - if (player->IsInFlight()) - errors.push_back("Can't be in flight."); - if (player->IsMounted()) - errors.push_back("Dismount before spectating."); - if (!player->IsAlive()) - errors.push_back("Must be alive."); - if (!player->m_Controlled.empty()) - errors.push_back("Can't be controlling creatures."); - - const Unit::VisibleAuraMap* va = player->GetVisibleAuras(); - for (Unit::VisibleAuraMap::const_iterator itr = va->begin(); itr != va->end(); ++itr) - if (Aura* aura = itr->second->GetBase()) - if (!itr->second->IsPositive() && !aura->IsPermanent() && aura->GetDuration() < HOUR * IN_MILLISECONDS) - { - switch (aura->GetSpellInfo()->Id) - { - case lfg::LFG_SPELL_DUNGEON_DESERTER: - case lfg::LFG_SPELL_DUNGEON_COOLDOWN: - case 26013: // bg deserter - case 57724: // sated - case 57723: // exhaustion - case 25771: // forbearance - case 15007: // resurrection sickness - case 24755: // Tricked or Treated (z eventu) - continue; - } - - errors.push_back("Can't have negative auras."); - break; - } - - if (uint32 inviteInstanceId = player->GetPendingSpectatorInviteInstanceId()) - { - if (Battleground* tbg = sBattlegroundMgr->GetBattleground(inviteInstanceId)) - tbg->RemoveToBeTeleported(player->GetGUID()); - player->SetPendingSpectatorInviteInstanceId(0); - } - - bool bgPreparation = false; - if ((!handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS) || - (handler->GetSession()->GetSecurity() && bgmap->GetBG()->GetStatus() != STATUS_WAIT_JOIN && bgmap->GetBG()->GetStatus() != STATUS_IN_PROGRESS)) - { - bgPreparation = true; - handler->SendSysMessage("Arena is not in progress yet. You will be invited as soon as it starts."); - bgmap->GetBG()->AddToBeTeleported(player->GetGUID(), spectate->GetGUID()); - player->SetPendingSpectatorInviteInstanceId(spectate->GetBattlegroundId()); - } - - if (!errors.empty()) - { - handler->PSendSysMessage("To spectate, please fix the following:"); - for (std::list::const_iterator itr = errors.begin(); itr != errors.end(); ++itr) - handler->PSendSysMessage("- %s", (*itr).c_str()); - - return true; - } - - if (bgPreparation) - return true; - - player->SetPendingSpectatorForBG(spectate->GetBattlegroundId()); - player->SetBattlegroundId(spectate->GetBattlegroundId(), spectate->GetBattlegroundTypeId(), PLAYER_MAX_BATTLEGROUND_QUEUES, false, false, TEAM_NEUTRAL); - player->SetEntryPoint(); - float z = spectate->GetMapId() == 618 ? std::max(28.27f, spectate->GetPositionZ() + 0.25f) : spectate->GetPositionZ() + 0.25f; - player->TeleportTo(spectate->GetMapId(), spectate->GetPositionX(), spectate->GetPositionY(), z, spectate->GetOrientation(), TELE_TO_GM_MODE); - return true; -} - -bool ArenaSpectator::HandleSpectatorWatchCommand(ChatHandler* handler, char const* args) -{ - if (!*args) - return true; - - Player* player = handler->GetSession()->GetPlayer(); - if (!player->IsSpectator()) - return true; - - if (!player->FindMap() || !player->FindMap()->IsBattleArena()) - return true; - - Battleground* bg = ((BattlegroundMap*)player->FindMap())->GetBG(); - if (!bg || bg->GetStatus() != STATUS_IN_PROGRESS) - return true; - - std::string name = std::string(args); - Player* spectate = ObjectAccessor::FindPlayerByName(name); - if (!spectate || !spectate->IsAlive() || spectate->IsSpectator() || spectate->GetGUID() == player->GetGUID() || !spectate->IsInWorld() || !spectate->FindMap() || spectate->IsBeingTeleported() || spectate->FindMap() != player->FindMap() || !bg->IsPlayerInBattleground(spectate->GetGUID())) - return true; - - if (WorldObject* o = player->GetViewpoint()) - if (Unit* u = o->ToUnit()) - { - u->RemoveAurasByType(SPELL_AURA_BIND_SIGHT, player->GetGUID()); - player->RemoveAurasDueToSpell(SPECTATOR_SPELL_BINDSIGHT, player->GetGUID(), (1 << EFFECT_1)); - - if (u->GetGUID() == spectate->GetGUID()) - return true; - } - - if (player->GetGuidValue(PLAYER_FARSIGHT) || player->m_seer != player) // pussywizard: below this point we must not have a viewpoint! - return true; - - if (player->HaveAtClient(spectate)) - player->CastSpell(spectate, SPECTATOR_SPELL_BINDSIGHT, true); - - return true; -} - void AddSC_spectator_commandscript() { new spectator_commandscript();