diff options
author | Nayd <dnpd.dd@gmail.com> | 2015-01-19 00:06:15 +0000 |
---|---|---|
committer | Nayd <dnpd.dd@gmail.com> | 2015-01-19 00:07:10 +0000 |
commit | 08a98c623742cd2873453797e565f3bdc2d90275 (patch) | |
tree | c6bbcad4d55a4ee05d6ed09a38b016ca9018874a /src | |
parent | 746fa496c98d247995fb2f3ff53a2f33e66b23a0 (diff) |
Line ending fix, sorry.
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Accounts/RBAC.cpp | 530 | ||||
-rw-r--r-- | src/server/game/Handlers/MiscHandler.cpp | 4258 | ||||
-rw-r--r-- | src/server/game/Handlers/QueryHandler.cpp | 18 | ||||
-rw-r--r-- | src/server/game/Server/Packets/LootPackets.cpp | 2 | ||||
-rw-r--r-- | src/server/game/Server/Packets/LootPackets.h | 8 | ||||
-rw-r--r-- | src/server/game/Server/Packets/MiscPackets.cpp | 522 | ||||
-rw-r--r-- | src/server/game/Server/Packets/MiscPackets.h | 732 | ||||
-rw-r--r-- | src/server/game/Server/Packets/QueryPackets.cpp | 50 | ||||
-rw-r--r-- | src/server/game/Server/Packets/QueryPackets.h | 76 | ||||
-rw-r--r-- | src/server/scripts/Commands/cs_rbac.cpp | 766 | ||||
-rw-r--r-- | src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp | 430 | ||||
-rw-r--r-- | src/server/scripts/Spells/spell_dk.cpp | 2 |
12 files changed, 3697 insertions, 3697 deletions
diff --git a/src/server/game/Accounts/RBAC.cpp b/src/server/game/Accounts/RBAC.cpp index 54ef1a34766..74ff060636e 100644 --- a/src/server/game/Accounts/RBAC.cpp +++ b/src/server/game/Accounts/RBAC.cpp @@ -1,265 +1,265 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "RBAC.h"
-#include "AccountMgr.h"
-#include "DatabaseEnv.h"
-#include "Log.h"
-
-namespace rbac
-{
-
-std::string GetDebugPermissionString(RBACPermissionContainer const& perms)
-{
- std::string str = "";
- if (!perms.empty())
- {
- std::ostringstream o;
- RBACPermissionContainer::const_iterator itr = perms.begin();
- o << (*itr);
- for (++itr; itr != perms.end(); ++itr)
- o << ", " << uint32(*itr);
- str = o.str();
- }
-
- return str;
-}
-
-RBACCommandResult RBACData::GrantPermission(uint32 permissionId, int32 realmId /* = 0*/)
-{
- // Check if permission Id exists
- RBACPermission const* perm = sAccountMgr->GetRBACPermission(permissionId);
- if (!perm)
- {
- TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission does not exists",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_ID_DOES_NOT_EXISTS;
- }
-
- // Check if already added in denied list
- if (HasDeniedPermission(permissionId))
- {
- TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission in deny list",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_IN_DENIED_LIST;
- }
-
- // Already added?
- if (HasGrantedPermission(permissionId))
- {
- TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission already granted",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_CANT_ADD_ALREADY_ADDED;
- }
-
- AddGrantedPermission(permissionId);
-
- // Do not save to db when loading data from DB (realmId = 0)
- if (realmId)
- {
- TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated",
- GetId(), GetName().c_str(), permissionId, realmId);
- SavePermission(permissionId, true, realmId);
- CalculateNewPermissions();
- }
- else
- TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok",
- GetId(), GetName().c_str(), permissionId, realmId);
-
- return RBAC_OK;
-}
-
-RBACCommandResult RBACData::DenyPermission(uint32 permissionId, int32 realmId /* = 0*/)
-{
- // Check if permission Id exists
- RBACPermission const* perm = sAccountMgr->GetRBACPermission(permissionId);
- if (!perm)
- {
- TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission does not exists",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_ID_DOES_NOT_EXISTS;
- }
-
- // Check if already added in granted list
- if (HasGrantedPermission(permissionId))
- {
- TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission in grant list",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_IN_GRANTED_LIST;
- }
-
- // Already added?
- if (HasDeniedPermission(permissionId))
- {
- TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission already denied",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_CANT_ADD_ALREADY_ADDED;
- }
-
- AddDeniedPermission(permissionId);
-
- // Do not save to db when loading data from DB (realmId = 0)
- if (realmId)
- {
- TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated",
- GetId(), GetName().c_str(), permissionId, realmId);
- SavePermission(permissionId, false, realmId);
- CalculateNewPermissions();
- }
- else
- TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok",
- GetId(), GetName().c_str(), permissionId, realmId);
-
- return RBAC_OK;
-}
-
-void RBACData::SavePermission(uint32 permission, bool granted, int32 realmId)
-{
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_RBAC_ACCOUNT_PERMISSION);
- stmt->setUInt32(0, GetId());
- stmt->setUInt32(1, permission);
- stmt->setBool(2, granted);
- stmt->setInt32(3, realmId);
- LoginDatabase.Execute(stmt);
-}
-
-RBACCommandResult RBACData::RevokePermission(uint32 permissionId, int32 realmId /* = 0*/)
-{
- // Check if it's present in any list
- if (!HasGrantedPermission(permissionId) && !HasDeniedPermission(permissionId))
- {
- TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Not granted or revoked",
- GetId(), GetName().c_str(), permissionId, realmId);
- return RBAC_CANT_REVOKE_NOT_IN_LIST;
- }
-
- RemoveGrantedPermission(permissionId);
- RemoveDeniedPermission(permissionId);
-
- // Do not save to db when loading data from DB (realmId = 0)
- if (realmId)
- {
- TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated",
- GetId(), GetName().c_str(), permissionId, realmId);
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_RBAC_ACCOUNT_PERMISSION);
- stmt->setUInt32(0, GetId());
- stmt->setUInt32(1, permissionId);
- stmt->setInt32(2, realmId);
- LoginDatabase.Execute(stmt);
-
- CalculateNewPermissions();
- }
- else
- TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok",
- GetId(), GetName().c_str(), permissionId, realmId);
-
- return RBAC_OK;
-}
-
-void RBACData::LoadFromDB()
-{
- ClearData();
-
- TC_LOG_DEBUG("rbac", "RBACData::LoadFromDB [Id: %u Name: %s]: Loading permissions", GetId(), GetName().c_str());
- // Load account permissions (granted and denied) that affect current realm
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_RBAC_ACCOUNT_PERMISSIONS);
- stmt->setUInt32(0, GetId());
- stmt->setInt32(1, GetRealmId());
-
- PreparedQueryResult result = LoginDatabase.Query(stmt);
- if (result)
- {
- do
- {
- Field* fields = result->Fetch();
- if (fields[1].GetBool())
- GrantPermission(fields[0].GetUInt32());
- else
- DenyPermission(fields[0].GetUInt32());
- }
- while (result->NextRow());
- }
-
- // Add default permissions
- RBACPermissionContainer const& permissions = sAccountMgr->GetRBACDefaultPermissions(_secLevel);
- for (RBACPermissionContainer::const_iterator itr = permissions.begin(); itr != permissions.end(); ++itr)
- GrantPermission(*itr);
-
- // Force calculation of permissions
- CalculateNewPermissions();
-}
-
-void RBACData::CalculateNewPermissions()
-{
- TC_LOG_TRACE("rbac", "RBACData::CalculateNewPermissions [Id: %u Name: %s]", GetId(), GetName().c_str());
-
- // Get the list of granted permissions
- _globalPerms = GetGrantedPermissions();
- ExpandPermissions(_globalPerms);
- RBACPermissionContainer revoked = GetDeniedPermissions();
- ExpandPermissions(revoked);
- RemovePermissions(_globalPerms, revoked);
-}
-
-void RBACData::AddPermissions(RBACPermissionContainer const& permsFrom, RBACPermissionContainer& permsTo)
-{
- for (RBACPermissionContainer::const_iterator itr = permsFrom.begin(); itr != permsFrom.end(); ++itr)
- permsTo.insert(*itr);
-}
-
-void RBACData::RemovePermissions(RBACPermissionContainer const& permsFrom, RBACPermissionContainer& permsTo)
-{
- for (RBACPermissionContainer::const_iterator itr = permsFrom.begin(); itr != permsFrom.end(); ++itr)
- permsTo.erase(*itr);
-}
-
-void RBACData::ExpandPermissions(RBACPermissionContainer& permissions)
-{
- RBACPermissionContainer toCheck = permissions;
- permissions.clear();
-
- while (!toCheck.empty())
- {
- // remove the permission from original list
- uint32 permissionId = *toCheck.begin();
- toCheck.erase(toCheck.begin());
-
- RBACPermission const* permission = sAccountMgr->GetRBACPermission(permissionId);
- if (!permission)
- continue;
-
- // insert into the final list (expanded list)
- permissions.insert(permissionId);
-
- // add all linked permissions (that are not already expanded) to the list of permissions to be checked
- RBACPermissionContainer const& linkedPerms = permission->GetLinkedPermissions();
- for (RBACPermissionContainer::const_iterator itr = linkedPerms.begin(); itr != linkedPerms.end(); ++itr)
- if (permissions.find(*itr) == permissions.end())
- toCheck.insert(*itr);
- }
-
- TC_LOG_DEBUG("rbac", "RBACData::ExpandPermissions: Expanded: %s", GetDebugPermissionString(permissions).c_str());
-}
-
-void RBACData::ClearData()
-{
- _grantedPerms.clear();
- _deniedPerms.clear();
- _globalPerms.clear();
-}
-
-}
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "RBAC.h" +#include "AccountMgr.h" +#include "DatabaseEnv.h" +#include "Log.h" + +namespace rbac +{ + +std::string GetDebugPermissionString(RBACPermissionContainer const& perms) +{ + std::string str = ""; + if (!perms.empty()) + { + std::ostringstream o; + RBACPermissionContainer::const_iterator itr = perms.begin(); + o << (*itr); + for (++itr; itr != perms.end(); ++itr) + o << ", " << uint32(*itr); + str = o.str(); + } + + return str; +} + +RBACCommandResult RBACData::GrantPermission(uint32 permissionId, int32 realmId /* = 0*/) +{ + // Check if permission Id exists + RBACPermission const* perm = sAccountMgr->GetRBACPermission(permissionId); + if (!perm) + { + TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission does not exists", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_ID_DOES_NOT_EXISTS; + } + + // Check if already added in denied list + if (HasDeniedPermission(permissionId)) + { + TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission in deny list", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_IN_DENIED_LIST; + } + + // Already added? + if (HasGrantedPermission(permissionId)) + { + TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission already granted", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_CANT_ADD_ALREADY_ADDED; + } + + AddGrantedPermission(permissionId); + + // Do not save to db when loading data from DB (realmId = 0) + if (realmId) + { + TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated", + GetId(), GetName().c_str(), permissionId, realmId); + SavePermission(permissionId, true, realmId); + CalculateNewPermissions(); + } + else + TC_LOG_TRACE("rbac", "RBACData::GrantPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok", + GetId(), GetName().c_str(), permissionId, realmId); + + return RBAC_OK; +} + +RBACCommandResult RBACData::DenyPermission(uint32 permissionId, int32 realmId /* = 0*/) +{ + // Check if permission Id exists + RBACPermission const* perm = sAccountMgr->GetRBACPermission(permissionId); + if (!perm) + { + TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission does not exists", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_ID_DOES_NOT_EXISTS; + } + + // Check if already added in granted list + if (HasGrantedPermission(permissionId)) + { + TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission in grant list", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_IN_GRANTED_LIST; + } + + // Already added? + if (HasDeniedPermission(permissionId)) + { + TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Permission already denied", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_CANT_ADD_ALREADY_ADDED; + } + + AddDeniedPermission(permissionId); + + // Do not save to db when loading data from DB (realmId = 0) + if (realmId) + { + TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated", + GetId(), GetName().c_str(), permissionId, realmId); + SavePermission(permissionId, false, realmId); + CalculateNewPermissions(); + } + else + TC_LOG_TRACE("rbac", "RBACData::DenyPermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok", + GetId(), GetName().c_str(), permissionId, realmId); + + return RBAC_OK; +} + +void RBACData::SavePermission(uint32 permission, bool granted, int32 realmId) +{ + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_RBAC_ACCOUNT_PERMISSION); + stmt->setUInt32(0, GetId()); + stmt->setUInt32(1, permission); + stmt->setBool(2, granted); + stmt->setInt32(3, realmId); + LoginDatabase.Execute(stmt); +} + +RBACCommandResult RBACData::RevokePermission(uint32 permissionId, int32 realmId /* = 0*/) +{ + // Check if it's present in any list + if (!HasGrantedPermission(permissionId) && !HasDeniedPermission(permissionId)) + { + TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Not granted or revoked", + GetId(), GetName().c_str(), permissionId, realmId); + return RBAC_CANT_REVOKE_NOT_IN_LIST; + } + + RemoveGrantedPermission(permissionId); + RemoveDeniedPermission(permissionId); + + // Do not save to db when loading data from DB (realmId = 0) + if (realmId) + { + TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok and DB updated", + GetId(), GetName().c_str(), permissionId, realmId); + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_RBAC_ACCOUNT_PERMISSION); + stmt->setUInt32(0, GetId()); + stmt->setUInt32(1, permissionId); + stmt->setInt32(2, realmId); + LoginDatabase.Execute(stmt); + + CalculateNewPermissions(); + } + else + TC_LOG_TRACE("rbac", "RBACData::RevokePermission [Id: %u Name: %s] (Permission %u, RealmId %d). Ok", + GetId(), GetName().c_str(), permissionId, realmId); + + return RBAC_OK; +} + +void RBACData::LoadFromDB() +{ + ClearData(); + + TC_LOG_DEBUG("rbac", "RBACData::LoadFromDB [Id: %u Name: %s]: Loading permissions", GetId(), GetName().c_str()); + // Load account permissions (granted and denied) that affect current realm + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_RBAC_ACCOUNT_PERMISSIONS); + stmt->setUInt32(0, GetId()); + stmt->setInt32(1, GetRealmId()); + + PreparedQueryResult result = LoginDatabase.Query(stmt); + if (result) + { + do + { + Field* fields = result->Fetch(); + if (fields[1].GetBool()) + GrantPermission(fields[0].GetUInt32()); + else + DenyPermission(fields[0].GetUInt32()); + } + while (result->NextRow()); + } + + // Add default permissions + RBACPermissionContainer const& permissions = sAccountMgr->GetRBACDefaultPermissions(_secLevel); + for (RBACPermissionContainer::const_iterator itr = permissions.begin(); itr != permissions.end(); ++itr) + GrantPermission(*itr); + + // Force calculation of permissions + CalculateNewPermissions(); +} + +void RBACData::CalculateNewPermissions() +{ + TC_LOG_TRACE("rbac", "RBACData::CalculateNewPermissions [Id: %u Name: %s]", GetId(), GetName().c_str()); + + // Get the list of granted permissions + _globalPerms = GetGrantedPermissions(); + ExpandPermissions(_globalPerms); + RBACPermissionContainer revoked = GetDeniedPermissions(); + ExpandPermissions(revoked); + RemovePermissions(_globalPerms, revoked); +} + +void RBACData::AddPermissions(RBACPermissionContainer const& permsFrom, RBACPermissionContainer& permsTo) +{ + for (RBACPermissionContainer::const_iterator itr = permsFrom.begin(); itr != permsFrom.end(); ++itr) + permsTo.insert(*itr); +} + +void RBACData::RemovePermissions(RBACPermissionContainer const& permsFrom, RBACPermissionContainer& permsTo) +{ + for (RBACPermissionContainer::const_iterator itr = permsFrom.begin(); itr != permsFrom.end(); ++itr) + permsTo.erase(*itr); +} + +void RBACData::ExpandPermissions(RBACPermissionContainer& permissions) +{ + RBACPermissionContainer toCheck = permissions; + permissions.clear(); + + while (!toCheck.empty()) + { + // remove the permission from original list + uint32 permissionId = *toCheck.begin(); + toCheck.erase(toCheck.begin()); + + RBACPermission const* permission = sAccountMgr->GetRBACPermission(permissionId); + if (!permission) + continue; + + // insert into the final list (expanded list) + permissions.insert(permissionId); + + // add all linked permissions (that are not already expanded) to the list of permissions to be checked + RBACPermissionContainer const& linkedPerms = permission->GetLinkedPermissions(); + for (RBACPermissionContainer::const_iterator itr = linkedPerms.begin(); itr != linkedPerms.end(); ++itr) + if (permissions.find(*itr) == permissions.end()) + toCheck.insert(*itr); + } + + TC_LOG_DEBUG("rbac", "RBACData::ExpandPermissions: Expanded: %s", GetDebugPermissionString(permissions).c_str()); +} + +void RBACData::ClearData() +{ + _grantedPerms.clear(); + _deniedPerms.clear(); + _globalPerms.clear(); +} + +} diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index b5e7b57e5c7..cc09e878056 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -1,2129 +1,2129 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "Common.h"
-#include "Language.h"
-#include "DatabaseEnv.h"
-#include "WorldPacket.h"
-#include "Opcodes.h"
-#include "Log.h"
-#include "Player.h"
-#include "GossipDef.h"
-#include "World.h"
-#include "ObjectMgr.h"
-#include "GuildMgr.h"
-#include "WorldSession.h"
-#include "BigNumber.h"
-#include "SHA1.h"
-#include "UpdateData.h"
-#include "LootMgr.h"
-#include "Chat.h"
-#include "zlib.h"
-#include "ObjectAccessor.h"
-#include "Object.h"
-#include "Battleground.h"
-#include "OutdoorPvP.h"
-#include "Pet.h"
-#include "SocialMgr.h"
-#include "CellImpl.h"
-#include "AccountMgr.h"
-#include "Vehicle.h"
-#include "CreatureAI.h"
-#include "DBCEnums.h"
-#include "ScriptMgr.h"
-#include "MapManager.h"
-#include "InstanceScript.h"
-#include "GameObjectAI.h"
-#include "Group.h"
-#include "AccountMgr.h"
-#include "Spell.h"
-#include "SpellPackets.h"
-#include "BattlegroundMgr.h"
-#include "Battlefield.h"
-#include "BattlefieldMgr.h"
-#include "DB2Stores.h"
-#include "CharacterPackets.h"
-#include "ClientConfigPackets.h"
-#include "MiscPackets.h"
-#include "AchievementPackets.h"
-
-void WorldSession::HandleRepopRequest(WorldPackets::Misc::RepopRequest& packet)
-{
- TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_REPOP_REQUEST Message");
-
- if (GetPlayer()->IsAlive() || GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
- return;
-
- if (GetPlayer()->HasAuraType(SPELL_AURA_PREVENT_RESURRECTION))
- return; // silently return, client should display the error by itself
-
- // the world update order is sessions, players, creatures
- // the netcode runs in parallel with all of these
- // creatures can kill players
- // so if the server is lagging enough the player can
- // release spirit after he's killed but before he is updated
- if (GetPlayer()->getDeathState() == JUST_DIED)
- {
- TC_LOG_DEBUG("network", "HandleRepopRequestOpcode: got request after player %s(%s) was killed and before he was updated",
- GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().ToString().c_str());
- GetPlayer()->KillPlayer();
- }
-
- //this is spirit release confirm?
- GetPlayer()->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true);
- GetPlayer()->BuildPlayerRepop();
- GetPlayer()->RepopAtGraveyard();
-}
-
-void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_GOSSIP_SELECT_OPTION");
-
- uint32 gossipListId;
- uint32 menuId;
- ObjectGuid guid;
- std::string code = "";
-
- recvData >> guid >> menuId >> gossipListId;
-
- if (!_player->PlayerTalkClass->GetGossipMenu().GetItem(gossipListId))
- {
- recvData.rfinish();
- return;
- }
-
- if (_player->PlayerTalkClass->IsGossipOptionCoded(gossipListId))
- recvData >> code;
-
- // Prevent cheating on C++ scripted menus
- if (_player->PlayerTalkClass->GetGossipMenu().GetSenderGUID() != guid)
- return;
-
- Creature* unit = NULL;
- GameObject* go = NULL;
- if (guid.IsCreatureOrVehicle())
- {
- unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE);
- if (!unit)
- {
- TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - %s not found or you can't interact with him.", guid.ToString().c_str());
- return;
- }
- }
- else if (guid.IsGameObject())
- {
- go = _player->GetMap()->GetGameObject(guid);
- if (!go)
- {
- TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - %s not found.", guid.ToString().c_str());
- return;
- }
- }
- else
- {
- TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - unsupported %s.", guid.ToString().c_str());
- return;
- }
-
- // remove fake death
- if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
- GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
-
- if ((unit && unit->GetCreatureTemplate()->ScriptID != unit->LastUsedScriptID) || (go && go->GetGOInfo()->ScriptId != go->LastUsedScriptID))
- {
- TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - Script reloaded while in use, ignoring and set new scipt id");
- if (unit)
- unit->LastUsedScriptID = unit->GetCreatureTemplate()->ScriptID;
- if (go)
- go->LastUsedScriptID = go->GetGOInfo()->ScriptId;
- _player->PlayerTalkClass->SendCloseGossip();
- return;
- }
- if (!code.empty())
- {
- if (unit)
- {
- unit->AI()->sGossipSelectCode(_player, menuId, gossipListId, code.c_str());
- if (!sScriptMgr->OnGossipSelectCode(_player, unit, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str()))
- _player->OnGossipSelect(unit, gossipListId, menuId);
- }
- else
- {
- go->AI()->GossipSelectCode(_player, menuId, gossipListId, code.c_str());
- if (!sScriptMgr->OnGossipSelectCode(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str()))
- _player->OnGossipSelect(go, gossipListId, menuId);
- }
- }
- else
- {
- if (unit)
- {
- unit->AI()->sGossipSelect(_player, menuId, gossipListId);
- if (!sScriptMgr->OnGossipSelect(_player, unit, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId)))
- _player->OnGossipSelect(unit, gossipListId, menuId);
- }
- else
- {
- go->AI()->GossipSelect(_player, menuId, gossipListId);
- if (!sScriptMgr->OnGossipSelect(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId)))
- _player->OnGossipSelect(go, gossipListId, menuId);
- }
- }
-}
-
-void WorldSession::HandleWhoOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_WHO Message");
-
- uint32 matchcount = 0;
-
- uint32 level_min, level_max, racemask, classmask, zones_count, str_count;
- uint32 zoneids[10]; // 10 is client limit
- std::string player_name, guild_name;
-
- recvData >> level_min; // maximal player level, default 0
- recvData >> level_max; // minimal player level, default 100 (MAX_LEVEL)
- recvData >> player_name; // player name, case sensitive...
-
- recvData >> guild_name; // guild name, case sensitive...
-
- recvData >> racemask; // race mask
- recvData >> classmask; // class mask
- recvData >> zones_count; // zones count, client limit = 10 (2.0.10)
-
- if (zones_count > 10)
- return; // can't be received from real client or broken packet
-
- for (uint32 i = 0; i < zones_count; ++i)
- {
- uint32 temp;
- recvData >> temp; // zone id, 0 if zone is unknown...
- zoneids[i] = temp;
- TC_LOG_DEBUG("network", "Zone %u: %u", i, zoneids[i]);
- }
-
- recvData >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10)
-
- if (str_count > 4)
- return; // can't be received from real client or broken packet
-
- TC_LOG_DEBUG("network", "Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count);
-
- std::wstring str[4]; // 4 is client limit
- for (uint32 i = 0; i < str_count; ++i)
- {
- std::string temp;
- recvData >> temp; // user entered string, it used as universal search pattern(guild+player name)?
-
- if (!Utf8toWStr(temp, str[i]))
- continue;
-
- wstrToLower(str[i]);
-
- TC_LOG_DEBUG("network", "String %u: %s", i, temp.c_str());
- }
-
- std::wstring wplayer_name;
- std::wstring wguild_name;
- if (!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name)))
- return;
- wstrToLower(wplayer_name);
- wstrToLower(wguild_name);
-
- // client send in case not set max level value 100 but Trinity supports 255 max level,
- // update it to show GMs with characters after 100 level
- if (level_max >= MAX_LEVEL)
- level_max = STRONG_MAX_LEVEL;
-
- uint32 team = _player->GetTeam();
-
- uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST);
- uint32 displaycount = 0;
-
- WorldPacket data(SMSG_WHO, 50); // guess size
- data << uint32(matchcount); // placeholder, count of players matching criteria
- data << uint32(displaycount); // placeholder, count of players displayed
-
- boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
-
- HashMapHolder<Player>::MapType const& m = ObjectAccessor::GetPlayers();
- for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
- {
- Player* target = itr->second;
- // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
- if (target->GetTeam() != team && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_WHO_LIST))
- continue;
-
- // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
- if (!HasPermission(rbac::RBAC_PERM_WHO_SEE_ALL_SEC_LEVELS) && target->GetSession()->GetSecurity() > AccountTypes(gmLevelInWhoList))
- continue;
-
- // do not process players which are not in world
- if (!target->IsInWorld())
- continue;
-
- // check if target is globally visible for player
- if (!target->IsVisibleGloballyFor(_player))
- continue;
-
- // check if target's level is in level range
- uint8 lvl = target->getLevel();
- if (lvl < level_min || lvl > level_max)
- continue;
-
- // check if class matches classmask
- uint8 class_ = target->getClass();
- if (!(classmask & (1 << class_)))
- continue;
-
- // check if race matches racemask
- uint32 race = target->getRace();
- if (!(racemask & (1 << race)))
- continue;
-
- uint32 pzoneid = target->GetZoneId();
- uint8 gender = target->getGender();
-
- bool z_show = true;
- for (uint32 i = 0; i < zones_count; ++i)
- {
- if (zoneids[i] == pzoneid)
- {
- z_show = true;
- break;
- }
-
- z_show = false;
- }
- if (!z_show)
- continue;
-
- std::string pname = target->GetName();
- std::wstring wpname;
- if (!Utf8toWStr(pname, wpname))
- continue;
- wstrToLower(wpname);
-
- if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
- continue;
-
- std::string gname = sGuildMgr->GetGuildNameById(target->GetGuildId());
- std::wstring wgname;
- if (!Utf8toWStr(gname, wgname))
- continue;
- wstrToLower(wgname);
-
- if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos))
- continue;
-
- std::string aname;
- if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid))
- aname = areaEntry->ZoneName;
-
- bool s_show = true;
- for (uint32 i = 0; i < str_count; ++i)
- {
- if (!str[i].empty())
- {
- if (wgname.find(str[i]) != std::wstring::npos ||
- wpname.find(str[i]) != std::wstring::npos ||
- Utf8FitTo(aname, str[i]))
- {
- s_show = true;
- break;
- }
- s_show = false;
- }
- }
- if (!s_show)
- continue;
-
- // 49 is maximum player count sent to client - can be overridden
- // through config, but is unstable
- if ((matchcount++) >= sWorld->getIntConfig(CONFIG_MAX_WHO))
- continue;
-
- data << pname; // player name
- data << gname; // guild name
- data << uint32(lvl); // player level
- data << uint32(class_); // player class
- data << uint32(race); // player race
- data << uint8(gender); // player gender
- data << uint32(pzoneid); // player zone id
-
- ++displaycount;
- }
-
- data.put(0, displaycount); // insert right count, count displayed
- data.put(4, matchcount); // insert right count, count of matches
-
- SendPacket(&data);
- TC_LOG_DEBUG("network", "WORLD: Send SMSG_WHO Message");
-}
-
-void WorldSession::HandleLogoutRequestOpcode(WorldPackets::Character::LogoutRequest& /*logoutRequest*/)
-{
- TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity());
-
- ObjectGuid lguid = GetPlayer()->GetLootGUID();
- if (!lguid.IsEmpty())
- DoLootRelease(lguid);
-
- bool instantLogout = (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) && !GetPlayer()->IsInCombat()) ||
- GetPlayer()->IsInFlight() || HasPermission(rbac::RBAC_PERM_INSTANT_LOGOUT);
-
- /// TODO: Possibly add RBAC permission to log out in combat
- bool canLogoutInCombat = GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
-
- uint32 reason = 0;
- if (GetPlayer()->IsInCombat() && !canLogoutInCombat)
- reason = 1;
- else if (GetPlayer()->IsFalling())
- reason = 3; // is jumping or falling
- else if (GetPlayer()->duel || GetPlayer()->HasAura(9454)) // is dueling or frozen by GM via freeze command
- reason = 2; // FIXME - Need the correct value
-
- WorldPackets::Character::LogoutResponse logoutResponse;
- logoutResponse.LogoutResult = reason;
- logoutResponse.Instant = instantLogout;
- SendPacket(logoutResponse.Write());
-
- if (reason)
- {
- SetLogoutStartTime(0);
- return;
- }
-
- // instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in worldserver.conf
- if (instantLogout)
- {
- LogoutPlayer(true);
- return;
- }
-
- // not set flags if player can't free move to prevent lost state at logout cancel
- if (GetPlayer()->CanFreeMove())
- {
- if (GetPlayer()->getStandState() == UNIT_STAND_STATE_STAND)
- GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT);
- GetPlayer()->SetRooted(true);
- GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
- }
-
- SetLogoutStartTime(time(NULL));
-}
-
-void WorldSession::HandleLogoutCancelOpcode(WorldPackets::Character::LogoutCancel& /*logoutCancel*/)
-{
- TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_LOGOUT_CANCEL Message");
-
- // Player have already logged out serverside, too late to cancel
- if (!GetPlayer())
- return;
-
- SetLogoutStartTime(0);
-
- SendPacket(WorldPackets::Character::LogoutCancelAck().Write());
-
- // not remove flags if can't free move - its not set in Logout request code.
- if (GetPlayer()->CanFreeMove())
- {
- //!we can move again
- GetPlayer()->SetRooted(false);
-
- //! Stand Up
- GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND);
-
- //! DISABLE_ROTATE
- GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
- }
-
- TC_LOG_DEBUG("network", "WORLD: Sent SMSG_LOGOUT_CANCEL_ACK Message");
-}
-
-void WorldSession::HandleTogglePvP(WorldPacket& recvData)
-{
- // this opcode can be used in two ways: Either set explicit new status or toggle old status
- if (recvData.size() == 1)
- {
- bool newPvPStatus;
- recvData >> newPvPStatus;
- GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus);
- GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus);
- }
- else
- {
- GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP);
- GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER);
- }
-
- if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP))
- {
- if (!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.EndTimer)
- GetPlayer()->UpdatePvP(true, true);
- }
- else
- {
- if (!GetPlayer()->pvpInfo.IsHostile && GetPlayer()->IsPvP())
- GetPlayer()->pvpInfo.EndTimer = time(NULL); // start toggle-off
- }
-
- //if (OutdoorPvP* pvp = _player->GetOutdoorPvP())
- // pvp->HandlePlayerActivityChanged(_player);
-}
-
-void WorldSession::HandleZoneUpdateOpcode(WorldPacket& recvData)
-{
- uint32 newZone;
- recvData >> newZone;
-
- TC_LOG_DEBUG("network", "WORLD: Recvd ZONE_UPDATE: %u", newZone);
-
- // use server side data, but only after update the player position. See Player::UpdatePosition().
- GetPlayer()->SetNeedsZoneUpdate(true);
-
- //GetPlayer()->SendInitWorldStates(true, newZone);
-}
-
-void WorldSession::HandlePortGraveyard(WorldPackets::Misc::PortGraveyard& /*packet*/)
-{
- if (GetPlayer()->IsAlive() || !GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
- return;
- GetPlayer()->RepopAtGraveyard();
-}
-
-void WorldSession::HandleRequestCemeteryList(WorldPackets::Misc::RequestCemeteryList& /*packet*/)
-{
- uint32 zoneId = _player->GetZoneId();
- uint32 team = _player->GetTeam();
-
- std::vector<uint32> graveyardIds;
- auto range = sObjectMgr->GraveYardStore.equal_range(zoneId);
-
- for (auto it = range.first; it != range.second && graveyardIds.size() < 16; ++it) // client max
- {
- if (it->second.team == 0 || it->second.team == team)
- graveyardIds.push_back(it->first);
- }
-
- if (graveyardIds.empty())
- {
- TC_LOG_DEBUG("network", "No graveyards found for zone %u for %s (team %u) in CMSG_REQUEST_CEMETERY_LIST",
- zoneId, _player->GetGUID().ToString().c_str(), team);
- return;
- }
-
- WorldPackets::Misc::RequestCemeteryListResponse packet;
- packet.IsGossipTriggered = false;
- packet.CemeteryID.reserve(graveyardIds.size());
-
- for (uint32 id : graveyardIds)
- packet.CemeteryID.push_back(id);
-
- SendPacket(packet.Write());
-}
-
-void WorldSession::HandleSetSelectionOpcode(WorldPackets::Misc::SetSelection& packet)
-{
- _player->SetSelection(packet.Selection);
-}
-
-void WorldSession::HandleStandStateChangeOpcode(WorldPacket& recvData)
-{
- // TC_LOG_DEBUG("network", "WORLD: Received CMSG_STANDSTATECHANGE"); -- too many spam in log at lags/debug stop
- uint32 animstate;
- recvData >> animstate;
-
- _player->SetStandState(animstate);
-}
-
-void WorldSession::HandleContactListOpcode(WorldPacket& recvData)
-{
- recvData.read_skip<uint32>(); // always 1
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_CONTACT_LIST");
- _player->GetSocial()->SendSocialList(_player);
-}
-
-void WorldSession::HandleAddFriendOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_ADD_FRIEND");
-
- std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
- std::string friendNote;
-
- recvData >> friendName;
-
- recvData >> friendNote;
-
- if (!normalizePlayerName(friendName))
- return;
-
- TC_LOG_DEBUG("network", "WORLD: %s asked to add friend : '%s'",
- GetPlayer()->GetName().c_str(), friendName.c_str());
-
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME);
-
- stmt->setString(0, friendName);
-
- _addFriendCallback.SetParam(friendNote);
- _addFriendCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt));
-}
-
-void WorldSession::HandleAddFriendOpcodeCallBack(PreparedQueryResult result, std::string const& friendNote)
-{
- if (!GetPlayer())
- return;
-
- ObjectGuid friendGuid;
- uint32 friendAccountId;
- uint32 team;
- FriendsResult friendResult;
-
- friendResult = FRIEND_NOT_FOUND;
-
- if (result)
- {
- Field* fields = result->Fetch();
-
- friendGuid = ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt64());
- team = Player::TeamForRace(fields[1].GetUInt8());
- friendAccountId = fields[2].GetUInt32();
-
- if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmHandle.Index)))
- {
- if (!friendGuid.IsEmpty())
- {
- if (friendGuid == GetPlayer()->GetGUID())
- friendResult = FRIEND_SELF;
- else if (GetPlayer()->GetTeam() != team && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_ADD_FRIEND))
- friendResult = FRIEND_ENEMY;
- else if (GetPlayer()->GetSocial()->HasFriend(friendGuid))
- friendResult = FRIEND_ALREADY;
- else
- {
- Player* pFriend = ObjectAccessor::FindPlayer(friendGuid);
- if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer()))
- friendResult = FRIEND_ADDED_ONLINE;
- else
- friendResult = FRIEND_ADDED_OFFLINE;
- if (!GetPlayer()->GetSocial()->AddToSocialList(friendGuid, false))
- {
- friendResult = FRIEND_LIST_FULL;
- TC_LOG_DEBUG("network", "WORLD: %s's friend list is full.", GetPlayer()->GetName().c_str());
- }
- }
- GetPlayer()->GetSocial()->SetFriendNote(friendGuid, friendNote);
- }
- }
- }
-
- sSocialMgr->SendFriendStatus(GetPlayer(), friendResult, friendGuid, false);
-
- TC_LOG_DEBUG("network", "WORLD: Sent (SMSG_FRIEND_STATUS)");
-}
-
-void WorldSession::HandleDelFriendOpcode(WorldPacket& recvData)
-{
- ObjectGuid FriendGUID;
-
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_DEL_FRIEND");
-
- recvData >> FriendGUID;
-
- _player->GetSocial()->RemoveFromSocialList(FriendGUID, false);
-
- sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_REMOVED, FriendGUID, false);
-
- TC_LOG_DEBUG("network", "WORLD: Sent motd (SMSG_FRIEND_STATUS)");
-}
-
-void WorldSession::HandleAddIgnoreOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_ADD_IGNORE");
-
- std::string ignoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN);
-
- recvData >> ignoreName;
-
- if (!normalizePlayerName(ignoreName))
- return;
-
- TC_LOG_DEBUG("network", "WORLD: %s asked to Ignore: '%s'",
- GetPlayer()->GetName().c_str(), ignoreName.c_str());
-
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME);
-
- stmt->setString(0, ignoreName);
-
- _addIgnoreCallback = CharacterDatabase.AsyncQuery(stmt);
-}
-
-void WorldSession::HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result)
-{
- if (!GetPlayer())
- return;
-
- ObjectGuid IgnoreGuid;
- FriendsResult ignoreResult;
-
- ignoreResult = FRIEND_IGNORE_NOT_FOUND;
-
- if (result)
- {
- IgnoreGuid = ObjectGuid::Create<HighGuid::Player>((*result)[0].GetUInt64());
-
- if (!IgnoreGuid.IsEmpty())
- {
- if (IgnoreGuid == GetPlayer()->GetGUID()) //not add yourself
- ignoreResult = FRIEND_IGNORE_SELF;
- else if (GetPlayer()->GetSocial()->HasIgnore(IgnoreGuid))
- ignoreResult = FRIEND_IGNORE_ALREADY;
- else
- {
- ignoreResult = FRIEND_IGNORE_ADDED;
-
- // ignore list full
- if (!GetPlayer()->GetSocial()->AddToSocialList(IgnoreGuid, true))
- ignoreResult = FRIEND_IGNORE_FULL;
- }
- }
- }
-
- sSocialMgr->SendFriendStatus(GetPlayer(), ignoreResult, IgnoreGuid, false);
-
- TC_LOG_DEBUG("network", "WORLD: Sent (SMSG_FRIEND_STATUS)");
-}
-
-void WorldSession::HandleDelIgnoreOpcode(WorldPacket& recvData)
-{
- ObjectGuid IgnoreGUID;
-
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_DEL_IGNORE");
-
- recvData >> IgnoreGUID;
-
- _player->GetSocial()->RemoveFromSocialList(IgnoreGUID, true);
-
- sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, IgnoreGUID, false);
-
- TC_LOG_DEBUG("network", "WORLD: Sent motd (SMSG_FRIEND_STATUS)");
-}
-
-void WorldSession::HandleSetContactNotesOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "CMSG_SET_CONTACT_NOTES");
- ObjectGuid guid;
- std::string note;
- recvData >> guid >> note;
- _player->GetSocial()->SetFriendNote(guid, note);
-}
-
-void WorldSession::HandleBugReportOpcode(WorldPacket& recvData)
-{
- uint32 suggestion, contentlen, typelen;
- std::string content, type;
-
- recvData >> suggestion >> contentlen;
- content = recvData.ReadString(contentlen);
-
- recvData >> typelen;
- type = recvData.ReadString(typelen);
-
- if (suggestion == 0)
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUG_REPORT [Bug Report]");
- else
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUG_REPORT [Suggestion]");
-
- TC_LOG_DEBUG("network", "%s", type.c_str());
- TC_LOG_DEBUG("network", "%s", content.c_str());
-
- PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_BUG_REPORT);
-
- stmt->setString(0, type);
- stmt->setString(1, content);
-
- CharacterDatabase.Execute(stmt);
-}
-
-void WorldSession::HandleReclaimCorpse(WorldPackets::Misc::ReclaimCorpse& packet)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_RECLAIM_CORPSE");
-
- if (_player->IsAlive())
- return;
-
- // do not allow corpse reclaim in arena
- if (_player->InArena())
- return;
-
- // body not released yet
- if (!_player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST))
- return;
-
- Corpse* corpse = _player->GetCorpse();
-
- if (!corpse)
- return;
-
- // prevent resurrect before 30-sec delay after body release not finished
- if (time_t(corpse->GetGhostTime() + _player->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(time(NULL)))
- return;
-
- if (!corpse->IsWithinDistInMap(_player, CORPSE_RECLAIM_RADIUS, true))
- return;
-
- // resurrect
- _player->ResurrectPlayer(_player->InBattleground() ? 1.0f : 0.5f);
-
- // spawn bones
- _player->SpawnCorpseBones();
-}
-
-void WorldSession::HandleResurrectResponse(WorldPackets::Misc::ResurrectResponse& packet)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_RESURRECT_RESPONSE");
-
- if (GetPlayer()->IsAlive())
- return;
-
- if (packet.Response == 0)
- {
- GetPlayer()->ClearResurrectRequestData(); // reject
- return;
- }
-
- if (!GetPlayer()->IsResurrectRequestedBy(packet.Resurrecter))
- return;
-
- GetPlayer()->ResurrectUsingRequestData();
-}
-
-void WorldSession::SendAreaTriggerMessage(const char* Text, ...)
-{
- va_list ap;
- char szStr [1024];
- szStr[0] = '\0';
-
- va_start(ap, Text);
- vsnprintf(szStr, 1024, Text, ap);
- va_end(ap);
-
- uint32 length = strlen(szStr)+1;
- WorldPacket data(SMSG_AREA_TRIGGER_MESSAGE, 4+length);
- data << length;
- data << szStr;
- SendPacket(&data);
-}
-
-void WorldSession::HandleAreaTriggerOpcode(WorldPackets::Misc::AreaTrigger& packet)
-{
- TC_LOG_DEBUG("network", "CMSG_AREATRIGGER. Trigger ID: %u", packet.AreaTriggerID);
-
- Player* player = GetPlayer();
- if (player->IsInFlight())
- {
- TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) in flight, ignore Area Trigger ID:%u",
- player->GetName().c_str(), player->GetGUID().ToString().c_str(), packet.AreaTriggerID);
- return;
- }
-
- AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(packet.AreaTriggerID);
- if (!atEntry)
- {
- TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) send unknown (by DBC) Area Trigger ID:%u",
- player->GetName().c_str(), player->GetGUID().ToString().c_str(), packet.AreaTriggerID);
- return;
- }
-
- if (player->GetMapId() != atEntry->MapID)
- {
- TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (trigger map: %u player map: %u), ignore Area Trigger ID: %u",
- player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->MapID, player->GetMapId(), packet.AreaTriggerID);
- return;
- }
-
- // delta is safe radius
- const float delta = 5.0f;
-
- if (atEntry->Radius > 0)
- {
- // if we have radius check it
- float dist = player->GetDistance(atEntry->Pos.X, atEntry->Pos.Y, atEntry->Pos.Z);
- if (dist > atEntry->Radius + delta)
- {
- TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (radius: %f distance: %f), ignore Area Trigger ID: %u",
- player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->Radius, dist, packet.AreaTriggerID);
- return;
- }
- }
- else
- {
- // we have only extent
-
- // rotate the players position instead of rotating the whole cube, that way we can make a simplified
- // is-in-cube check and we have to calculate only one point instead of 4
-
- // 2PI = 360°, keep in mind that ingame orientation is counter-clockwise
- double rotation = 2 * M_PI - atEntry->BoxYaw;
- double sinVal = std::sin(rotation);
- double cosVal = std::cos(rotation);
-
- float playerBoxDistX = player->GetPositionX() - atEntry->Pos.X;
- float playerBoxDistY = player->GetPositionY() - atEntry->Pos.Y;
-
- float rotPlayerX = float(atEntry->Pos.X + playerBoxDistX * cosVal - playerBoxDistY*sinVal);
- float rotPlayerY = float(atEntry->Pos.Y + playerBoxDistY * cosVal + playerBoxDistX*sinVal);
-
- // box edges are parallel to coordiante axis, so we can treat every dimension independently :D
- float dz = player->GetPositionZ() - atEntry->Pos.Z;
- float dx = rotPlayerX - atEntry->Pos.X;
- float dy = rotPlayerY - atEntry->Pos.Y;
- if ((std::fabs(dx) > atEntry->BoxLength / 2 + delta) ||
- (std::fabs(dy) > atEntry->BoxWidth / 2 + delta) ||
- (std::fabs(dz) > atEntry->BoxHeight / 2 + delta))
- {
- TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotatedPlayerX: %f rotatedPlayerY: %f dZ:%f), ignore Area Trigger ID: %u",
- player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->BoxLength / 2, atEntry->BoxWidth / 2, atEntry->BoxHeight / 2, rotPlayerX, rotPlayerY, dz, packet.AreaTriggerID);
- return;
- }
- }
-
- if (player->isDebugAreaTriggers)
- ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_REACHED, packet.AreaTriggerID);
-
- if (sScriptMgr->OnAreaTrigger(player, atEntry))
- return;
-
- if (player->IsAlive())
- {
- if (uint32 questId = sObjectMgr->GetQuestForAreaTrigger(packet.AreaTriggerID))
- {
- Quest const* qInfo = sObjectMgr->GetQuestTemplate(questId);
- if (qInfo && player->GetQuestStatus(questId) == QUEST_STATUS_INCOMPLETE)
- {
- for (uint8 j = 0; j < qInfo->Objectives.size(); ++j)
- {
- if (qInfo->Objectives[j].Type == QUEST_OBJECTIVE_AREATRIGGER)
- {
- player->SetQuestObjectiveData(qInfo, j, int32(true));
- break;
- }
- }
-
- if (player->CanCompleteQuest(questId))
- player->CompleteQuest(questId);
- }
- }
- }
-
- if (sObjectMgr->IsTavernAreaTrigger(packet.AreaTriggerID))
- {
- // set resting flag we are in the inn
- player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
- player->InnEnter(time(NULL), atEntry->MapID, atEntry->Pos.X, atEntry->Pos.Y, atEntry->Pos.Z);
- player->SetRestType(REST_TYPE_IN_TAVERN);
-
- if (sWorld->IsFFAPvPRealm())
- player->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP);
-
- return;
- }
-
- if (Battleground* bg = player->GetBattleground())
- if (bg->GetStatus() == STATUS_IN_PROGRESS)
- bg->HandleAreaTrigger(player, packet.AreaTriggerID);
-
- if (OutdoorPvP* pvp = player->GetOutdoorPvP())
- if (pvp->HandleAreaTrigger(_player, packet.AreaTriggerID))
- return;
-
- AreaTriggerStruct const* at = sObjectMgr->GetAreaTrigger(packet.AreaTriggerID);
- if (!at)
- return;
-
- bool teleported = false;
- if (player->GetMapId() != at->target_mapId)
- {
- if (!sMapMgr->CanPlayerEnter(at->target_mapId, player, false))
- return;
-
- if (Group* group = player->GetGroup())
- if (group->isLFGGroup() && player->GetMap()->IsDungeon())
- teleported = player->TeleportToBGEntryPoint();
- }
-
- if (!teleported)
- player->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT);
-}
-
-void WorldSession::HandleUpdateAccountData(WorldPackets::ClientConfig::UserClientUpdateAccountData& packet)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_UPDATE_ACCOUNT_DATA: type %u, time %u, decompressedSize %u",
- packet.DataType, packet.Time, packet.Size);
-
- if (packet.DataType > NUM_ACCOUNT_DATA_TYPES)
- return;
-
- if (packet.Size == 0) // erase
- {
- SetAccountData(AccountDataType(packet.DataType), 0, "");
- return;
- }
-
- if (packet.Size > 0xFFFF)
- {
- TC_LOG_ERROR("network", "UAD: Account data packet too big, size %u", packet.Size);
- return;
- }
-
- ByteBuffer dest;
- dest.resize(packet.Size);
-
- uLongf realSize = packet.Size;
- if (uncompress(dest.contents(), &realSize, packet.CompressedData.contents(), packet.CompressedData.size()) != Z_OK)
- {
- TC_LOG_ERROR("network", "UAD: Failed to decompress account data");
- return;
- }
-
- std::string adata;
- dest >> adata;
-
- SetAccountData(AccountDataType(packet.DataType), packet.Time, adata);
-}
-
-void WorldSession::HandleRequestAccountData(WorldPackets::ClientConfig::RequestAccountData& request)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_REQUEST_ACCOUNT_DATA: type %u", request.DataType);
-
- if (request.DataType >= NUM_ACCOUNT_DATA_TYPES)
- return;
-
- AccountData const* adata = GetAccountData(AccountDataType(request.DataType));
-
- WorldPackets::ClientConfig::UpdateAccountData data;
- data.Player = _player ? _player->GetGUID() : ObjectGuid::Empty;
- data.Time = adata->Time;
- data.Size = adata->Data.size();
- data.DataType = request.DataType;
-
- uLongf destSize = compressBound(data.Size);
-
- data.CompressedData.resize(destSize);
-
- if (data.Size && compress(data.CompressedData.contents(), &destSize, (uint8 const*)adata->Data.c_str(), data.Size) != Z_OK)
- {
- TC_LOG_ERROR("network", "RAD: Failed to compress account data");
- return;
- }
-
- data.CompressedData.resize(destSize);
-
- SendPacket(data.Write());
-}
-
-int32 WorldSession::HandleEnableNagleAlgorithm()
-{
- // Instructs the server we wish to receive few amounts of large packets (SMSG_MULTIPLE_PACKETS?)
- // instead of large amount of small packets
- return 0;
-}
-
-void WorldSession::HandleSetActionButtonOpcode(WorldPackets::Spells::SetActionButton& packet)
-{
- uint32 action = ACTION_BUTTON_ACTION(packet.Action);
- uint32 type = ACTION_BUTTON_TYPE(packet.Action);
-
- TC_LOG_DEBUG("network", "CMSG_SET_ACTION_BUTTON Button: %u Action: %u Type: %u", packet.Index, action, type);
-
- if (!packet.Action)
- GetPlayer()->RemoveActionButton(packet.Index);
- else
- GetPlayer()->AddActionButton(packet.Index, action, type);
-}
-
-void WorldSession::HandleCompleteCinematic(WorldPacket& /*recvData*/)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_COMPLETE_CINEMATIC");
-}
-
-void WorldSession::HandleNextCinematicCamera(WorldPacket& /*recvData*/)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_NEXT_CINEMATIC_CAMERA");
-}
-
-void WorldSession::HandleMoveTimeSkippedOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_MOVE_TIME_SKIPPED");
-
- ObjectGuid guid;
- uint32 time;
- recvData >> time;
-
- guid[5] = recvData.ReadBit();
- guid[1] = recvData.ReadBit();
- guid[3] = recvData.ReadBit();
- guid[7] = recvData.ReadBit();
- guid[6] = recvData.ReadBit();
- guid[0] = recvData.ReadBit();
- guid[4] = recvData.ReadBit();
- guid[2] = recvData.ReadBit();
-
- recvData.ReadByteSeq(guid[7]);
- recvData.ReadByteSeq(guid[1]);
- recvData.ReadByteSeq(guid[2]);
- recvData.ReadByteSeq(guid[4]);
- recvData.ReadByteSeq(guid[3]);
- recvData.ReadByteSeq(guid[6]);
- recvData.ReadByteSeq(guid[0]);
- recvData.ReadByteSeq(guid[5]);
-
- //TODO!
-
- /*
- uint64 guid;
- uint32 time_skipped;
- recvData >> guid;
- recvData >> time_skipped;
- TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_TIME_SKIPPED");
-
- //// @todo
- must be need use in Trinity
- We substract server Lags to move time (AntiLags)
- for exmaple
- GetPlayer()->ModifyLastMoveTime(-int32(time_skipped));
- */
-}
-
-void WorldSession::HandleFeatherFallAck(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FEATHER_FALL_ACK");
-
- // no used
- recvData.rfinish(); // prevent warnings spam
-}
-
-void WorldSession::HandleMoveUnRootAck(WorldPacket& recvData)
-{
- // no used
- recvData.rfinish(); // prevent warnings spam
-/*
- uint64 guid;
- recvData >> guid;
-
- // now can skip not our packet
- if (_player->GetGUID() != guid)
- {
- recvData.rfinish(); // prevent warnings spam
- return;
- }
-
- TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FORCE_UNROOT_ACK");
-
- recvData.read_skip<uint32>(); // unk
-
- MovementInfo movementInfo;
- movementInfo.guid = guid;
- ReadMovementInfo(recvData, &movementInfo);
- recvData.read_skip<float>(); // unk2
-*/
-}
-
-void WorldSession::HandleMoveRootAck(WorldPacket& recvData)
-{
- // no used
- recvData.rfinish(); // prevent warnings spam
-/*
- uint64 guid;
- recvData >> guid;
-
- // now can skip not our packet
- if (_player->GetGUID() != guid)
- {
- recvData.rfinish(); // prevent warnings spam
- return;
- }
-
- TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FORCE_ROOT_ACK");
-
- recvData.read_skip<uint32>(); // unk
-
- MovementInfo movementInfo;
- ReadMovementInfo(recvData, &movementInfo);
-*/
-}
-
-void WorldSession::HandleSetActionBarToggles(WorldPacket& recvData)
-{
- uint8 actionBar;
- recvData >> actionBar;
-
- if (!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED)
- {
- if (actionBar != 0)
- TC_LOG_ERROR("network", "WorldSession::HandleSetActionBarToggles in not logged state with value: %u, ignored", uint32(actionBar));
- return;
- }
-
- GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, actionBar);
-}
-
-void WorldSession::HandlePlayedTime(WorldPacket& recvData)
-{
- uint8 unk1;
- recvData >> unk1; // 0 or 1 expected
-
- WorldPacket data(SMSG_PLAYED_TIME, 4 + 4 + 1);
- data << uint32(_player->GetTotalPlayedTime());
- data << uint32(_player->GetLevelPlayedTime());
- data << uint8(unk1); // 0 - will not show in chat frame
- SendPacket(&data);
-}
-
-void WorldSession::HandleInspectOpcode(WorldPacket& recvData)
-{
- ObjectGuid guid;
- recvData >> guid;
-
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_INSPECT");
-
- Player* player = ObjectAccessor::FindPlayer(guid);
- if (!player)
- {
- TC_LOG_DEBUG("network", "CMSG_INSPECT: No player found from %s", guid.ToString().c_str());
- return;
- }
-
- if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
- return;
-
- if (GetPlayer()->IsValidAttackTarget(player))
- return;
-
- uint32 talent_points = 41;
- WorldPacket data(SMSG_INSPECT_TALENT, 8 + 4 + 1 + 1 + talent_points + 8 + 4 + 8 + 4);
- data << player->GetGUID();
-
- /* TODO: 6.x update packet structure (BuildPlayerTalentsInfoData no longer exists)
- if (sWorld->getBoolConfig(CONFIG_TALENTS_INSPECTING) || _player->IsGameMaster())
- player->BuildPlayerTalentsInfoData(&data);
- else
- {
- data << uint32(0); // unspentTalentPoints
- data << uint8(0); // talentGroupCount
- data << uint8(0); // talentGroupIndex
- }
- */
-
- player->BuildEnchantmentsInfoData(&data);
- if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId()))
- {
- data << guild->GetGUID();
- data << uint32(guild->GetLevel());
- data << uint64(guild->GetExperience());
- data << uint32(guild->GetMembersCount());
- }
- SendPacket(&data);
-}
-
-void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recvData)
-{
- ObjectGuid guid;
- guid[1] = recvData.ReadBit();
- guid[5] = recvData.ReadBit();
- guid[7] = recvData.ReadBit();
- guid[3] = recvData.ReadBit();
- guid[2] = recvData.ReadBit();
- guid[4] = recvData.ReadBit();
- guid[0] = recvData.ReadBit();
- guid[6] = recvData.ReadBit();
-
- recvData.ReadByteSeq(guid[4]);
- recvData.ReadByteSeq(guid[7]);
- recvData.ReadByteSeq(guid[0]);
- recvData.ReadByteSeq(guid[5]);
- recvData.ReadByteSeq(guid[1]);
- recvData.ReadByteSeq(guid[6]);
- recvData.ReadByteSeq(guid[2]);
- recvData.ReadByteSeq(guid[3]);
- Player* player = ObjectAccessor::FindPlayer(guid);
- if (!player)
- {
- TC_LOG_DEBUG("network", "CMSG_INSPECT_HONOR_STATS: No player found from %s", guid.ToString().c_str());
- return;
- }
-
- if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
- return;
-
- if (GetPlayer()->IsValidAttackTarget(player))
- return;
-
- ObjectGuid playerGuid = player->GetGUID();
- WorldPacket data(SMSG_INSPECT_HONOR_STATS, 8+1+4+4);
- data.WriteBit(playerGuid[4]);
- data.WriteBit(playerGuid[3]);
- data.WriteBit(playerGuid[6]);
- data.WriteBit(playerGuid[2]);
- data.WriteBit(playerGuid[5]);
- data.WriteBit(playerGuid[0]);
- data.WriteBit(playerGuid[7]);
- data.WriteBit(playerGuid[1]);
- data << uint8(0); // rank
- data << uint16(player->GetUInt16Value(PLAYER_FIELD_KILLS, 1)); // yesterday kills
- data << uint16(player->GetUInt16Value(PLAYER_FIELD_KILLS, 0)); // today kills
- data.WriteByteSeq(playerGuid[2]);
- data.WriteByteSeq(playerGuid[0]);
- data.WriteByteSeq(playerGuid[6]);
- data.WriteByteSeq(playerGuid[3]);
- data.WriteByteSeq(playerGuid[4]);
- data.WriteByteSeq(playerGuid[1]);
- data.WriteByteSeq(playerGuid[5]);
- data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS));
- data.WriteByteSeq(playerGuid[7]);
- SendPacket(&data);
-}
-
-void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recvData)
-{
- uint32 time;
- uint32 mapid;
- float PositionX;
- float PositionY;
- float PositionZ;
- float Orientation;
-
- recvData >> time; // time in m.sec.
- recvData >> mapid;
- recvData >> PositionX;
- recvData >> PositionY;
- recvData >> PositionZ;
- recvData >> Orientation; // o (3.141593 = 180 degrees)
-
- TC_LOG_DEBUG("network", "WORLD: Received CMSG_WORLD_TELEPORT");
-
- if (GetPlayer()->IsInFlight())
- {
- TC_LOG_DEBUG("network", "Player '%s' (%s) in flight, ignore worldport command.",
- GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().ToString().c_str());
- return;
- }
-
- TC_LOG_DEBUG("network", "CMSG_WORLD_TELEPORT: Player = %s, Time = %u, map = %u, x = %f, y = %f, z = %f, o = %f",
- GetPlayer()->GetName().c_str(), time, mapid, PositionX, PositionY, PositionZ, Orientation);
-
- if (HasPermission(rbac::RBAC_PERM_OPCODE_WORLD_TELEPORT))
- GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation);
- else
- SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
-}
-
-void WorldSession::HandleWhoisOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "Received opcode CMSG_WHOIS");
- std::string charname;
- recvData >> charname;
-
- if (!HasPermission(rbac::RBAC_PERM_OPCODE_WHOIS))
- {
- SendNotification(LANG_YOU_NOT_HAVE_PERMISSION);
- return;
- }
-
- if (charname.empty() || !normalizePlayerName (charname))
- {
- SendNotification(LANG_NEED_CHARACTER_NAME);
- return;
- }
-
- Player* player = ObjectAccessor::FindConnectedPlayerByName(charname);
-
- if (!player)
- {
- SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
- return;
- }
-
- uint32 accid = player->GetSession()->GetAccountId();
-
- PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_WHOIS);
-
- stmt->setUInt32(0, accid);
-
- PreparedQueryResult result = LoginDatabase.Query(stmt);
-
- if (!result)
- {
- SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
- return;
- }
-
- Field* fields = result->Fetch();
- std::string acc = fields[0].GetString();
- if (acc.empty())
- acc = "Unknown";
- std::string email = fields[1].GetString();
- if (email.empty())
- email = "Unknown";
- std::string lastip = fields[2].GetString();
- if (lastip.empty())
- lastip = "Unknown";
-
- std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip;
-
- WorldPacket data(SMSG_WHOIS, msg.size()+1);
- data << msg;
- SendPacket(&data);
-
- TC_LOG_DEBUG("network", "Received whois command from player %s for character %s",
- GetPlayer()->GetName().c_str(), charname.c_str());
-}
-
-void WorldSession::HandleComplainOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_COMPLAIN");
-
- uint8 spam_type; // 0 - mail, 1 - chat
- ObjectGuid spammer_guid;
- uint32 unk1 = 0;
- uint32 unk2 = 0;
- uint32 unk3 = 0;
- uint32 unk4 = 0;
- std::string description = "";
- recvData >> spam_type; // unk 0x01 const, may be spam type (mail/chat)
- recvData >> spammer_guid; // player guid
- switch (spam_type)
- {
- case 0:
- recvData >> unk1; // const 0
- recvData >> unk2; // probably mail id
- recvData >> unk3; // const 0
- break;
- case 1:
- recvData >> unk1; // probably language
- recvData >> unk2; // message type?
- recvData >> unk3; // probably channel id
- recvData >> unk4; // time
- recvData >> description; // spam description string (messagetype, channel name, player name, message)
- break;
- }
-
- // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam.
- // if it's mail spam - ALL mails from this spammer automatically removed by client
-
- // Complaint Received message
- WorldPacket data(SMSG_COMPLAIN_RESULT, 2);
- data << uint8(0); // value 1 resets CGChat::m_complaintsSystemStatus in client. (unused?)
- data << uint8(0); // value 0xC generates a "CalendarError" in client.
- SendPacket(&data);
-
- TC_LOG_DEBUG("network", "REPORT SPAM: type %u, %s, unk1 %u, unk2 %u, unk3 %u, unk4 %u, message %s",
- spam_type, spammer_guid.ToString().c_str(), unk1, unk2, unk3, unk4, description.c_str());
-}
-
-void WorldSession::HandleRealmSplitOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "CMSG_REALM_SPLIT");
-
- uint32 unk;
- std::string split_date = "01/01/01";
- recvData >> unk;
-
- WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1);
- data << unk;
- data << uint32(0x00000000); // realm split state
- // split states:
- // 0x0 realm normal
- // 0x1 realm split
- // 0x2 realm split pending
- data << split_date;
- SendPacket(&data);
- //TC_LOG_DEBUG("response sent %u", unk);
-}
-
-void WorldSession::HandleFarSightOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_FAR_SIGHT");
-
- bool apply;
- recvData >> apply;
-
- if (apply)
- {
- TC_LOG_DEBUG("network", "Added FarSight %s to %s", _player->GetGuidValue(PLAYER_FARSIGHT).ToString().c_str(), _player->GetGUID().ToString().c_str());
- if (WorldObject* target = _player->GetViewpoint())
- _player->SetSeer(target);
- else
- TC_LOG_ERROR("network", "Player %s (%s) requests non-existing seer %s", _player->GetName().c_str(), _player->GetGUID().ToString().c_str(), _player->GetGuidValue(PLAYER_FARSIGHT).ToString().c_str());
- }
- else
- {
- TC_LOG_DEBUG("network", "%s set vision to self", _player->GetGUID().ToString().c_str());
- _player->SetSeer(_player);
- }
-
- GetPlayer()->UpdateVisibilityForPlayer();
-}
-
-void WorldSession::HandleSetTitleOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "CMSG_SET_TITLE");
-
- int32 title;
- recvData >> title;
-
- // -1 at none
- if (title > 0 && title < MAX_TITLE_INDEX)
- {
- if (!GetPlayer()->HasTitle(title))
- return;
- }
- else
- title = 0;
-
- GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title);
-}
-
-void WorldSession::HandleTimeSyncResponse(WorldPackets::Misc::TimeSyncResponse& packet)
-{
- TC_LOG_DEBUG("network", "CMSG_TIME_SYNC_RESPONSE");
-
- // Prevent crashing server if queue is empty
- if (_player->m_timeSyncQueue.empty())
- {
- TC_LOG_ERROR("network", "Received CMSG_TIME_SYNC_RESPONSE from player %s without requesting it (hacker?)", _player->GetName().c_str());
- return;
- }
-
- if (packet.SequenceIndex != _player->m_timeSyncQueue.front())
- TC_LOG_ERROR("network", "Wrong time sync counter from player %s (cheater?)", _player->GetName().c_str());
-
- TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", packet.SequenceIndex, packet.ClientTime, packet.ClientTime - _player->m_timeSyncClient);
-
- uint32 ourTicks = packet.ClientTime + (getMSTime() - _player->m_timeSyncServer);
-
- // diff should be small
- TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - packet.ClientTime, GetLatency());
-
- _player->m_timeSyncClient = packet.ClientTime;
- _player->m_timeSyncQueue.pop();
-}
-
-void WorldSession::HandleResetInstancesOpcode(WorldPacket& /*recvData*/)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_RESET_INSTANCES");
-
- if (Group* group = _player->GetGroup())
- {
- if (group->IsLeader(_player->GetGUID()))
- group->ResetInstances(INSTANCE_RESET_ALL, false, false, _player);
- }
- else
- _player->ResetInstances(INSTANCE_RESET_ALL, false, false);
-}
-
-void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPackets::Misc::SetDungeonDifficulty& setDungeonDifficulty)
-{
- DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(setDungeonDifficulty.DifficultyID);
- if (!difficultyEntry)
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an invalid instance mode %d!",
- _player->GetGUID().ToString().c_str(), setDungeonDifficulty.DifficultyID);
- return;
- }
-
- if (difficultyEntry->InstanceType != MAP_INSTANCE)
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an non-dungeon instance mode %d!",
- _player->GetGUID().ToString().c_str(), difficultyEntry->ID);
- return;
- }
-
- if (!(difficultyEntry->Flags & DIFFICULTY_FLAG_CAN_SELECT))
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent unselectable instance mode %d!",
- _player->GetGUID().ToString().c_str(), difficultyEntry->ID);
- return;
- }
-
- Difficulty difficultyID = Difficulty(difficultyEntry->ID);
- if (difficultyID == _player->GetDungeonDifficultyID())
- return;
-
- // cannot reset while in an instance
- Map* map = _player->FindMap();
- if (map && map->IsDungeon())
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: player (Name: %s, %s) tried to reset the instance while player is inside!",
- _player->GetName().c_str(), _player->GetGUID().ToString().c_str());
- return;
- }
-
- Group* group = _player->GetGroup();
- if (group)
- {
- if (group->IsLeader(_player->GetGUID()))
- {
- for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
- {
- Player* groupGuy = itr->GetSource();
- if (!groupGuy)
- continue;
-
- if (!groupGuy->IsInMap(groupGuy))
- return;
-
- if (groupGuy->GetMap()->IsNonRaidDungeon())
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s tried to reset the instance while group member (Name: %s, %s) is inside!",
- _player->GetGUID().ToString().c_str(), groupGuy->GetName().c_str(), groupGuy->GetGUID().ToString().c_str());
- return;
- }
- }
- // the difficulty is set even if the instances can't be reset
- //_player->SendDungeonDifficulty(true);
- group->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, false, _player);
- group->SetDungeonDifficultyID(difficultyID);
- }
- }
- else
- {
- _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, false);
- _player->SetDungeonDifficultyID(difficultyID);
- _player->SendDungeonDifficulty();
- }
-}
-
-void WorldSession::HandleSetRaidDifficultyOpcode(WorldPackets::Misc::SetRaidDifficulty& setRaidDifficulty)
-{
- DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(setRaidDifficulty.DifficultyID);
- if (!difficultyEntry)
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an invalid instance mode %u!",
- _player->GetGUID().ToString().c_str(), setRaidDifficulty.DifficultyID);
- return;
- }
-
- if (difficultyEntry->InstanceType != MAP_RAID)
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an non-dungeon instance mode %u!",
- _player->GetGUID().ToString().c_str(), difficultyEntry->ID);
- return;
- }
-
- if (!(difficultyEntry->Flags & DIFFICULTY_FLAG_CAN_SELECT))
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent unselectable instance mode %u!",
- _player->GetGUID().ToString().c_str(), difficultyEntry->ID);
- return;
- }
-
- if (((difficultyEntry->Flags & DIFFICULTY_FLAG_LEGACY) >> 5) != setRaidDifficulty.Legacy)
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent not matching legacy difficulty %u!",
- _player->GetGUID().ToString().c_str(), difficultyEntry->ID);
- return;
- }
-
- Difficulty difficultyID = Difficulty(difficultyEntry->ID);
- if (difficultyID == (setRaidDifficulty.Legacy ? _player->GetLegacyRaidDifficultyID() : _player->GetRaidDifficultyID()))
- return;
-
- // cannot reset while in an instance
- Map* map = _player->FindMap();
- if (map && map->IsDungeon())
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetRaidDifficultyOpcode: player (Name: %s, %s) tried to reset the instance while player is inside!",
- _player->GetName().c_str(), _player->GetGUID().ToString().c_str());
- return;
- }
-
- Group* group = _player->GetGroup();
- if (group)
- {
- if (group->IsLeader(_player->GetGUID()))
- {
- for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
- {
- Player* groupGuy = itr->GetSource();
- if (!groupGuy)
- continue;
-
- if (!groupGuy->IsInMap(groupGuy))
- return;
-
- if (groupGuy->GetMap()->IsRaid())
- {
- TC_LOG_DEBUG("network", "WorldSession::HandleSetRaidDifficultyOpcode: %s tried to reset the instance while group member (Name: %s, %s) is inside!",
- _player->GetGUID().ToString().c_str(), groupGuy->GetName().c_str(), groupGuy->GetGUID().ToString().c_str());
- return;
- }
- }
- // the difficulty is set even if the instances can't be reset
- group->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, setRaidDifficulty.Legacy != 0, _player);
- if (setRaidDifficulty.Legacy)
- group->SetLegacyRaidDifficultyID(difficultyID);
- else
- group->SetRaidDifficultyID(difficultyID);
- }
- }
- else
- {
- _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, setRaidDifficulty.Legacy != 0);
- if (setRaidDifficulty.Legacy)
- _player->SetLegacyRaidDifficultyID(difficultyID);
- else
- _player->SetRaidDifficultyID(difficultyID);
-
- _player->SendRaidDifficulty(setRaidDifficulty.Legacy != 0);
- }
-}
-
-void WorldSession::HandleCancelMountAuraOpcode(WorldPacket& /*recvData*/)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_CANCEL_MOUNT_AURA");
-
- //If player is not mounted, so go out :)
- if (!_player->IsMounted()) // not blizz like; no any messages on blizz
- {
- ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED);
- return;
- }
-
- if (_player->IsInFlight()) // not blizz like; no any messages on blizz
- {
- ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT);
- return;
- }
-
- _player->RemoveAurasByType(SPELL_AURA_MOUNTED); // Calls Dismount()
-}
-
-void WorldSession::HandleMoveSetCanFlyAckOpcode(WorldPacket& recvData)
-{
- // fly mode on/off
- TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_SET_CAN_FLY_ACK");
-
- MovementInfo movementInfo;
- _player->ReadMovementInfo(recvData, &movementInfo);
-
- _player->m_mover->m_movementInfo.flags = movementInfo.GetMovementFlags();
-}
-
-void WorldSession::HandleRequestPetInfoOpcode(WorldPacket& /*recvData */)
-{
- /*
- TC_LOG_DEBUG("network", "WORLD: CMSG_REQUEST_PET_INFO");
- recvData.hexlike();
- */
-}
-
-void WorldSession::HandleSetTaxiBenchmarkOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_SET_TAXI_BENCHMARK_MODE");
-
- uint8 mode;
- recvData >> mode;
-
- mode ? _player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_TAXI_BENCHMARK) : _player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_TAXI_BENCHMARK);
-
- TC_LOG_DEBUG("network", "Client used \"/timetest %d\" command", mode);
-}
-
-void WorldSession::HandleQueryInspectAchievements(WorldPacket& recvData)
-{
- ObjectGuid guid;
- recvData >> guid.ReadAsPacked();
-
- TC_LOG_DEBUG("network", "CMSG_QUERY_INSPECT_ACHIEVEMENTS [%s] Inspected Player [%s]", _player->GetGUID().ToString().c_str(), guid.ToString().c_str());
- Player* player = ObjectAccessor::FindPlayer(guid);
- if (!player)
- return;
-
- if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false))
- return;
-
- if (GetPlayer()->IsValidAttackTarget(player))
- return;
-
- player->SendRespondInspectAchievements(_player);
-}
-
-void WorldSession::HandleGuildSetFocusedAchievement(WorldPackets::Achievement::GuildSetFocusedAchievement& setFocusedAchievement)
-{
- if (Guild* guild = sGuildMgr->GetGuildById(_player->GetGuildId()))
- guild->GetAchievementMgr().SendAchievementInfo(_player, setFocusedAchievement.AchievementID);
-}
-
-void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& /*recvData*/)
-{
- // empty opcode
- TC_LOG_DEBUG("network", "WORLD: CMSG_WORLD_STATE_UI_TIMER_UPDATE");
-
- WorldPackets::Misc::UITime response;
- response.Time = time(NULL);
- SendPacket(response.Write());
-}
-
-void WorldSession::SendSetPhaseShift(std::set<uint32> const& phaseIds, std::set<uint32> const& terrainswaps, std::set<uint32> const& worldMapAreaSwaps)
-{
- ObjectGuid guid = _player->GetGUID();
-
- WorldPacket data(SMSG_SET_PHASE_SHIFT, 1 + 8 + 4 + 4 + 4 + 4 + 2 * phaseIds.size() + 4 + terrainswaps.size() * 2);
- data.WriteBit(guid[2]);
- data.WriteBit(guid[3]);
- data.WriteBit(guid[1]);
- data.WriteBit(guid[6]);
- data.WriteBit(guid[4]);
- data.WriteBit(guid[5]);
- data.WriteBit(guid[0]);
- data.WriteBit(guid[7]);
-
- data.WriteByteSeq(guid[7]);
- data.WriteByteSeq(guid[4]);
-
- data << uint32(worldMapAreaSwaps.size());
- for (auto mapSwap : worldMapAreaSwaps)
- data << uint16(mapSwap); // WorldMapArea.dbc id (controls map display)
-
- data.WriteByteSeq(guid[1]);
-
- data << uint32(phaseIds.size() ? 0 : 8); // flags (not phasemask)
-
- data.WriteByteSeq(guid[2]);
- data.WriteByteSeq(guid[6]);
-
- data << uint32(0); // Inactive terrain swaps
- //for (uint8 i = 0; i < inactiveSwapsCount; ++i)
- // data << uint16(0);
-
- data << uint32(phaseIds.size()) * 2; // Phase.dbc ids
- for (std::set<uint32>::const_iterator itr = phaseIds.begin(); itr != phaseIds.end(); ++itr)
- data << uint16(*itr);
-
- data.WriteByteSeq(guid[3]);
- data.WriteByteSeq(guid[0]);
-
- data << uint32(terrainswaps.size()) * 2; // Active terrain swaps
- for (std::set<uint32>::const_iterator itr = terrainswaps.begin(); itr != terrainswaps.end(); ++itr)
- data << uint16(*itr);
-
- data.WriteByteSeq(guid[5]);
-
- SendPacket(&data);
-}
-
-// Battlefield and Battleground
-void WorldSession::HandleAreaSpiritHealerQueryOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_AREA_SPIRIT_HEALER_QUERY");
-
- Battleground* bg = _player->GetBattleground();
-
- ObjectGuid guid;
- recvData >> guid;
-
- Creature* unit = GetPlayer()->GetMap()->GetCreature(guid);
- if (!unit)
- return;
-
- if (!unit->IsSpiritService()) // it's not spirit service
- return;
-
- if (bg)
- sBattlegroundMgr->SendAreaSpiritHealerQueryOpcode(_player, bg, guid);
-
- if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
- bf->SendAreaSpiritHealerQueryOpcode(_player, guid);
-}
-
-void WorldSession::HandleAreaSpiritHealerQueueOpcode(WorldPacket& recvData)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_AREA_SPIRIT_HEALER_QUEUE");
-
- Battleground* bg = _player->GetBattleground();
-
- ObjectGuid guid;
- recvData >> guid;
-
- Creature* unit = GetPlayer()->GetMap()->GetCreature(guid);
- if (!unit)
- return;
-
- if (!unit->IsSpiritService()) // it's not spirit service
- return;
-
- if (bg)
- bg->AddPlayerToResurrectQueue(guid, _player->GetGUID());
-
- if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
- bf->AddPlayerToResurrectQueue(guid, _player->GetGUID());
-}
-
-void WorldSession::HandleHearthAndResurrect(WorldPacket& /*recvData*/)
-{
- if (_player->IsInFlight())
- return;
-
- if (/*Battlefield* bf = */sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId()))
- {
- // bf->PlayerAskToLeave(_player); FIXME
- return;
- }
-
- AreaTableEntry const* atEntry = GetAreaEntryByAreaID(_player->GetAreaId());
- if (!atEntry || !(atEntry->Flags[0] & AREA_FLAG_WINTERGRASP_2))
- return;
-
- _player->BuildPlayerRepop();
- _player->ResurrectPlayer(1.0f);
- _player->TeleportTo(_player->m_homebindMapId, _player->m_homebindX, _player->m_homebindY, _player->m_homebindZ, _player->GetOrientation());
-}
-
-void WorldSession::HandleInstanceLockResponse(WorldPacket& recvPacket)
-{
- uint8 accept;
- recvPacket >> accept;
-
- if (!_player->HasPendingBind())
- {
- TC_LOG_INFO("network", "InstanceLockResponse: Player %s (%s) tried to bind himself/teleport to graveyard without a pending bind!",
- _player->GetName().c_str(), _player->GetGUID().ToString().c_str());
- return;
- }
-
- if (accept)
- _player->BindToInstance();
- else
- _player->RepopAtGraveyard();
-
- _player->SetPendingBind(0, 0);
-}
-
-void WorldSession::HandleUpdateMissileTrajectory(WorldPacket& recvPacket)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_UPDATE_MISSILE_TRAJECTORY");
-
- ObjectGuid guid;
- uint32 spellId;
- float elevation, speed;
- float curX, curY, curZ;
- float targetX, targetY, targetZ;
- uint8 moveStop;
-
- recvPacket >> guid >> spellId >> elevation >> speed;
- recvPacket >> curX >> curY >> curZ;
- recvPacket >> targetX >> targetY >> targetZ;
- recvPacket >> moveStop;
-
- Unit* caster = ObjectAccessor::GetUnit(*_player, guid);
- Spell* spell = caster ? caster->GetCurrentSpell(CURRENT_GENERIC_SPELL) : NULL;
- if (!spell || spell->m_spellInfo->Id != spellId || !spell->m_targets.HasDst() || !spell->m_targets.HasSrc())
- {
- recvPacket.rfinish();
- return;
- }
-
- Position pos = *spell->m_targets.GetSrcPos();
- pos.Relocate(curX, curY, curZ);
- spell->m_targets.ModSrc(pos);
-
- pos = *spell->m_targets.GetDstPos();
- pos.Relocate(targetX, targetY, targetZ);
- spell->m_targets.ModDst(pos);
-
- spell->m_targets.SetElevation(elevation);
- spell->m_targets.SetSpeed(speed);
-
- if (moveStop)
- {
- uint32 opcode;
- recvPacket >> opcode;
- recvPacket.SetOpcode(CMSG_MOVE_STOP); // always set to CMSG_MOVE_STOP in client SetOpcode
- //HandleMovementOpcodes(recvPacket);
- }
-}
-
-void WorldSession::HandleViolenceLevel(WorldPackets::Misc::ViolenceLevel& /*violenceLevel*/)
-{
- // do something?
-}
-
-void WorldSession::HandleObjectUpdateFailedOpcode(WorldPacket& recvPacket)
-{
- ObjectGuid guid;
- guid[6] = recvPacket.ReadBit();
- guid[7] = recvPacket.ReadBit();
- guid[4] = recvPacket.ReadBit();
- guid[0] = recvPacket.ReadBit();
- guid[1] = recvPacket.ReadBit();
- guid[5] = recvPacket.ReadBit();
- guid[3] = recvPacket.ReadBit();
- guid[2] = recvPacket.ReadBit();
-
- recvPacket.ReadByteSeq(guid[6]);
- recvPacket.ReadByteSeq(guid[7]);
- recvPacket.ReadByteSeq(guid[2]);
- recvPacket.ReadByteSeq(guid[3]);
- recvPacket.ReadByteSeq(guid[1]);
- recvPacket.ReadByteSeq(guid[4]);
- recvPacket.ReadByteSeq(guid[0]);
- recvPacket.ReadByteSeq(guid[5]);
-
- WorldObject* obj = ObjectAccessor::GetWorldObject(*GetPlayer(), guid);
- TC_LOG_ERROR("network", "Object update failed for %s (%s) for player %s (%s)", guid.ToString().c_str(), obj ? obj->GetName().c_str() : "object-not-found", GetPlayerName().c_str(), _player->GetGUID().ToString().c_str());
-
- // If create object failed for current player then client will be stuck on loading screen
- if (_player->GetGUID() == guid)
- {
- LogoutPlayer(true);
- return;
- }
-
- // Pretend we've never seen this object
- _player->m_clientGUIDs.erase(guid);
-}
-
-void WorldSession::HandleSaveCUFProfiles(WorldPacket& recvPacket)
-{
- TC_LOG_DEBUG("network", "WORLD: CMSG_SAVE_CUF_PROFILES");
-
- uint8 count = (uint8)recvPacket.ReadBits(20);
-
- if (count > MAX_CUF_PROFILES)
- {
- TC_LOG_ERROR("entities.player", "HandleSaveCUFProfiles - %s tried to save more than %i CUF profiles. Hacking attempt?", GetPlayerName().c_str(), MAX_CUF_PROFILES);
- recvPacket.rfinish();
- return;
- }
-
- CUFProfile* profiles[MAX_CUF_PROFILES];
- uint8 strlens[MAX_CUF_PROFILES];
-
- for (uint8 i = 0; i < count; ++i)
- {
- profiles[i] = new CUFProfile;
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_SPEC_2 , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_10_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_UNK_157 , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_HEAL_PREDICTION , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_SPEC_1 , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_PVP , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_POWER_BAR , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_15_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_40_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_PETS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_5_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_ONLY_DISPELLABLE_DEBUFFS, recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_2_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_UNK_156 , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_NON_BOSS_DEBUFFS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_MAIN_TANK_AND_ASSIST , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_AGGRO_HIGHLIGHT , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_3_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_BORDER , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_USE_CLASS_COLORS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_UNK_145 , recvPacket.ReadBit());
- strlens[i] = (uint8)recvPacket.ReadBits(8);
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_PVE , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_DISPLAY_HORIZONTAL_GROUPS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_25_PLAYERS , recvPacket.ReadBit());
- profiles[i]->BoolOptions.set(CUF_KEEP_GROUPS_TOGETHER , recvPacket.ReadBit());
- }
-
- for (uint8 i = 0; i < count; ++i)
- {
- recvPacket >> profiles[i]->Unk146;
- profiles[i]->ProfileName = recvPacket.ReadString(strlens[i]);
- recvPacket >> profiles[i]->Unk152;
- recvPacket >> profiles[i]->FrameHeight;
- recvPacket >> profiles[i]->FrameWidth;
- recvPacket >> profiles[i]->Unk150;
- recvPacket >> profiles[i]->HealthText;
- recvPacket >> profiles[i]->Unk147;
- recvPacket >> profiles[i]->SortBy;
- recvPacket >> profiles[i]->Unk154;
- recvPacket >> profiles[i]->Unk148;
-
- GetPlayer()->SaveCUFProfile(i, profiles[i]);
- }
-
- for (uint8 i = count; i < MAX_CUF_PROFILES; ++i)
- GetPlayer()->SaveCUFProfile(i, NULL);
-}
-
-void WorldSession::SendLoadCUFProfiles()
-{
- Player* player = GetPlayer();
-
- uint8 count = player->GetCUFProfilesCount();
-
- ByteBuffer byteBuffer(25 * count);
- WorldPacket data(SMSG_LOAD_CUF_PROFILES, 5 * count + 25 * count);
-
- data.WriteBits(count, 20);
- for (uint8 i = 0; i < MAX_CUF_PROFILES; ++i)
- {
- CUFProfile* profile = player->GetCUFProfile(i);
- if (!profile)
- continue;
-
- data.WriteBit(profile->BoolOptions[CUF_UNK_157]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_10_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_5_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_25_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_HEAL_PREDICTION]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_PVE]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_HORIZONTAL_GROUPS]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_40_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_3_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_AGGRO_HIGHLIGHT]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_BORDER]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_2_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_NON_BOSS_DEBUFFS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_MAIN_TANK_AND_ASSIST]);
- data.WriteBit(profile->BoolOptions[CUF_UNK_156]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_SPEC_2]);
- data.WriteBit(profile->BoolOptions[CUF_USE_CLASS_COLORS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_POWER_BAR]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_SPEC_1]);
- data.WriteBits(profile->ProfileName.size(), 8);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_ONLY_DISPELLABLE_DEBUFFS]);
- data.WriteBit(profile->BoolOptions[CUF_KEEP_GROUPS_TOGETHER]);
- data.WriteBit(profile->BoolOptions[CUF_UNK_145]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_15_PLAYERS]);
- data.WriteBit(profile->BoolOptions[CUF_DISPLAY_PETS]);
- data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_PVP]);
-
- byteBuffer << uint16(profile->Unk154);
- byteBuffer << uint16(profile->FrameHeight);
- byteBuffer << uint16(profile->Unk152);
- byteBuffer << uint8(profile->Unk147);
- byteBuffer << uint16(profile->Unk150);
- byteBuffer << uint8(profile->Unk146);
- byteBuffer << uint8(profile->HealthText);
- byteBuffer << uint8(profile->SortBy);
- byteBuffer << uint16(profile->FrameWidth);
- byteBuffer << uint8(profile->Unk148);
- byteBuffer.WriteString(profile->ProfileName);
- }
-
- data.FlushBits();
- data.append(byteBuffer);
- SendPacket(&data);
-}
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "Common.h" +#include "Language.h" +#include "DatabaseEnv.h" +#include "WorldPacket.h" +#include "Opcodes.h" +#include "Log.h" +#include "Player.h" +#include "GossipDef.h" +#include "World.h" +#include "ObjectMgr.h" +#include "GuildMgr.h" +#include "WorldSession.h" +#include "BigNumber.h" +#include "SHA1.h" +#include "UpdateData.h" +#include "LootMgr.h" +#include "Chat.h" +#include "zlib.h" +#include "ObjectAccessor.h" +#include "Object.h" +#include "Battleground.h" +#include "OutdoorPvP.h" +#include "Pet.h" +#include "SocialMgr.h" +#include "CellImpl.h" +#include "AccountMgr.h" +#include "Vehicle.h" +#include "CreatureAI.h" +#include "DBCEnums.h" +#include "ScriptMgr.h" +#include "MapManager.h" +#include "InstanceScript.h" +#include "GameObjectAI.h" +#include "Group.h" +#include "AccountMgr.h" +#include "Spell.h" +#include "SpellPackets.h" +#include "BattlegroundMgr.h" +#include "Battlefield.h" +#include "BattlefieldMgr.h" +#include "DB2Stores.h" +#include "CharacterPackets.h" +#include "ClientConfigPackets.h" +#include "MiscPackets.h" +#include "AchievementPackets.h" + +void WorldSession::HandleRepopRequest(WorldPackets::Misc::RepopRequest& packet) +{ + TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_REPOP_REQUEST Message"); + + if (GetPlayer()->IsAlive() || GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) + return; + + if (GetPlayer()->HasAuraType(SPELL_AURA_PREVENT_RESURRECTION)) + return; // silently return, client should display the error by itself + + // the world update order is sessions, players, creatures + // the netcode runs in parallel with all of these + // creatures can kill players + // so if the server is lagging enough the player can + // release spirit after he's killed but before he is updated + if (GetPlayer()->getDeathState() == JUST_DIED) + { + TC_LOG_DEBUG("network", "HandleRepopRequestOpcode: got request after player %s(%s) was killed and before he was updated", + GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().ToString().c_str()); + GetPlayer()->KillPlayer(); + } + + //this is spirit release confirm? + GetPlayer()->RemovePet(NULL, PET_SAVE_NOT_IN_SLOT, true); + GetPlayer()->BuildPlayerRepop(); + GetPlayer()->RepopAtGraveyard(); +} + +void WorldSession::HandleGossipSelectOptionOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_GOSSIP_SELECT_OPTION"); + + uint32 gossipListId; + uint32 menuId; + ObjectGuid guid; + std::string code = ""; + + recvData >> guid >> menuId >> gossipListId; + + if (!_player->PlayerTalkClass->GetGossipMenu().GetItem(gossipListId)) + { + recvData.rfinish(); + return; + } + + if (_player->PlayerTalkClass->IsGossipOptionCoded(gossipListId)) + recvData >> code; + + // Prevent cheating on C++ scripted menus + if (_player->PlayerTalkClass->GetGossipMenu().GetSenderGUID() != guid) + return; + + Creature* unit = NULL; + GameObject* go = NULL; + if (guid.IsCreatureOrVehicle()) + { + unit = GetPlayer()->GetNPCIfCanInteractWith(guid, UNIT_NPC_FLAG_NONE); + if (!unit) + { + TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - %s not found or you can't interact with him.", guid.ToString().c_str()); + return; + } + } + else if (guid.IsGameObject()) + { + go = _player->GetMap()->GetGameObject(guid); + if (!go) + { + TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - %s not found.", guid.ToString().c_str()); + return; + } + } + else + { + TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - unsupported %s.", guid.ToString().c_str()); + return; + } + + // remove fake death + if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) + GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); + + if ((unit && unit->GetCreatureTemplate()->ScriptID != unit->LastUsedScriptID) || (go && go->GetGOInfo()->ScriptId != go->LastUsedScriptID)) + { + TC_LOG_DEBUG("network", "WORLD: HandleGossipSelectOptionOpcode - Script reloaded while in use, ignoring and set new scipt id"); + if (unit) + unit->LastUsedScriptID = unit->GetCreatureTemplate()->ScriptID; + if (go) + go->LastUsedScriptID = go->GetGOInfo()->ScriptId; + _player->PlayerTalkClass->SendCloseGossip(); + return; + } + if (!code.empty()) + { + if (unit) + { + unit->AI()->sGossipSelectCode(_player, menuId, gossipListId, code.c_str()); + if (!sScriptMgr->OnGossipSelectCode(_player, unit, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str())) + _player->OnGossipSelect(unit, gossipListId, menuId); + } + else + { + go->AI()->GossipSelectCode(_player, menuId, gossipListId, code.c_str()); + if (!sScriptMgr->OnGossipSelectCode(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId), code.c_str())) + _player->OnGossipSelect(go, gossipListId, menuId); + } + } + else + { + if (unit) + { + unit->AI()->sGossipSelect(_player, menuId, gossipListId); + if (!sScriptMgr->OnGossipSelect(_player, unit, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId))) + _player->OnGossipSelect(unit, gossipListId, menuId); + } + else + { + go->AI()->GossipSelect(_player, menuId, gossipListId); + if (!sScriptMgr->OnGossipSelect(_player, go, _player->PlayerTalkClass->GetGossipOptionSender(gossipListId), _player->PlayerTalkClass->GetGossipOptionAction(gossipListId))) + _player->OnGossipSelect(go, gossipListId, menuId); + } + } +} + +void WorldSession::HandleWhoOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_WHO Message"); + + uint32 matchcount = 0; + + uint32 level_min, level_max, racemask, classmask, zones_count, str_count; + uint32 zoneids[10]; // 10 is client limit + std::string player_name, guild_name; + + recvData >> level_min; // maximal player level, default 0 + recvData >> level_max; // minimal player level, default 100 (MAX_LEVEL) + recvData >> player_name; // player name, case sensitive... + + recvData >> guild_name; // guild name, case sensitive... + + recvData >> racemask; // race mask + recvData >> classmask; // class mask + recvData >> zones_count; // zones count, client limit = 10 (2.0.10) + + if (zones_count > 10) + return; // can't be received from real client or broken packet + + for (uint32 i = 0; i < zones_count; ++i) + { + uint32 temp; + recvData >> temp; // zone id, 0 if zone is unknown... + zoneids[i] = temp; + TC_LOG_DEBUG("network", "Zone %u: %u", i, zoneids[i]); + } + + recvData >> str_count; // user entered strings count, client limit=4 (checked on 2.0.10) + + if (str_count > 4) + return; // can't be received from real client or broken packet + + TC_LOG_DEBUG("network", "Minlvl %u, maxlvl %u, name %s, guild %s, racemask %u, classmask %u, zones %u, strings %u", level_min, level_max, player_name.c_str(), guild_name.c_str(), racemask, classmask, zones_count, str_count); + + std::wstring str[4]; // 4 is client limit + for (uint32 i = 0; i < str_count; ++i) + { + std::string temp; + recvData >> temp; // user entered string, it used as universal search pattern(guild+player name)? + + if (!Utf8toWStr(temp, str[i])) + continue; + + wstrToLower(str[i]); + + TC_LOG_DEBUG("network", "String %u: %s", i, temp.c_str()); + } + + std::wstring wplayer_name; + std::wstring wguild_name; + if (!(Utf8toWStr(player_name, wplayer_name) && Utf8toWStr(guild_name, wguild_name))) + return; + wstrToLower(wplayer_name); + wstrToLower(wguild_name); + + // client send in case not set max level value 100 but Trinity supports 255 max level, + // update it to show GMs with characters after 100 level + if (level_max >= MAX_LEVEL) + level_max = STRONG_MAX_LEVEL; + + uint32 team = _player->GetTeam(); + + uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST); + uint32 displaycount = 0; + + WorldPacket data(SMSG_WHO, 50); // guess size + data << uint32(matchcount); // placeholder, count of players matching criteria + data << uint32(displaycount); // placeholder, count of players displayed + + boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock()); + + HashMapHolder<Player>::MapType const& m = ObjectAccessor::GetPlayers(); + for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) + { + Player* target = itr->second; + // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST + if (target->GetTeam() != team && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_WHO_LIST)) + continue; + + // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST + if (!HasPermission(rbac::RBAC_PERM_WHO_SEE_ALL_SEC_LEVELS) && target->GetSession()->GetSecurity() > AccountTypes(gmLevelInWhoList)) + continue; + + // do not process players which are not in world + if (!target->IsInWorld()) + continue; + + // check if target is globally visible for player + if (!target->IsVisibleGloballyFor(_player)) + continue; + + // check if target's level is in level range + uint8 lvl = target->getLevel(); + if (lvl < level_min || lvl > level_max) + continue; + + // check if class matches classmask + uint8 class_ = target->getClass(); + if (!(classmask & (1 << class_))) + continue; + + // check if race matches racemask + uint32 race = target->getRace(); + if (!(racemask & (1 << race))) + continue; + + uint32 pzoneid = target->GetZoneId(); + uint8 gender = target->getGender(); + + bool z_show = true; + for (uint32 i = 0; i < zones_count; ++i) + { + if (zoneids[i] == pzoneid) + { + z_show = true; + break; + } + + z_show = false; + } + if (!z_show) + continue; + + std::string pname = target->GetName(); + std::wstring wpname; + if (!Utf8toWStr(pname, wpname)) + continue; + wstrToLower(wpname); + + if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos)) + continue; + + std::string gname = sGuildMgr->GetGuildNameById(target->GetGuildId()); + std::wstring wgname; + if (!Utf8toWStr(gname, wgname)) + continue; + wstrToLower(wgname); + + if (!(wguild_name.empty() || wgname.find(wguild_name) != std::wstring::npos)) + continue; + + std::string aname; + if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid)) + aname = areaEntry->ZoneName; + + bool s_show = true; + for (uint32 i = 0; i < str_count; ++i) + { + if (!str[i].empty()) + { + if (wgname.find(str[i]) != std::wstring::npos || + wpname.find(str[i]) != std::wstring::npos || + Utf8FitTo(aname, str[i])) + { + s_show = true; + break; + } + s_show = false; + } + } + if (!s_show) + continue; + + // 49 is maximum player count sent to client - can be overridden + // through config, but is unstable + if ((matchcount++) >= sWorld->getIntConfig(CONFIG_MAX_WHO)) + continue; + + data << pname; // player name + data << gname; // guild name + data << uint32(lvl); // player level + data << uint32(class_); // player class + data << uint32(race); // player race + data << uint8(gender); // player gender + data << uint32(pzoneid); // player zone id + + ++displaycount; + } + + data.put(0, displaycount); // insert right count, count displayed + data.put(4, matchcount); // insert right count, count of matches + + SendPacket(&data); + TC_LOG_DEBUG("network", "WORLD: Send SMSG_WHO Message"); +} + +void WorldSession::HandleLogoutRequestOpcode(WorldPackets::Character::LogoutRequest& /*logoutRequest*/) +{ + TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_LOGOUT_REQUEST Message, security - %u", GetSecurity()); + + ObjectGuid lguid = GetPlayer()->GetLootGUID(); + if (!lguid.IsEmpty()) + DoLootRelease(lguid); + + bool instantLogout = (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) && !GetPlayer()->IsInCombat()) || + GetPlayer()->IsInFlight() || HasPermission(rbac::RBAC_PERM_INSTANT_LOGOUT); + + /// TODO: Possibly add RBAC permission to log out in combat + bool canLogoutInCombat = GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); + + uint32 reason = 0; + if (GetPlayer()->IsInCombat() && !canLogoutInCombat) + reason = 1; + else if (GetPlayer()->IsFalling()) + reason = 3; // is jumping or falling + else if (GetPlayer()->duel || GetPlayer()->HasAura(9454)) // is dueling or frozen by GM via freeze command + reason = 2; // FIXME - Need the correct value + + WorldPackets::Character::LogoutResponse logoutResponse; + logoutResponse.LogoutResult = reason; + logoutResponse.Instant = instantLogout; + SendPacket(logoutResponse.Write()); + + if (reason) + { + SetLogoutStartTime(0); + return; + } + + // instant logout in taverns/cities or on taxi or for admins, gm's, mod's if its enabled in worldserver.conf + if (instantLogout) + { + LogoutPlayer(true); + return; + } + + // not set flags if player can't free move to prevent lost state at logout cancel + if (GetPlayer()->CanFreeMove()) + { + if (GetPlayer()->getStandState() == UNIT_STAND_STATE_STAND) + GetPlayer()->SetStandState(UNIT_STAND_STATE_SIT); + GetPlayer()->SetRooted(true); + GetPlayer()->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); + } + + SetLogoutStartTime(time(NULL)); +} + +void WorldSession::HandleLogoutCancelOpcode(WorldPackets::Character::LogoutCancel& /*logoutCancel*/) +{ + TC_LOG_DEBUG("network", "WORLD: Recvd CMSG_LOGOUT_CANCEL Message"); + + // Player have already logged out serverside, too late to cancel + if (!GetPlayer()) + return; + + SetLogoutStartTime(0); + + SendPacket(WorldPackets::Character::LogoutCancelAck().Write()); + + // not remove flags if can't free move - its not set in Logout request code. + if (GetPlayer()->CanFreeMove()) + { + //!we can move again + GetPlayer()->SetRooted(false); + + //! Stand Up + GetPlayer()->SetStandState(UNIT_STAND_STATE_STAND); + + //! DISABLE_ROTATE + GetPlayer()->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED); + } + + TC_LOG_DEBUG("network", "WORLD: Sent SMSG_LOGOUT_CANCEL_ACK Message"); +} + +void WorldSession::HandleTogglePvP(WorldPacket& recvData) +{ + // this opcode can be used in two ways: Either set explicit new status or toggle old status + if (recvData.size() == 1) + { + bool newPvPStatus; + recvData >> newPvPStatus; + GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP, newPvPStatus); + GetPlayer()->ApplyModFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER, !newPvPStatus); + } + else + { + GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP); + GetPlayer()->ToggleFlag(PLAYER_FLAGS, PLAYER_FLAGS_PVP_TIMER); + } + + if (GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_IN_PVP)) + { + if (!GetPlayer()->IsPvP() || GetPlayer()->pvpInfo.EndTimer) + GetPlayer()->UpdatePvP(true, true); + } + else + { + if (!GetPlayer()->pvpInfo.IsHostile && GetPlayer()->IsPvP()) + GetPlayer()->pvpInfo.EndTimer = time(NULL); // start toggle-off + } + + //if (OutdoorPvP* pvp = _player->GetOutdoorPvP()) + // pvp->HandlePlayerActivityChanged(_player); +} + +void WorldSession::HandleZoneUpdateOpcode(WorldPacket& recvData) +{ + uint32 newZone; + recvData >> newZone; + + TC_LOG_DEBUG("network", "WORLD: Recvd ZONE_UPDATE: %u", newZone); + + // use server side data, but only after update the player position. See Player::UpdatePosition(). + GetPlayer()->SetNeedsZoneUpdate(true); + + //GetPlayer()->SendInitWorldStates(true, newZone); +} + +void WorldSession::HandlePortGraveyard(WorldPackets::Misc::PortGraveyard& /*packet*/) +{ + if (GetPlayer()->IsAlive() || !GetPlayer()->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) + return; + GetPlayer()->RepopAtGraveyard(); +} + +void WorldSession::HandleRequestCemeteryList(WorldPackets::Misc::RequestCemeteryList& /*packet*/) +{ + uint32 zoneId = _player->GetZoneId(); + uint32 team = _player->GetTeam(); + + std::vector<uint32> graveyardIds; + auto range = sObjectMgr->GraveYardStore.equal_range(zoneId); + + for (auto it = range.first; it != range.second && graveyardIds.size() < 16; ++it) // client max + { + if (it->second.team == 0 || it->second.team == team) + graveyardIds.push_back(it->first); + } + + if (graveyardIds.empty()) + { + TC_LOG_DEBUG("network", "No graveyards found for zone %u for %s (team %u) in CMSG_REQUEST_CEMETERY_LIST", + zoneId, _player->GetGUID().ToString().c_str(), team); + return; + } + + WorldPackets::Misc::RequestCemeteryListResponse packet; + packet.IsGossipTriggered = false; + packet.CemeteryID.reserve(graveyardIds.size()); + + for (uint32 id : graveyardIds) + packet.CemeteryID.push_back(id); + + SendPacket(packet.Write()); +} + +void WorldSession::HandleSetSelectionOpcode(WorldPackets::Misc::SetSelection& packet) +{ + _player->SetSelection(packet.Selection); +} + +void WorldSession::HandleStandStateChangeOpcode(WorldPacket& recvData) +{ + // TC_LOG_DEBUG("network", "WORLD: Received CMSG_STANDSTATECHANGE"); -- too many spam in log at lags/debug stop + uint32 animstate; + recvData >> animstate; + + _player->SetStandState(animstate); +} + +void WorldSession::HandleContactListOpcode(WorldPacket& recvData) +{ + recvData.read_skip<uint32>(); // always 1 + TC_LOG_DEBUG("network", "WORLD: Received CMSG_CONTACT_LIST"); + _player->GetSocial()->SendSocialList(_player); +} + +void WorldSession::HandleAddFriendOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_ADD_FRIEND"); + + std::string friendName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); + std::string friendNote; + + recvData >> friendName; + + recvData >> friendNote; + + if (!normalizePlayerName(friendName)) + return; + + TC_LOG_DEBUG("network", "WORLD: %s asked to add friend : '%s'", + GetPlayer()->GetName().c_str(), friendName.c_str()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME); + + stmt->setString(0, friendName); + + _addFriendCallback.SetParam(friendNote); + _addFriendCallback.SetFutureResult(CharacterDatabase.AsyncQuery(stmt)); +} + +void WorldSession::HandleAddFriendOpcodeCallBack(PreparedQueryResult result, std::string const& friendNote) +{ + if (!GetPlayer()) + return; + + ObjectGuid friendGuid; + uint32 friendAccountId; + uint32 team; + FriendsResult friendResult; + + friendResult = FRIEND_NOT_FOUND; + + if (result) + { + Field* fields = result->Fetch(); + + friendGuid = ObjectGuid::Create<HighGuid::Player>(fields[0].GetUInt64()); + team = Player::TeamForRace(fields[1].GetUInt8()); + friendAccountId = fields[2].GetUInt32(); + + if (HasPermission(rbac::RBAC_PERM_ALLOW_GM_FRIEND) || AccountMgr::IsPlayerAccount(AccountMgr::GetSecurity(friendAccountId, realmHandle.Index))) + { + if (!friendGuid.IsEmpty()) + { + if (friendGuid == GetPlayer()->GetGUID()) + friendResult = FRIEND_SELF; + else if (GetPlayer()->GetTeam() != team && !HasPermission(rbac::RBAC_PERM_TWO_SIDE_ADD_FRIEND)) + friendResult = FRIEND_ENEMY; + else if (GetPlayer()->GetSocial()->HasFriend(friendGuid)) + friendResult = FRIEND_ALREADY; + else + { + Player* pFriend = ObjectAccessor::FindPlayer(friendGuid); + if (pFriend && pFriend->IsVisibleGloballyFor(GetPlayer())) + friendResult = FRIEND_ADDED_ONLINE; + else + friendResult = FRIEND_ADDED_OFFLINE; + if (!GetPlayer()->GetSocial()->AddToSocialList(friendGuid, false)) + { + friendResult = FRIEND_LIST_FULL; + TC_LOG_DEBUG("network", "WORLD: %s's friend list is full.", GetPlayer()->GetName().c_str()); + } + } + GetPlayer()->GetSocial()->SetFriendNote(friendGuid, friendNote); + } + } + } + + sSocialMgr->SendFriendStatus(GetPlayer(), friendResult, friendGuid, false); + + TC_LOG_DEBUG("network", "WORLD: Sent (SMSG_FRIEND_STATUS)"); +} + +void WorldSession::HandleDelFriendOpcode(WorldPacket& recvData) +{ + ObjectGuid FriendGUID; + + TC_LOG_DEBUG("network", "WORLD: Received CMSG_DEL_FRIEND"); + + recvData >> FriendGUID; + + _player->GetSocial()->RemoveFromSocialList(FriendGUID, false); + + sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_REMOVED, FriendGUID, false); + + TC_LOG_DEBUG("network", "WORLD: Sent motd (SMSG_FRIEND_STATUS)"); +} + +void WorldSession::HandleAddIgnoreOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_ADD_IGNORE"); + + std::string ignoreName = GetTrinityString(LANG_FRIEND_IGNORE_UNKNOWN); + + recvData >> ignoreName; + + if (!normalizePlayerName(ignoreName)) + return; + + TC_LOG_DEBUG("network", "WORLD: %s asked to Ignore: '%s'", + GetPlayer()->GetName().c_str(), ignoreName.c_str()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_BY_NAME); + + stmt->setString(0, ignoreName); + + _addIgnoreCallback = CharacterDatabase.AsyncQuery(stmt); +} + +void WorldSession::HandleAddIgnoreOpcodeCallBack(PreparedQueryResult result) +{ + if (!GetPlayer()) + return; + + ObjectGuid IgnoreGuid; + FriendsResult ignoreResult; + + ignoreResult = FRIEND_IGNORE_NOT_FOUND; + + if (result) + { + IgnoreGuid = ObjectGuid::Create<HighGuid::Player>((*result)[0].GetUInt64()); + + if (!IgnoreGuid.IsEmpty()) + { + if (IgnoreGuid == GetPlayer()->GetGUID()) //not add yourself + ignoreResult = FRIEND_IGNORE_SELF; + else if (GetPlayer()->GetSocial()->HasIgnore(IgnoreGuid)) + ignoreResult = FRIEND_IGNORE_ALREADY; + else + { + ignoreResult = FRIEND_IGNORE_ADDED; + + // ignore list full + if (!GetPlayer()->GetSocial()->AddToSocialList(IgnoreGuid, true)) + ignoreResult = FRIEND_IGNORE_FULL; + } + } + } + + sSocialMgr->SendFriendStatus(GetPlayer(), ignoreResult, IgnoreGuid, false); + + TC_LOG_DEBUG("network", "WORLD: Sent (SMSG_FRIEND_STATUS)"); +} + +void WorldSession::HandleDelIgnoreOpcode(WorldPacket& recvData) +{ + ObjectGuid IgnoreGUID; + + TC_LOG_DEBUG("network", "WORLD: Received CMSG_DEL_IGNORE"); + + recvData >> IgnoreGUID; + + _player->GetSocial()->RemoveFromSocialList(IgnoreGUID, true); + + sSocialMgr->SendFriendStatus(GetPlayer(), FRIEND_IGNORE_REMOVED, IgnoreGUID, false); + + TC_LOG_DEBUG("network", "WORLD: Sent motd (SMSG_FRIEND_STATUS)"); +} + +void WorldSession::HandleSetContactNotesOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "CMSG_SET_CONTACT_NOTES"); + ObjectGuid guid; + std::string note; + recvData >> guid >> note; + _player->GetSocial()->SetFriendNote(guid, note); +} + +void WorldSession::HandleBugReportOpcode(WorldPacket& recvData) +{ + uint32 suggestion, contentlen, typelen; + std::string content, type; + + recvData >> suggestion >> contentlen; + content = recvData.ReadString(contentlen); + + recvData >> typelen; + type = recvData.ReadString(typelen); + + if (suggestion == 0) + TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUG_REPORT [Bug Report]"); + else + TC_LOG_DEBUG("network", "WORLD: Received CMSG_BUG_REPORT [Suggestion]"); + + TC_LOG_DEBUG("network", "%s", type.c_str()); + TC_LOG_DEBUG("network", "%s", content.c_str()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_BUG_REPORT); + + stmt->setString(0, type); + stmt->setString(1, content); + + CharacterDatabase.Execute(stmt); +} + +void WorldSession::HandleReclaimCorpse(WorldPackets::Misc::ReclaimCorpse& packet) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_RECLAIM_CORPSE"); + + if (_player->IsAlive()) + return; + + // do not allow corpse reclaim in arena + if (_player->InArena()) + return; + + // body not released yet + if (!_player->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_GHOST)) + return; + + Corpse* corpse = _player->GetCorpse(); + + if (!corpse) + return; + + // prevent resurrect before 30-sec delay after body release not finished + if (time_t(corpse->GetGhostTime() + _player->GetCorpseReclaimDelay(corpse->GetType() == CORPSE_RESURRECTABLE_PVP)) > time_t(time(NULL))) + return; + + if (!corpse->IsWithinDistInMap(_player, CORPSE_RECLAIM_RADIUS, true)) + return; + + // resurrect + _player->ResurrectPlayer(_player->InBattleground() ? 1.0f : 0.5f); + + // spawn bones + _player->SpawnCorpseBones(); +} + +void WorldSession::HandleResurrectResponse(WorldPackets::Misc::ResurrectResponse& packet) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_RESURRECT_RESPONSE"); + + if (GetPlayer()->IsAlive()) + return; + + if (packet.Response == 0) + { + GetPlayer()->ClearResurrectRequestData(); // reject + return; + } + + if (!GetPlayer()->IsResurrectRequestedBy(packet.Resurrecter)) + return; + + GetPlayer()->ResurrectUsingRequestData(); +} + +void WorldSession::SendAreaTriggerMessage(const char* Text, ...) +{ + va_list ap; + char szStr [1024]; + szStr[0] = '\0'; + + va_start(ap, Text); + vsnprintf(szStr, 1024, Text, ap); + va_end(ap); + + uint32 length = strlen(szStr)+1; + WorldPacket data(SMSG_AREA_TRIGGER_MESSAGE, 4+length); + data << length; + data << szStr; + SendPacket(&data); +} + +void WorldSession::HandleAreaTriggerOpcode(WorldPackets::Misc::AreaTrigger& packet) +{ + TC_LOG_DEBUG("network", "CMSG_AREATRIGGER. Trigger ID: %u", packet.AreaTriggerID); + + Player* player = GetPlayer(); + if (player->IsInFlight()) + { + TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) in flight, ignore Area Trigger ID:%u", + player->GetName().c_str(), player->GetGUID().ToString().c_str(), packet.AreaTriggerID); + return; + } + + AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(packet.AreaTriggerID); + if (!atEntry) + { + TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) send unknown (by DBC) Area Trigger ID:%u", + player->GetName().c_str(), player->GetGUID().ToString().c_str(), packet.AreaTriggerID); + return; + } + + if (player->GetMapId() != atEntry->MapID) + { + TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (trigger map: %u player map: %u), ignore Area Trigger ID: %u", + player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->MapID, player->GetMapId(), packet.AreaTriggerID); + return; + } + + // delta is safe radius + const float delta = 5.0f; + + if (atEntry->Radius > 0) + { + // if we have radius check it + float dist = player->GetDistance(atEntry->Pos.X, atEntry->Pos.Y, atEntry->Pos.Z); + if (dist > atEntry->Radius + delta) + { + TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (radius: %f distance: %f), ignore Area Trigger ID: %u", + player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->Radius, dist, packet.AreaTriggerID); + return; + } + } + else + { + // we have only extent + + // rotate the players position instead of rotating the whole cube, that way we can make a simplified + // is-in-cube check and we have to calculate only one point instead of 4 + + // 2PI = 360°, keep in mind that ingame orientation is counter-clockwise + double rotation = 2 * M_PI - atEntry->BoxYaw; + double sinVal = std::sin(rotation); + double cosVal = std::cos(rotation); + + float playerBoxDistX = player->GetPositionX() - atEntry->Pos.X; + float playerBoxDistY = player->GetPositionY() - atEntry->Pos.Y; + + float rotPlayerX = float(atEntry->Pos.X + playerBoxDistX * cosVal - playerBoxDistY*sinVal); + float rotPlayerY = float(atEntry->Pos.Y + playerBoxDistY * cosVal + playerBoxDistX*sinVal); + + // box edges are parallel to coordiante axis, so we can treat every dimension independently :D + float dz = player->GetPositionZ() - atEntry->Pos.Z; + float dx = rotPlayerX - atEntry->Pos.X; + float dy = rotPlayerY - atEntry->Pos.Y; + if ((std::fabs(dx) > atEntry->BoxLength / 2 + delta) || + (std::fabs(dy) > atEntry->BoxWidth / 2 + delta) || + (std::fabs(dz) > atEntry->BoxHeight / 2 + delta)) + { + TC_LOG_DEBUG("network", "HandleAreaTriggerOpcode: Player '%s' (%s) too far (1/2 box X: %f 1/2 box Y: %f 1/2 box Z: %f rotatedPlayerX: %f rotatedPlayerY: %f dZ:%f), ignore Area Trigger ID: %u", + player->GetName().c_str(), player->GetGUID().ToString().c_str(), atEntry->BoxLength / 2, atEntry->BoxWidth / 2, atEntry->BoxHeight / 2, rotPlayerX, rotPlayerY, dz, packet.AreaTriggerID); + return; + } + } + + if (player->isDebugAreaTriggers) + ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_REACHED, packet.AreaTriggerID); + + if (sScriptMgr->OnAreaTrigger(player, atEntry)) + return; + + if (player->IsAlive()) + { + if (uint32 questId = sObjectMgr->GetQuestForAreaTrigger(packet.AreaTriggerID)) + { + Quest const* qInfo = sObjectMgr->GetQuestTemplate(questId); + if (qInfo && player->GetQuestStatus(questId) == QUEST_STATUS_INCOMPLETE) + { + for (uint8 j = 0; j < qInfo->Objectives.size(); ++j) + { + if (qInfo->Objectives[j].Type == QUEST_OBJECTIVE_AREATRIGGER) + { + player->SetQuestObjectiveData(qInfo, j, int32(true)); + break; + } + } + + if (player->CanCompleteQuest(questId)) + player->CompleteQuest(questId); + } + } + } + + if (sObjectMgr->IsTavernAreaTrigger(packet.AreaTriggerID)) + { + // set resting flag we are in the inn + player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING); + player->InnEnter(time(NULL), atEntry->MapID, atEntry->Pos.X, atEntry->Pos.Y, atEntry->Pos.Z); + player->SetRestType(REST_TYPE_IN_TAVERN); + + if (sWorld->IsFFAPvPRealm()) + player->RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_FFA_PVP); + + return; + } + + if (Battleground* bg = player->GetBattleground()) + if (bg->GetStatus() == STATUS_IN_PROGRESS) + bg->HandleAreaTrigger(player, packet.AreaTriggerID); + + if (OutdoorPvP* pvp = player->GetOutdoorPvP()) + if (pvp->HandleAreaTrigger(_player, packet.AreaTriggerID)) + return; + + AreaTriggerStruct const* at = sObjectMgr->GetAreaTrigger(packet.AreaTriggerID); + if (!at) + return; + + bool teleported = false; + if (player->GetMapId() != at->target_mapId) + { + if (!sMapMgr->CanPlayerEnter(at->target_mapId, player, false)) + return; + + if (Group* group = player->GetGroup()) + if (group->isLFGGroup() && player->GetMap()->IsDungeon()) + teleported = player->TeleportToBGEntryPoint(); + } + + if (!teleported) + player->TeleportTo(at->target_mapId, at->target_X, at->target_Y, at->target_Z, at->target_Orientation, TELE_TO_NOT_LEAVE_TRANSPORT); +} + +void WorldSession::HandleUpdateAccountData(WorldPackets::ClientConfig::UserClientUpdateAccountData& packet) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_UPDATE_ACCOUNT_DATA: type %u, time %u, decompressedSize %u", + packet.DataType, packet.Time, packet.Size); + + if (packet.DataType > NUM_ACCOUNT_DATA_TYPES) + return; + + if (packet.Size == 0) // erase + { + SetAccountData(AccountDataType(packet.DataType), 0, ""); + return; + } + + if (packet.Size > 0xFFFF) + { + TC_LOG_ERROR("network", "UAD: Account data packet too big, size %u", packet.Size); + return; + } + + ByteBuffer dest; + dest.resize(packet.Size); + + uLongf realSize = packet.Size; + if (uncompress(dest.contents(), &realSize, packet.CompressedData.contents(), packet.CompressedData.size()) != Z_OK) + { + TC_LOG_ERROR("network", "UAD: Failed to decompress account data"); + return; + } + + std::string adata; + dest >> adata; + + SetAccountData(AccountDataType(packet.DataType), packet.Time, adata); +} + +void WorldSession::HandleRequestAccountData(WorldPackets::ClientConfig::RequestAccountData& request) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_REQUEST_ACCOUNT_DATA: type %u", request.DataType); + + if (request.DataType >= NUM_ACCOUNT_DATA_TYPES) + return; + + AccountData const* adata = GetAccountData(AccountDataType(request.DataType)); + + WorldPackets::ClientConfig::UpdateAccountData data; + data.Player = _player ? _player->GetGUID() : ObjectGuid::Empty; + data.Time = adata->Time; + data.Size = adata->Data.size(); + data.DataType = request.DataType; + + uLongf destSize = compressBound(data.Size); + + data.CompressedData.resize(destSize); + + if (data.Size && compress(data.CompressedData.contents(), &destSize, (uint8 const*)adata->Data.c_str(), data.Size) != Z_OK) + { + TC_LOG_ERROR("network", "RAD: Failed to compress account data"); + return; + } + + data.CompressedData.resize(destSize); + + SendPacket(data.Write()); +} + +int32 WorldSession::HandleEnableNagleAlgorithm() +{ + // Instructs the server we wish to receive few amounts of large packets (SMSG_MULTIPLE_PACKETS?) + // instead of large amount of small packets + return 0; +} + +void WorldSession::HandleSetActionButtonOpcode(WorldPackets::Spells::SetActionButton& packet) +{ + uint32 action = ACTION_BUTTON_ACTION(packet.Action); + uint32 type = ACTION_BUTTON_TYPE(packet.Action); + + TC_LOG_DEBUG("network", "CMSG_SET_ACTION_BUTTON Button: %u Action: %u Type: %u", packet.Index, action, type); + + if (!packet.Action) + GetPlayer()->RemoveActionButton(packet.Index); + else + GetPlayer()->AddActionButton(packet.Index, action, type); +} + +void WorldSession::HandleCompleteCinematic(WorldPacket& /*recvData*/) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_COMPLETE_CINEMATIC"); +} + +void WorldSession::HandleNextCinematicCamera(WorldPacket& /*recvData*/) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_NEXT_CINEMATIC_CAMERA"); +} + +void WorldSession::HandleMoveTimeSkippedOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: Received CMSG_MOVE_TIME_SKIPPED"); + + ObjectGuid guid; + uint32 time; + recvData >> time; + + guid[5] = recvData.ReadBit(); + guid[1] = recvData.ReadBit(); + guid[3] = recvData.ReadBit(); + guid[7] = recvData.ReadBit(); + guid[6] = recvData.ReadBit(); + guid[0] = recvData.ReadBit(); + guid[4] = recvData.ReadBit(); + guid[2] = recvData.ReadBit(); + + recvData.ReadByteSeq(guid[7]); + recvData.ReadByteSeq(guid[1]); + recvData.ReadByteSeq(guid[2]); + recvData.ReadByteSeq(guid[4]); + recvData.ReadByteSeq(guid[3]); + recvData.ReadByteSeq(guid[6]); + recvData.ReadByteSeq(guid[0]); + recvData.ReadByteSeq(guid[5]); + + //TODO! + + /* + uint64 guid; + uint32 time_skipped; + recvData >> guid; + recvData >> time_skipped; + TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_TIME_SKIPPED"); + + //// @todo + must be need use in Trinity + We substract server Lags to move time (AntiLags) + for exmaple + GetPlayer()->ModifyLastMoveTime(-int32(time_skipped)); + */ +} + +void WorldSession::HandleFeatherFallAck(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FEATHER_FALL_ACK"); + + // no used + recvData.rfinish(); // prevent warnings spam +} + +void WorldSession::HandleMoveUnRootAck(WorldPacket& recvData) +{ + // no used + recvData.rfinish(); // prevent warnings spam +/* + uint64 guid; + recvData >> guid; + + // now can skip not our packet + if (_player->GetGUID() != guid) + { + recvData.rfinish(); // prevent warnings spam + return; + } + + TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FORCE_UNROOT_ACK"); + + recvData.read_skip<uint32>(); // unk + + MovementInfo movementInfo; + movementInfo.guid = guid; + ReadMovementInfo(recvData, &movementInfo); + recvData.read_skip<float>(); // unk2 +*/ +} + +void WorldSession::HandleMoveRootAck(WorldPacket& recvData) +{ + // no used + recvData.rfinish(); // prevent warnings spam +/* + uint64 guid; + recvData >> guid; + + // now can skip not our packet + if (_player->GetGUID() != guid) + { + recvData.rfinish(); // prevent warnings spam + return; + } + + TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_FORCE_ROOT_ACK"); + + recvData.read_skip<uint32>(); // unk + + MovementInfo movementInfo; + ReadMovementInfo(recvData, &movementInfo); +*/ +} + +void WorldSession::HandleSetActionBarToggles(WorldPacket& recvData) +{ + uint8 actionBar; + recvData >> actionBar; + + if (!GetPlayer()) // ignore until not logged (check needed because STATUS_AUTHED) + { + if (actionBar != 0) + TC_LOG_ERROR("network", "WorldSession::HandleSetActionBarToggles in not logged state with value: %u, ignored", uint32(actionBar)); + return; + } + + GetPlayer()->SetByteValue(PLAYER_FIELD_BYTES, 2, actionBar); +} + +void WorldSession::HandlePlayedTime(WorldPacket& recvData) +{ + uint8 unk1; + recvData >> unk1; // 0 or 1 expected + + WorldPacket data(SMSG_PLAYED_TIME, 4 + 4 + 1); + data << uint32(_player->GetTotalPlayedTime()); + data << uint32(_player->GetLevelPlayedTime()); + data << uint8(unk1); // 0 - will not show in chat frame + SendPacket(&data); +} + +void WorldSession::HandleInspectOpcode(WorldPacket& recvData) +{ + ObjectGuid guid; + recvData >> guid; + + TC_LOG_DEBUG("network", "WORLD: Received CMSG_INSPECT"); + + Player* player = ObjectAccessor::FindPlayer(guid); + if (!player) + { + TC_LOG_DEBUG("network", "CMSG_INSPECT: No player found from %s", guid.ToString().c_str()); + return; + } + + if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false)) + return; + + if (GetPlayer()->IsValidAttackTarget(player)) + return; + + uint32 talent_points = 41; + WorldPacket data(SMSG_INSPECT_TALENT, 8 + 4 + 1 + 1 + talent_points + 8 + 4 + 8 + 4); + data << player->GetGUID(); + + /* TODO: 6.x update packet structure (BuildPlayerTalentsInfoData no longer exists) + if (sWorld->getBoolConfig(CONFIG_TALENTS_INSPECTING) || _player->IsGameMaster()) + player->BuildPlayerTalentsInfoData(&data); + else + { + data << uint32(0); // unspentTalentPoints + data << uint8(0); // talentGroupCount + data << uint8(0); // talentGroupIndex + } + */ + + player->BuildEnchantmentsInfoData(&data); + if (Guild* guild = sGuildMgr->GetGuildById(player->GetGuildId())) + { + data << guild->GetGUID(); + data << uint32(guild->GetLevel()); + data << uint64(guild->GetExperience()); + data << uint32(guild->GetMembersCount()); + } + SendPacket(&data); +} + +void WorldSession::HandleInspectHonorStatsOpcode(WorldPacket& recvData) +{ + ObjectGuid guid; + guid[1] = recvData.ReadBit(); + guid[5] = recvData.ReadBit(); + guid[7] = recvData.ReadBit(); + guid[3] = recvData.ReadBit(); + guid[2] = recvData.ReadBit(); + guid[4] = recvData.ReadBit(); + guid[0] = recvData.ReadBit(); + guid[6] = recvData.ReadBit(); + + recvData.ReadByteSeq(guid[4]); + recvData.ReadByteSeq(guid[7]); + recvData.ReadByteSeq(guid[0]); + recvData.ReadByteSeq(guid[5]); + recvData.ReadByteSeq(guid[1]); + recvData.ReadByteSeq(guid[6]); + recvData.ReadByteSeq(guid[2]); + recvData.ReadByteSeq(guid[3]); + Player* player = ObjectAccessor::FindPlayer(guid); + if (!player) + { + TC_LOG_DEBUG("network", "CMSG_INSPECT_HONOR_STATS: No player found from %s", guid.ToString().c_str()); + return; + } + + if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false)) + return; + + if (GetPlayer()->IsValidAttackTarget(player)) + return; + + ObjectGuid playerGuid = player->GetGUID(); + WorldPacket data(SMSG_INSPECT_HONOR_STATS, 8+1+4+4); + data.WriteBit(playerGuid[4]); + data.WriteBit(playerGuid[3]); + data.WriteBit(playerGuid[6]); + data.WriteBit(playerGuid[2]); + data.WriteBit(playerGuid[5]); + data.WriteBit(playerGuid[0]); + data.WriteBit(playerGuid[7]); + data.WriteBit(playerGuid[1]); + data << uint8(0); // rank + data << uint16(player->GetUInt16Value(PLAYER_FIELD_KILLS, 1)); // yesterday kills + data << uint16(player->GetUInt16Value(PLAYER_FIELD_KILLS, 0)); // today kills + data.WriteByteSeq(playerGuid[2]); + data.WriteByteSeq(playerGuid[0]); + data.WriteByteSeq(playerGuid[6]); + data.WriteByteSeq(playerGuid[3]); + data.WriteByteSeq(playerGuid[4]); + data.WriteByteSeq(playerGuid[1]); + data.WriteByteSeq(playerGuid[5]); + data << uint32(player->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS)); + data.WriteByteSeq(playerGuid[7]); + SendPacket(&data); +} + +void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recvData) +{ + uint32 time; + uint32 mapid; + float PositionX; + float PositionY; + float PositionZ; + float Orientation; + + recvData >> time; // time in m.sec. + recvData >> mapid; + recvData >> PositionX; + recvData >> PositionY; + recvData >> PositionZ; + recvData >> Orientation; // o (3.141593 = 180 degrees) + + TC_LOG_DEBUG("network", "WORLD: Received CMSG_WORLD_TELEPORT"); + + if (GetPlayer()->IsInFlight()) + { + TC_LOG_DEBUG("network", "Player '%s' (%s) in flight, ignore worldport command.", + GetPlayer()->GetName().c_str(), GetPlayer()->GetGUID().ToString().c_str()); + return; + } + + TC_LOG_DEBUG("network", "CMSG_WORLD_TELEPORT: Player = %s, Time = %u, map = %u, x = %f, y = %f, z = %f, o = %f", + GetPlayer()->GetName().c_str(), time, mapid, PositionX, PositionY, PositionZ, Orientation); + + if (HasPermission(rbac::RBAC_PERM_OPCODE_WORLD_TELEPORT)) + GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation); + else + SendNotification(LANG_YOU_NOT_HAVE_PERMISSION); +} + +void WorldSession::HandleWhoisOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "Received opcode CMSG_WHOIS"); + std::string charname; + recvData >> charname; + + if (!HasPermission(rbac::RBAC_PERM_OPCODE_WHOIS)) + { + SendNotification(LANG_YOU_NOT_HAVE_PERMISSION); + return; + } + + if (charname.empty() || !normalizePlayerName (charname)) + { + SendNotification(LANG_NEED_CHARACTER_NAME); + return; + } + + Player* player = ObjectAccessor::FindConnectedPlayerByName(charname); + + if (!player) + { + SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str()); + return; + } + + uint32 accid = player->GetSession()->GetAccountId(); + + PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_ACCOUNT_WHOIS); + + stmt->setUInt32(0, accid); + + PreparedQueryResult result = LoginDatabase.Query(stmt); + + if (!result) + { + SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str()); + return; + } + + Field* fields = result->Fetch(); + std::string acc = fields[0].GetString(); + if (acc.empty()) + acc = "Unknown"; + std::string email = fields[1].GetString(); + if (email.empty()) + email = "Unknown"; + std::string lastip = fields[2].GetString(); + if (lastip.empty()) + lastip = "Unknown"; + + std::string msg = charname + "'s " + "account is " + acc + ", e-mail: " + email + ", last ip: " + lastip; + + WorldPacket data(SMSG_WHOIS, msg.size()+1); + data << msg; + SendPacket(&data); + + TC_LOG_DEBUG("network", "Received whois command from player %s for character %s", + GetPlayer()->GetName().c_str(), charname.c_str()); +} + +void WorldSession::HandleComplainOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_COMPLAIN"); + + uint8 spam_type; // 0 - mail, 1 - chat + ObjectGuid spammer_guid; + uint32 unk1 = 0; + uint32 unk2 = 0; + uint32 unk3 = 0; + uint32 unk4 = 0; + std::string description = ""; + recvData >> spam_type; // unk 0x01 const, may be spam type (mail/chat) + recvData >> spammer_guid; // player guid + switch (spam_type) + { + case 0: + recvData >> unk1; // const 0 + recvData >> unk2; // probably mail id + recvData >> unk3; // const 0 + break; + case 1: + recvData >> unk1; // probably language + recvData >> unk2; // message type? + recvData >> unk3; // probably channel id + recvData >> unk4; // time + recvData >> description; // spam description string (messagetype, channel name, player name, message) + break; + } + + // NOTE: all chat messages from this spammer automatically ignored by spam reporter until logout in case chat spam. + // if it's mail spam - ALL mails from this spammer automatically removed by client + + // Complaint Received message + WorldPacket data(SMSG_COMPLAIN_RESULT, 2); + data << uint8(0); // value 1 resets CGChat::m_complaintsSystemStatus in client. (unused?) + data << uint8(0); // value 0xC generates a "CalendarError" in client. + SendPacket(&data); + + TC_LOG_DEBUG("network", "REPORT SPAM: type %u, %s, unk1 %u, unk2 %u, unk3 %u, unk4 %u, message %s", + spam_type, spammer_guid.ToString().c_str(), unk1, unk2, unk3, unk4, description.c_str()); +} + +void WorldSession::HandleRealmSplitOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "CMSG_REALM_SPLIT"); + + uint32 unk; + std::string split_date = "01/01/01"; + recvData >> unk; + + WorldPacket data(SMSG_REALM_SPLIT, 4+4+split_date.size()+1); + data << unk; + data << uint32(0x00000000); // realm split state + // split states: + // 0x0 realm normal + // 0x1 realm split + // 0x2 realm split pending + data << split_date; + SendPacket(&data); + //TC_LOG_DEBUG("response sent %u", unk); +} + +void WorldSession::HandleFarSightOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_FAR_SIGHT"); + + bool apply; + recvData >> apply; + + if (apply) + { + TC_LOG_DEBUG("network", "Added FarSight %s to %s", _player->GetGuidValue(PLAYER_FARSIGHT).ToString().c_str(), _player->GetGUID().ToString().c_str()); + if (WorldObject* target = _player->GetViewpoint()) + _player->SetSeer(target); + else + TC_LOG_ERROR("network", "Player %s (%s) requests non-existing seer %s", _player->GetName().c_str(), _player->GetGUID().ToString().c_str(), _player->GetGuidValue(PLAYER_FARSIGHT).ToString().c_str()); + } + else + { + TC_LOG_DEBUG("network", "%s set vision to self", _player->GetGUID().ToString().c_str()); + _player->SetSeer(_player); + } + + GetPlayer()->UpdateVisibilityForPlayer(); +} + +void WorldSession::HandleSetTitleOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "CMSG_SET_TITLE"); + + int32 title; + recvData >> title; + + // -1 at none + if (title > 0 && title < MAX_TITLE_INDEX) + { + if (!GetPlayer()->HasTitle(title)) + return; + } + else + title = 0; + + GetPlayer()->SetUInt32Value(PLAYER_CHOSEN_TITLE, title); +} + +void WorldSession::HandleTimeSyncResponse(WorldPackets::Misc::TimeSyncResponse& packet) +{ + TC_LOG_DEBUG("network", "CMSG_TIME_SYNC_RESPONSE"); + + // Prevent crashing server if queue is empty + if (_player->m_timeSyncQueue.empty()) + { + TC_LOG_ERROR("network", "Received CMSG_TIME_SYNC_RESPONSE from player %s without requesting it (hacker?)", _player->GetName().c_str()); + return; + } + + if (packet.SequenceIndex != _player->m_timeSyncQueue.front()) + TC_LOG_ERROR("network", "Wrong time sync counter from player %s (cheater?)", _player->GetName().c_str()); + + TC_LOG_DEBUG("network", "Time sync received: counter %u, client ticks %u, time since last sync %u", packet.SequenceIndex, packet.ClientTime, packet.ClientTime - _player->m_timeSyncClient); + + uint32 ourTicks = packet.ClientTime + (getMSTime() - _player->m_timeSyncServer); + + // diff should be small + TC_LOG_DEBUG("network", "Our ticks: %u, diff %u, latency %u", ourTicks, ourTicks - packet.ClientTime, GetLatency()); + + _player->m_timeSyncClient = packet.ClientTime; + _player->m_timeSyncQueue.pop(); +} + +void WorldSession::HandleResetInstancesOpcode(WorldPacket& /*recvData*/) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_RESET_INSTANCES"); + + if (Group* group = _player->GetGroup()) + { + if (group->IsLeader(_player->GetGUID())) + group->ResetInstances(INSTANCE_RESET_ALL, false, false, _player); + } + else + _player->ResetInstances(INSTANCE_RESET_ALL, false, false); +} + +void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPackets::Misc::SetDungeonDifficulty& setDungeonDifficulty) +{ + DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(setDungeonDifficulty.DifficultyID); + if (!difficultyEntry) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an invalid instance mode %d!", + _player->GetGUID().ToString().c_str(), setDungeonDifficulty.DifficultyID); + return; + } + + if (difficultyEntry->InstanceType != MAP_INSTANCE) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an non-dungeon instance mode %d!", + _player->GetGUID().ToString().c_str(), difficultyEntry->ID); + return; + } + + if (!(difficultyEntry->Flags & DIFFICULTY_FLAG_CAN_SELECT)) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent unselectable instance mode %d!", + _player->GetGUID().ToString().c_str(), difficultyEntry->ID); + return; + } + + Difficulty difficultyID = Difficulty(difficultyEntry->ID); + if (difficultyID == _player->GetDungeonDifficultyID()) + return; + + // cannot reset while in an instance + Map* map = _player->FindMap(); + if (map && map->IsDungeon()) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: player (Name: %s, %s) tried to reset the instance while player is inside!", + _player->GetName().c_str(), _player->GetGUID().ToString().c_str()); + return; + } + + Group* group = _player->GetGroup(); + if (group) + { + if (group->IsLeader(_player->GetGUID())) + { + for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) + { + Player* groupGuy = itr->GetSource(); + if (!groupGuy) + continue; + + if (!groupGuy->IsInMap(groupGuy)) + return; + + if (groupGuy->GetMap()->IsNonRaidDungeon()) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s tried to reset the instance while group member (Name: %s, %s) is inside!", + _player->GetGUID().ToString().c_str(), groupGuy->GetName().c_str(), groupGuy->GetGUID().ToString().c_str()); + return; + } + } + // the difficulty is set even if the instances can't be reset + //_player->SendDungeonDifficulty(true); + group->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, false, _player); + group->SetDungeonDifficultyID(difficultyID); + } + } + else + { + _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, false, false); + _player->SetDungeonDifficultyID(difficultyID); + _player->SendDungeonDifficulty(); + } +} + +void WorldSession::HandleSetRaidDifficultyOpcode(WorldPackets::Misc::SetRaidDifficulty& setRaidDifficulty) +{ + DifficultyEntry const* difficultyEntry = sDifficultyStore.LookupEntry(setRaidDifficulty.DifficultyID); + if (!difficultyEntry) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an invalid instance mode %u!", + _player->GetGUID().ToString().c_str(), setRaidDifficulty.DifficultyID); + return; + } + + if (difficultyEntry->InstanceType != MAP_RAID) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent an non-dungeon instance mode %u!", + _player->GetGUID().ToString().c_str(), difficultyEntry->ID); + return; + } + + if (!(difficultyEntry->Flags & DIFFICULTY_FLAG_CAN_SELECT)) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent unselectable instance mode %u!", + _player->GetGUID().ToString().c_str(), difficultyEntry->ID); + return; + } + + if (((difficultyEntry->Flags & DIFFICULTY_FLAG_LEGACY) >> 5) != setRaidDifficulty.Legacy) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetDungeonDifficultyOpcode: %s sent not matching legacy difficulty %u!", + _player->GetGUID().ToString().c_str(), difficultyEntry->ID); + return; + } + + Difficulty difficultyID = Difficulty(difficultyEntry->ID); + if (difficultyID == (setRaidDifficulty.Legacy ? _player->GetLegacyRaidDifficultyID() : _player->GetRaidDifficultyID())) + return; + + // cannot reset while in an instance + Map* map = _player->FindMap(); + if (map && map->IsDungeon()) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetRaidDifficultyOpcode: player (Name: %s, %s) tried to reset the instance while player is inside!", + _player->GetName().c_str(), _player->GetGUID().ToString().c_str()); + return; + } + + Group* group = _player->GetGroup(); + if (group) + { + if (group->IsLeader(_player->GetGUID())) + { + for (GroupReference* itr = group->GetFirstMember(); itr != NULL; itr = itr->next()) + { + Player* groupGuy = itr->GetSource(); + if (!groupGuy) + continue; + + if (!groupGuy->IsInMap(groupGuy)) + return; + + if (groupGuy->GetMap()->IsRaid()) + { + TC_LOG_DEBUG("network", "WorldSession::HandleSetRaidDifficultyOpcode: %s tried to reset the instance while group member (Name: %s, %s) is inside!", + _player->GetGUID().ToString().c_str(), groupGuy->GetName().c_str(), groupGuy->GetGUID().ToString().c_str()); + return; + } + } + // the difficulty is set even if the instances can't be reset + group->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, setRaidDifficulty.Legacy != 0, _player); + if (setRaidDifficulty.Legacy) + group->SetLegacyRaidDifficultyID(difficultyID); + else + group->SetRaidDifficultyID(difficultyID); + } + } + else + { + _player->ResetInstances(INSTANCE_RESET_CHANGE_DIFFICULTY, true, setRaidDifficulty.Legacy != 0); + if (setRaidDifficulty.Legacy) + _player->SetLegacyRaidDifficultyID(difficultyID); + else + _player->SetRaidDifficultyID(difficultyID); + + _player->SendRaidDifficulty(setRaidDifficulty.Legacy != 0); + } +} + +void WorldSession::HandleCancelMountAuraOpcode(WorldPacket& /*recvData*/) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_CANCEL_MOUNT_AURA"); + + //If player is not mounted, so go out :) + if (!_player->IsMounted()) // not blizz like; no any messages on blizz + { + ChatHandler(this).SendSysMessage(LANG_CHAR_NON_MOUNTED); + return; + } + + if (_player->IsInFlight()) // not blizz like; no any messages on blizz + { + ChatHandler(this).SendSysMessage(LANG_YOU_IN_FLIGHT); + return; + } + + _player->RemoveAurasByType(SPELL_AURA_MOUNTED); // Calls Dismount() +} + +void WorldSession::HandleMoveSetCanFlyAckOpcode(WorldPacket& recvData) +{ + // fly mode on/off + TC_LOG_DEBUG("network", "WORLD: CMSG_MOVE_SET_CAN_FLY_ACK"); + + MovementInfo movementInfo; + _player->ReadMovementInfo(recvData, &movementInfo); + + _player->m_mover->m_movementInfo.flags = movementInfo.GetMovementFlags(); +} + +void WorldSession::HandleRequestPetInfoOpcode(WorldPacket& /*recvData */) +{ + /* + TC_LOG_DEBUG("network", "WORLD: CMSG_REQUEST_PET_INFO"); + recvData.hexlike(); + */ +} + +void WorldSession::HandleSetTaxiBenchmarkOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_SET_TAXI_BENCHMARK_MODE"); + + uint8 mode; + recvData >> mode; + + mode ? _player->SetFlag(PLAYER_FLAGS, PLAYER_FLAGS_TAXI_BENCHMARK) : _player->RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_TAXI_BENCHMARK); + + TC_LOG_DEBUG("network", "Client used \"/timetest %d\" command", mode); +} + +void WorldSession::HandleQueryInspectAchievements(WorldPacket& recvData) +{ + ObjectGuid guid; + recvData >> guid.ReadAsPacked(); + + TC_LOG_DEBUG("network", "CMSG_QUERY_INSPECT_ACHIEVEMENTS [%s] Inspected Player [%s]", _player->GetGUID().ToString().c_str(), guid.ToString().c_str()); + Player* player = ObjectAccessor::FindPlayer(guid); + if (!player) + return; + + if (!GetPlayer()->IsWithinDistInMap(player, INSPECT_DISTANCE, false)) + return; + + if (GetPlayer()->IsValidAttackTarget(player)) + return; + + player->SendRespondInspectAchievements(_player); +} + +void WorldSession::HandleGuildSetFocusedAchievement(WorldPackets::Achievement::GuildSetFocusedAchievement& setFocusedAchievement) +{ + if (Guild* guild = sGuildMgr->GetGuildById(_player->GetGuildId())) + guild->GetAchievementMgr().SendAchievementInfo(_player, setFocusedAchievement.AchievementID); +} + +void WorldSession::HandleWorldStateUITimerUpdate(WorldPacket& /*recvData*/) +{ + // empty opcode + TC_LOG_DEBUG("network", "WORLD: CMSG_WORLD_STATE_UI_TIMER_UPDATE"); + + WorldPackets::Misc::UITime response; + response.Time = time(NULL); + SendPacket(response.Write()); +} + +void WorldSession::SendSetPhaseShift(std::set<uint32> const& phaseIds, std::set<uint32> const& terrainswaps, std::set<uint32> const& worldMapAreaSwaps) +{ + ObjectGuid guid = _player->GetGUID(); + + WorldPacket data(SMSG_SET_PHASE_SHIFT, 1 + 8 + 4 + 4 + 4 + 4 + 2 * phaseIds.size() + 4 + terrainswaps.size() * 2); + data.WriteBit(guid[2]); + data.WriteBit(guid[3]); + data.WriteBit(guid[1]); + data.WriteBit(guid[6]); + data.WriteBit(guid[4]); + data.WriteBit(guid[5]); + data.WriteBit(guid[0]); + data.WriteBit(guid[7]); + + data.WriteByteSeq(guid[7]); + data.WriteByteSeq(guid[4]); + + data << uint32(worldMapAreaSwaps.size()); + for (auto mapSwap : worldMapAreaSwaps) + data << uint16(mapSwap); // WorldMapArea.dbc id (controls map display) + + data.WriteByteSeq(guid[1]); + + data << uint32(phaseIds.size() ? 0 : 8); // flags (not phasemask) + + data.WriteByteSeq(guid[2]); + data.WriteByteSeq(guid[6]); + + data << uint32(0); // Inactive terrain swaps + //for (uint8 i = 0; i < inactiveSwapsCount; ++i) + // data << uint16(0); + + data << uint32(phaseIds.size()) * 2; // Phase.dbc ids + for (std::set<uint32>::const_iterator itr = phaseIds.begin(); itr != phaseIds.end(); ++itr) + data << uint16(*itr); + + data.WriteByteSeq(guid[3]); + data.WriteByteSeq(guid[0]); + + data << uint32(terrainswaps.size()) * 2; // Active terrain swaps + for (std::set<uint32>::const_iterator itr = terrainswaps.begin(); itr != terrainswaps.end(); ++itr) + data << uint16(*itr); + + data.WriteByteSeq(guid[5]); + + SendPacket(&data); +} + +// Battlefield and Battleground +void WorldSession::HandleAreaSpiritHealerQueryOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_AREA_SPIRIT_HEALER_QUERY"); + + Battleground* bg = _player->GetBattleground(); + + ObjectGuid guid; + recvData >> guid; + + Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); + if (!unit) + return; + + if (!unit->IsSpiritService()) // it's not spirit service + return; + + if (bg) + sBattlegroundMgr->SendAreaSpiritHealerQueryOpcode(_player, bg, guid); + + if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId())) + bf->SendAreaSpiritHealerQueryOpcode(_player, guid); +} + +void WorldSession::HandleAreaSpiritHealerQueueOpcode(WorldPacket& recvData) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_AREA_SPIRIT_HEALER_QUEUE"); + + Battleground* bg = _player->GetBattleground(); + + ObjectGuid guid; + recvData >> guid; + + Creature* unit = GetPlayer()->GetMap()->GetCreature(guid); + if (!unit) + return; + + if (!unit->IsSpiritService()) // it's not spirit service + return; + + if (bg) + bg->AddPlayerToResurrectQueue(guid, _player->GetGUID()); + + if (Battlefield* bf = sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId())) + bf->AddPlayerToResurrectQueue(guid, _player->GetGUID()); +} + +void WorldSession::HandleHearthAndResurrect(WorldPacket& /*recvData*/) +{ + if (_player->IsInFlight()) + return; + + if (/*Battlefield* bf = */sBattlefieldMgr->GetBattlefieldToZoneId(_player->GetZoneId())) + { + // bf->PlayerAskToLeave(_player); FIXME + return; + } + + AreaTableEntry const* atEntry = GetAreaEntryByAreaID(_player->GetAreaId()); + if (!atEntry || !(atEntry->Flags[0] & AREA_FLAG_WINTERGRASP_2)) + return; + + _player->BuildPlayerRepop(); + _player->ResurrectPlayer(1.0f); + _player->TeleportTo(_player->m_homebindMapId, _player->m_homebindX, _player->m_homebindY, _player->m_homebindZ, _player->GetOrientation()); +} + +void WorldSession::HandleInstanceLockResponse(WorldPacket& recvPacket) +{ + uint8 accept; + recvPacket >> accept; + + if (!_player->HasPendingBind()) + { + TC_LOG_INFO("network", "InstanceLockResponse: Player %s (%s) tried to bind himself/teleport to graveyard without a pending bind!", + _player->GetName().c_str(), _player->GetGUID().ToString().c_str()); + return; + } + + if (accept) + _player->BindToInstance(); + else + _player->RepopAtGraveyard(); + + _player->SetPendingBind(0, 0); +} + +void WorldSession::HandleUpdateMissileTrajectory(WorldPacket& recvPacket) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_UPDATE_MISSILE_TRAJECTORY"); + + ObjectGuid guid; + uint32 spellId; + float elevation, speed; + float curX, curY, curZ; + float targetX, targetY, targetZ; + uint8 moveStop; + + recvPacket >> guid >> spellId >> elevation >> speed; + recvPacket >> curX >> curY >> curZ; + recvPacket >> targetX >> targetY >> targetZ; + recvPacket >> moveStop; + + Unit* caster = ObjectAccessor::GetUnit(*_player, guid); + Spell* spell = caster ? caster->GetCurrentSpell(CURRENT_GENERIC_SPELL) : NULL; + if (!spell || spell->m_spellInfo->Id != spellId || !spell->m_targets.HasDst() || !spell->m_targets.HasSrc()) + { + recvPacket.rfinish(); + return; + } + + Position pos = *spell->m_targets.GetSrcPos(); + pos.Relocate(curX, curY, curZ); + spell->m_targets.ModSrc(pos); + + pos = *spell->m_targets.GetDstPos(); + pos.Relocate(targetX, targetY, targetZ); + spell->m_targets.ModDst(pos); + + spell->m_targets.SetElevation(elevation); + spell->m_targets.SetSpeed(speed); + + if (moveStop) + { + uint32 opcode; + recvPacket >> opcode; + recvPacket.SetOpcode(CMSG_MOVE_STOP); // always set to CMSG_MOVE_STOP in client SetOpcode + //HandleMovementOpcodes(recvPacket); + } +} + +void WorldSession::HandleViolenceLevel(WorldPackets::Misc::ViolenceLevel& /*violenceLevel*/) +{ + // do something? +} + +void WorldSession::HandleObjectUpdateFailedOpcode(WorldPacket& recvPacket) +{ + ObjectGuid guid; + guid[6] = recvPacket.ReadBit(); + guid[7] = recvPacket.ReadBit(); + guid[4] = recvPacket.ReadBit(); + guid[0] = recvPacket.ReadBit(); + guid[1] = recvPacket.ReadBit(); + guid[5] = recvPacket.ReadBit(); + guid[3] = recvPacket.ReadBit(); + guid[2] = recvPacket.ReadBit(); + + recvPacket.ReadByteSeq(guid[6]); + recvPacket.ReadByteSeq(guid[7]); + recvPacket.ReadByteSeq(guid[2]); + recvPacket.ReadByteSeq(guid[3]); + recvPacket.ReadByteSeq(guid[1]); + recvPacket.ReadByteSeq(guid[4]); + recvPacket.ReadByteSeq(guid[0]); + recvPacket.ReadByteSeq(guid[5]); + + WorldObject* obj = ObjectAccessor::GetWorldObject(*GetPlayer(), guid); + TC_LOG_ERROR("network", "Object update failed for %s (%s) for player %s (%s)", guid.ToString().c_str(), obj ? obj->GetName().c_str() : "object-not-found", GetPlayerName().c_str(), _player->GetGUID().ToString().c_str()); + + // If create object failed for current player then client will be stuck on loading screen + if (_player->GetGUID() == guid) + { + LogoutPlayer(true); + return; + } + + // Pretend we've never seen this object + _player->m_clientGUIDs.erase(guid); +} + +void WorldSession::HandleSaveCUFProfiles(WorldPacket& recvPacket) +{ + TC_LOG_DEBUG("network", "WORLD: CMSG_SAVE_CUF_PROFILES"); + + uint8 count = (uint8)recvPacket.ReadBits(20); + + if (count > MAX_CUF_PROFILES) + { + TC_LOG_ERROR("entities.player", "HandleSaveCUFProfiles - %s tried to save more than %i CUF profiles. Hacking attempt?", GetPlayerName().c_str(), MAX_CUF_PROFILES); + recvPacket.rfinish(); + return; + } + + CUFProfile* profiles[MAX_CUF_PROFILES]; + uint8 strlens[MAX_CUF_PROFILES]; + + for (uint8 i = 0; i < count; ++i) + { + profiles[i] = new CUFProfile; + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_SPEC_2 , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_10_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_UNK_157 , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_HEAL_PREDICTION , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_SPEC_1 , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_PVP , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_POWER_BAR , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_15_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_40_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_PETS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_5_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_ONLY_DISPELLABLE_DEBUFFS, recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_2_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_UNK_156 , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_NON_BOSS_DEBUFFS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_MAIN_TANK_AND_ASSIST , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_AGGRO_HIGHLIGHT , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_3_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_BORDER , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_USE_CLASS_COLORS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_UNK_145 , recvPacket.ReadBit()); + strlens[i] = (uint8)recvPacket.ReadBits(8); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_PVE , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_DISPLAY_HORIZONTAL_GROUPS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_AUTO_ACTIVATE_25_PLAYERS , recvPacket.ReadBit()); + profiles[i]->BoolOptions.set(CUF_KEEP_GROUPS_TOGETHER , recvPacket.ReadBit()); + } + + for (uint8 i = 0; i < count; ++i) + { + recvPacket >> profiles[i]->Unk146; + profiles[i]->ProfileName = recvPacket.ReadString(strlens[i]); + recvPacket >> profiles[i]->Unk152; + recvPacket >> profiles[i]->FrameHeight; + recvPacket >> profiles[i]->FrameWidth; + recvPacket >> profiles[i]->Unk150; + recvPacket >> profiles[i]->HealthText; + recvPacket >> profiles[i]->Unk147; + recvPacket >> profiles[i]->SortBy; + recvPacket >> profiles[i]->Unk154; + recvPacket >> profiles[i]->Unk148; + + GetPlayer()->SaveCUFProfile(i, profiles[i]); + } + + for (uint8 i = count; i < MAX_CUF_PROFILES; ++i) + GetPlayer()->SaveCUFProfile(i, NULL); +} + +void WorldSession::SendLoadCUFProfiles() +{ + Player* player = GetPlayer(); + + uint8 count = player->GetCUFProfilesCount(); + + ByteBuffer byteBuffer(25 * count); + WorldPacket data(SMSG_LOAD_CUF_PROFILES, 5 * count + 25 * count); + + data.WriteBits(count, 20); + for (uint8 i = 0; i < MAX_CUF_PROFILES; ++i) + { + CUFProfile* profile = player->GetCUFProfile(i); + if (!profile) + continue; + + data.WriteBit(profile->BoolOptions[CUF_UNK_157]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_10_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_5_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_25_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_HEAL_PREDICTION]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_PVE]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_HORIZONTAL_GROUPS]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_40_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_3_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_AGGRO_HIGHLIGHT]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_BORDER]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_2_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_NON_BOSS_DEBUFFS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_MAIN_TANK_AND_ASSIST]); + data.WriteBit(profile->BoolOptions[CUF_UNK_156]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_SPEC_2]); + data.WriteBit(profile->BoolOptions[CUF_USE_CLASS_COLORS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_POWER_BAR]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_SPEC_1]); + data.WriteBits(profile->ProfileName.size(), 8); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_ONLY_DISPELLABLE_DEBUFFS]); + data.WriteBit(profile->BoolOptions[CUF_KEEP_GROUPS_TOGETHER]); + data.WriteBit(profile->BoolOptions[CUF_UNK_145]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_15_PLAYERS]); + data.WriteBit(profile->BoolOptions[CUF_DISPLAY_PETS]); + data.WriteBit(profile->BoolOptions[CUF_AUTO_ACTIVATE_PVP]); + + byteBuffer << uint16(profile->Unk154); + byteBuffer << uint16(profile->FrameHeight); + byteBuffer << uint16(profile->Unk152); + byteBuffer << uint8(profile->Unk147); + byteBuffer << uint16(profile->Unk150); + byteBuffer << uint8(profile->Unk146); + byteBuffer << uint8(profile->HealthText); + byteBuffer << uint8(profile->SortBy); + byteBuffer << uint16(profile->FrameWidth); + byteBuffer << uint8(profile->Unk148); + byteBuffer.WriteString(profile->ProfileName); + } + + data.FlushBits(); + data.append(byteBuffer); + SendPacket(&data); +} diff --git a/src/server/game/Handlers/QueryHandler.cpp b/src/server/game/Handlers/QueryHandler.cpp index 0a8b7fd5298..35f17f84f7b 100644 --- a/src/server/game/Handlers/QueryHandler.cpp +++ b/src/server/game/Handlers/QueryHandler.cpp @@ -173,9 +173,9 @@ void WorldSession::HandleQueryCorpseLocation(WorldPackets::Query::QueryCorpseLoc if (!corpse) { - WorldPackets::Query::CorpseLocation packet;
- packet.Valid = false; // corpse not found
- SendPacket(packet.Write());
+ WorldPackets::Query::CorpseLocation packet; + packet.Valid = false; // corpse not found + SendPacket(packet.Write()); return; } @@ -205,12 +205,12 @@ void WorldSession::HandleQueryCorpseLocation(WorldPackets::Query::QueryCorpseLoc } } - WorldPackets::Query::CorpseLocation packet;
- packet.Valid = true;
- packet.MapID = corpseMapID;
- packet.ActualMapID = mapID;
- packet.Position = G3D::Vector3(x, y, z);
- packet.Transport = ObjectGuid::Empty; // NYI
+ WorldPackets::Query::CorpseLocation packet; + packet.Valid = true; + packet.MapID = corpseMapID; + packet.ActualMapID = mapID; + packet.Position = G3D::Vector3(x, y, z); + packet.Transport = ObjectGuid::Empty; // NYI SendPacket(packet.Write()); } diff --git a/src/server/game/Server/Packets/LootPackets.cpp b/src/server/game/Server/Packets/LootPackets.cpp index c51e05f9e25..e8c365ea45b 100644 --- a/src/server/game/Server/Packets/LootPackets.cpp +++ b/src/server/game/Server/Packets/LootPackets.cpp @@ -33,7 +33,7 @@ WorldPacket const* WorldPackets::Loot::LootResponse::Write() _worldPacket << Coins; _worldPacket << uint32(Items.size()); _worldPacket << uint32(Currencies.size()); - + for (LootItem const& item : Items) { _worldPacket.WriteBits(item.Type, 2); diff --git a/src/server/game/Server/Packets/LootPackets.h b/src/server/game/Server/Packets/LootPackets.h index 6a3df9de214..74a5c58d649 100644 --- a/src/server/game/Server/Packets/LootPackets.h +++ b/src/server/game/Server/Packets/LootPackets.h @@ -104,7 +104,7 @@ namespace WorldPackets ObjectGuid Owner; uint8 LootListID = 0; }; - + class LootRelease final : public ClientPacket { public: @@ -114,7 +114,7 @@ namespace WorldPackets ObjectGuid Unit; }; - + class LootMoney final : public ClientPacket { public: @@ -122,7 +122,7 @@ namespace WorldPackets void Read() override { } }; - + class LootMoneyNotify final : public ServerPacket { public: @@ -133,7 +133,7 @@ namespace WorldPackets uint32 Money = 0; bool SoleLooter = false; }; - + class CoinRemoved final : public ServerPacket { public: diff --git a/src/server/game/Server/Packets/MiscPackets.cpp b/src/server/game/Server/Packets/MiscPackets.cpp index dc0881ac302..da92f65020a 100644 --- a/src/server/game/Server/Packets/MiscPackets.cpp +++ b/src/server/game/Server/Packets/MiscPackets.cpp @@ -1,261 +1,261 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "MiscPackets.h"
-
-WorldPacket const* WorldPackets::Misc::BindPointUpdate::Write()
-{
- _worldPacket << float(BindPosition.x);
- _worldPacket << float(BindPosition.y);
- _worldPacket << float(BindPosition.z);
- _worldPacket << uint32(BindMapID);
- _worldPacket << uint32(BindAreaID);
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::InvalidatePlayer::Write()
-{
- _worldPacket << Guid;
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::LoginSetTimeSpeed::Write()
-{
- _worldPacket.AppendPackedTime(ServerTime);
- _worldPacket.AppendPackedTime(GameTime);
- _worldPacket << float(NewSpeed);
- _worldPacket << uint32(ServerTimeHolidayOffset);
- _worldPacket << uint32(GameTimeHolidayOffset);
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::SetCurrency::Write()
-{
- _worldPacket << uint32(Type);
- _worldPacket << uint32(Quantity);
- _worldPacket << uint32(Flags);
- _worldPacket.WriteBit(WeeklyQuantity.HasValue);
- _worldPacket.WriteBit(TrackedQuantity.HasValue);
- _worldPacket.WriteBit(SuppressChatLog);
-
- if (WeeklyQuantity.HasValue)
- _worldPacket << uint32(WeeklyQuantity.Value);
-
- if (TrackedQuantity.HasValue)
- _worldPacket << uint32(TrackedQuantity.Value);
-
- _worldPacket.FlushBits();
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::SetSelection::Read()
-{
- _worldPacket >> Selection;
-}
-
-WorldPacket const* WorldPackets::Misc::SetupCurrency::Write()
-{
- _worldPacket << uint32(Data.size());
-
- for (Record const& data : Data)
- {
- _worldPacket << uint32(data.Type);
- _worldPacket << uint32(data.Quantity);
-
- _worldPacket.WriteBit(data.WeeklyQuantity.HasValue);
- _worldPacket.WriteBit(data.MaxWeeklyQuantity.HasValue);
- _worldPacket.WriteBit(data.TrackedQuantity.HasValue);
-
- _worldPacket.WriteBits(data.Flags, 5);
-
- if (data.WeeklyQuantity.HasValue)
- _worldPacket << uint32(data.WeeklyQuantity.Value);
- if (data.MaxWeeklyQuantity.HasValue)
- _worldPacket << uint32(data.MaxWeeklyQuantity.Value);
- if (data.TrackedQuantity.HasValue)
- _worldPacket << uint32(data.TrackedQuantity.Value);
- }
-
- _worldPacket.FlushBits();
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::ViolenceLevel::Read()
-{
- _worldPacket >> ViolenceLvl;
-}
-
-WorldPacket const* WorldPackets::Misc::TimeSyncRequest::Write()
-{
- _worldPacket << SequenceIndex;
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::TimeSyncResponse::Read()
-{
- _worldPacket >> SequenceIndex;
- _worldPacket >> ClientTime;
-}
-
-WorldPacket const* WorldPackets::Misc::UITime::Write()
-{
- _worldPacket << Time;
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::TriggerMovie::Write()
-{
- _worldPacket << uint32(MovieID);
-
- return &_worldPacket;
-}
-WorldPacket const* WorldPackets::Misc::TriggerCinematic::Write()
-{
- _worldPacket << uint32(CinematicID);
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::TutorialFlags::Write()
-{
- _worldPacket.append(TutorialData, MAX_ACCOUNT_TUTORIAL_VALUES);
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::TutorialSetFlag::Read()
-{
- Action = _worldPacket.ReadBits(2);
- _worldPacket >> TutorialBit;
-}
-
-WorldPacket const* WorldPackets::Misc::WorldServerInfo::Write()
-{
- _worldPacket << uint32(DifficultyID);
- _worldPacket << uint8(IsTournamentRealm);
- _worldPacket << uint32(WeeklyReset);
- _worldPacket.WriteBit(RestrictedAccountMaxLevel.HasValue);
- _worldPacket.WriteBit(RestrictedAccountMaxMoney.HasValue);
- _worldPacket.WriteBit(IneligibleForLootMask.HasValue);
- _worldPacket.WriteBit(InstanceGroupSize.HasValue);
-
- if (RestrictedAccountMaxLevel.HasValue)
- _worldPacket << uint32(RestrictedAccountMaxLevel.Value);
-
- if (RestrictedAccountMaxMoney.HasValue)
- _worldPacket << uint32(RestrictedAccountMaxMoney.Value);
-
- if (IneligibleForLootMask.HasValue)
- _worldPacket << uint32(IneligibleForLootMask.Value);
-
- if (InstanceGroupSize.HasValue)
- _worldPacket << uint32(InstanceGroupSize.Value);
-
- _worldPacket.FlushBits();
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::AreaTrigger::Read()
-{
- _worldPacket >> AreaTriggerID;
- Entered = _worldPacket.ReadBit();
- FromClient = _worldPacket.ReadBit();
-}
-
-void WorldPackets::Misc::SetDungeonDifficulty::Read()
-{
- _worldPacket >> DifficultyID;
-}
-
-void WorldPackets::Misc::SetRaidDifficulty::Read()
-{
- _worldPacket >> DifficultyID;
- _worldPacket >> Legacy;
-}
-
-WorldPacket const* WorldPackets::Misc::DungeonDifficultySet::Write()
-{
- _worldPacket << int32(DifficultyID);
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::RaidDifficultySet::Write()
-{
- _worldPacket << int32(DifficultyID);
- _worldPacket << uint8(Legacy);
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::CorpseReclaimDelay::Write()
-{
- _worldPacket << Remaining;
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::DeathReleaseLoc::Write()
-{
- _worldPacket << MapID;
- _worldPacket << float(Loc.x);
- _worldPacket << float(Loc.y);
- _worldPacket << float(Loc.z);
-
- return &_worldPacket;
-}
-
-WorldPacket const* WorldPackets::Misc::PreRessurect::Write()
-{
- _worldPacket << PlayerGUID;
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::ReclaimCorpse::Read()
-{
- _worldPacket >> CorpseGUID;
-}
-
-void WorldPackets::Misc::RepopRequest::Read()
-{
- CheckInstance = _worldPacket.ReadBit();
-}
-
-WorldPacket const* WorldPackets::Misc::RequestCemeteryListResponse::Write()
-{
- _worldPacket.WriteBit(IsGossipTriggered);
- _worldPacket.FlushBits();
-
- _worldPacket << uint32(CemeteryID.size());
- for (uint32 cemetery : CemeteryID)
- _worldPacket << cemetery;
-
- return &_worldPacket;
-}
-
-void WorldPackets::Misc::ResurrectResponse::Read()
-{
- _worldPacket >> Resurrecter;
- _worldPacket >> Response;
-}
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "MiscPackets.h" + +WorldPacket const* WorldPackets::Misc::BindPointUpdate::Write() +{ + _worldPacket << float(BindPosition.x); + _worldPacket << float(BindPosition.y); + _worldPacket << float(BindPosition.z); + _worldPacket << uint32(BindMapID); + _worldPacket << uint32(BindAreaID); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::InvalidatePlayer::Write() +{ + _worldPacket << Guid; + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::LoginSetTimeSpeed::Write() +{ + _worldPacket.AppendPackedTime(ServerTime); + _worldPacket.AppendPackedTime(GameTime); + _worldPacket << float(NewSpeed); + _worldPacket << uint32(ServerTimeHolidayOffset); + _worldPacket << uint32(GameTimeHolidayOffset); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::SetCurrency::Write() +{ + _worldPacket << uint32(Type); + _worldPacket << uint32(Quantity); + _worldPacket << uint32(Flags); + _worldPacket.WriteBit(WeeklyQuantity.HasValue); + _worldPacket.WriteBit(TrackedQuantity.HasValue); + _worldPacket.WriteBit(SuppressChatLog); + + if (WeeklyQuantity.HasValue) + _worldPacket << uint32(WeeklyQuantity.Value); + + if (TrackedQuantity.HasValue) + _worldPacket << uint32(TrackedQuantity.Value); + + _worldPacket.FlushBits(); + + return &_worldPacket; +} + +void WorldPackets::Misc::SetSelection::Read() +{ + _worldPacket >> Selection; +} + +WorldPacket const* WorldPackets::Misc::SetupCurrency::Write() +{ + _worldPacket << uint32(Data.size()); + + for (Record const& data : Data) + { + _worldPacket << uint32(data.Type); + _worldPacket << uint32(data.Quantity); + + _worldPacket.WriteBit(data.WeeklyQuantity.HasValue); + _worldPacket.WriteBit(data.MaxWeeklyQuantity.HasValue); + _worldPacket.WriteBit(data.TrackedQuantity.HasValue); + + _worldPacket.WriteBits(data.Flags, 5); + + if (data.WeeklyQuantity.HasValue) + _worldPacket << uint32(data.WeeklyQuantity.Value); + if (data.MaxWeeklyQuantity.HasValue) + _worldPacket << uint32(data.MaxWeeklyQuantity.Value); + if (data.TrackedQuantity.HasValue) + _worldPacket << uint32(data.TrackedQuantity.Value); + } + + _worldPacket.FlushBits(); + + return &_worldPacket; +} + +void WorldPackets::Misc::ViolenceLevel::Read() +{ + _worldPacket >> ViolenceLvl; +} + +WorldPacket const* WorldPackets::Misc::TimeSyncRequest::Write() +{ + _worldPacket << SequenceIndex; + + return &_worldPacket; +} + +void WorldPackets::Misc::TimeSyncResponse::Read() +{ + _worldPacket >> SequenceIndex; + _worldPacket >> ClientTime; +} + +WorldPacket const* WorldPackets::Misc::UITime::Write() +{ + _worldPacket << Time; + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::TriggerMovie::Write() +{ + _worldPacket << uint32(MovieID); + + return &_worldPacket; +} +WorldPacket const* WorldPackets::Misc::TriggerCinematic::Write() +{ + _worldPacket << uint32(CinematicID); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::TutorialFlags::Write() +{ + _worldPacket.append(TutorialData, MAX_ACCOUNT_TUTORIAL_VALUES); + + return &_worldPacket; +} + +void WorldPackets::Misc::TutorialSetFlag::Read() +{ + Action = _worldPacket.ReadBits(2); + _worldPacket >> TutorialBit; +} + +WorldPacket const* WorldPackets::Misc::WorldServerInfo::Write() +{ + _worldPacket << uint32(DifficultyID); + _worldPacket << uint8(IsTournamentRealm); + _worldPacket << uint32(WeeklyReset); + _worldPacket.WriteBit(RestrictedAccountMaxLevel.HasValue); + _worldPacket.WriteBit(RestrictedAccountMaxMoney.HasValue); + _worldPacket.WriteBit(IneligibleForLootMask.HasValue); + _worldPacket.WriteBit(InstanceGroupSize.HasValue); + + if (RestrictedAccountMaxLevel.HasValue) + _worldPacket << uint32(RestrictedAccountMaxLevel.Value); + + if (RestrictedAccountMaxMoney.HasValue) + _worldPacket << uint32(RestrictedAccountMaxMoney.Value); + + if (IneligibleForLootMask.HasValue) + _worldPacket << uint32(IneligibleForLootMask.Value); + + if (InstanceGroupSize.HasValue) + _worldPacket << uint32(InstanceGroupSize.Value); + + _worldPacket.FlushBits(); + + return &_worldPacket; +} + +void WorldPackets::Misc::AreaTrigger::Read() +{ + _worldPacket >> AreaTriggerID; + Entered = _worldPacket.ReadBit(); + FromClient = _worldPacket.ReadBit(); +} + +void WorldPackets::Misc::SetDungeonDifficulty::Read() +{ + _worldPacket >> DifficultyID; +} + +void WorldPackets::Misc::SetRaidDifficulty::Read() +{ + _worldPacket >> DifficultyID; + _worldPacket >> Legacy; +} + +WorldPacket const* WorldPackets::Misc::DungeonDifficultySet::Write() +{ + _worldPacket << int32(DifficultyID); + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::RaidDifficultySet::Write() +{ + _worldPacket << int32(DifficultyID); + _worldPacket << uint8(Legacy); + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::CorpseReclaimDelay::Write() +{ + _worldPacket << Remaining; + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::DeathReleaseLoc::Write() +{ + _worldPacket << MapID; + _worldPacket << float(Loc.x); + _worldPacket << float(Loc.y); + _worldPacket << float(Loc.z); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Misc::PreRessurect::Write() +{ + _worldPacket << PlayerGUID; + + return &_worldPacket; +} + +void WorldPackets::Misc::ReclaimCorpse::Read() +{ + _worldPacket >> CorpseGUID; +} + +void WorldPackets::Misc::RepopRequest::Read() +{ + CheckInstance = _worldPacket.ReadBit(); +} + +WorldPacket const* WorldPackets::Misc::RequestCemeteryListResponse::Write() +{ + _worldPacket.WriteBit(IsGossipTriggered); + _worldPacket.FlushBits(); + + _worldPacket << uint32(CemeteryID.size()); + for (uint32 cemetery : CemeteryID) + _worldPacket << cemetery; + + return &_worldPacket; +} + +void WorldPackets::Misc::ResurrectResponse::Read() +{ + _worldPacket >> Resurrecter; + _worldPacket >> Response; +} diff --git a/src/server/game/Server/Packets/MiscPackets.h b/src/server/game/Server/Packets/MiscPackets.h index e7b334ee629..acfb3115d50 100644 --- a/src/server/game/Server/Packets/MiscPackets.h +++ b/src/server/game/Server/Packets/MiscPackets.h @@ -1,366 +1,366 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef MiscPackets_h__
-#define MiscPackets_h__
-
-#include "Packet.h"
-#include "ObjectGuid.h"
-#include "WorldSession.h"
-#include "G3D/Vector3.h"
-#include "Object.h"
-
-namespace WorldPackets
-{
- namespace Misc
- {
- class BindPointUpdate final : public ServerPacket
- {
- public:
- BindPointUpdate() : ServerPacket(SMSG_BINDPOINTUPDATE, 20) { }
-
- WorldPacket const* Write() override;
-
- uint32 BindMapID = MAPID_INVALID;
- G3D::Vector3 BindPosition;
- uint32 BindAreaID = 0;
- };
-
- class InvalidatePlayer final : public ServerPacket
- {
- public:
- InvalidatePlayer() : ServerPacket(SMSG_INVALIDATE_PLAYER, 18) { }
-
- WorldPacket const* Write() override;
-
- ObjectGuid Guid;
- };
-
- class LoginSetTimeSpeed final : public ServerPacket
- {
- public:
- LoginSetTimeSpeed() : ServerPacket(SMSG_LOGIN_SETTIMESPEED, 20) { }
-
- WorldPacket const* Write() override;
-
- float NewSpeed = 0.0f;
- int32 ServerTimeHolidayOffset = 0;
- uint32 GameTime = 0;
- uint32 ServerTime = 0;
- int32 GameTimeHolidayOffset = 0;
- };
-
- class SetCurrency final : public ServerPacket
- {
- public:
- SetCurrency() : ServerPacket(SMSG_SET_CURRENCY, 12) { }
-
- WorldPacket const* Write() override;
-
- bool SuppressChatLog = false;
- Optional<int32> TrackedQuantity;
- int32 Quantity = 0;
- uint32 Flags = 0;
- int32 Type = 0;
- Optional<int32> WeeklyQuantity;
- };
-
- class SetSelection final : public ClientPacket
- {
- public:
- SetSelection(WorldPacket&& packet) : ClientPacket(CMSG_SET_SELECTION, std::move(packet)) { }
-
- void Read() override;
-
- ObjectGuid Selection; ///< Target
- };
-
- class SetupCurrency final : public ServerPacket
- {
- public:
- struct Record
- {
- int32 Type = 0; // ID from CurrencyTypes.dbc
- int32 Quantity = 0;
- Optional<int32> WeeklyQuantity; // Currency count obtained this Week.
- Optional<int32> MaxWeeklyQuantity; // Weekly Currency cap.
- Optional<int32> TrackedQuantity;
- uint8 Flags = 0; // 0 = none,
- };
-
- SetupCurrency() : ServerPacket(SMSG_SETUP_CURRENCY, 22) { }
-
- WorldPacket const* Write() override;
-
- std::vector<Record> Data;
- };
-
- class ViolenceLevel final : public ClientPacket
- {
- public:
- ViolenceLevel(WorldPacket&& packet) : ClientPacket(CMSG_VIOLENCE_LEVEL, std::move(packet)) { }
-
- void Read() override;
-
- int8 ViolenceLvl = -1; ///< 0 - no combat effects, 1 - display some combat effects, 2 - blood, 3 - bloody, 4 - bloodier, 5 - bloodiest
- };
-
- class TimeSyncRequest final : public ServerPacket
- {
- public:
- TimeSyncRequest() : ServerPacket(SMSG_TIME_SYNC_REQ, 4) { }
-
- WorldPacket const* Write() override;
-
- uint32 SequenceIndex = 0;
- };
-
- class TimeSyncResponse final : public ClientPacket
- {
- public:
- TimeSyncResponse(WorldPacket&& packet) : ClientPacket(CMSG_TIME_SYNC_RESPONSE, std::move(packet)) { }
-
- void Read() override;
-
- uint32 ClientTime = 0; // Client ticks in ms
- uint32 SequenceIndex = 0; // Same index as in request
- };
-
- class TriggerCinematic final : public ServerPacket
- {
- public:
- TriggerCinematic() : ServerPacket(SMSG_TRIGGER_CINEMATIC, 4) { }
-
- WorldPacket const* Write() override;
-
- uint32 CinematicID = 0;
- };
-
- class TriggerMovie final : public ServerPacket
- {
- public:
- TriggerMovie() : ServerPacket(SMSG_TRIGGER_MOVIE, 4) { }
-
- WorldPacket const* Write() override;
-
- uint32 MovieID = 0;
- };
-
- class UITime final : public ServerPacket
- {
- public:
- UITime() : ServerPacket(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4) { }
-
- WorldPacket const* Write() override;
-
- uint32 Time = 0;
- };
-
- class TutorialFlags : public ServerPacket
- {
- public:
- TutorialFlags() : ServerPacket(SMSG_TUTORIAL_FLAGS, 32)
- {
- std::memset(TutorialData, 0, sizeof(TutorialData));
- }
-
- WorldPacket const* Write() override;
-
- uint32 TutorialData[MAX_ACCOUNT_TUTORIAL_VALUES];
- };
-
- class TutorialSetFlag final : public ClientPacket
- {
- public:
- TutorialSetFlag(WorldPacket&& packet) : ClientPacket(CMSG_TUTORIAL_FLAG, std::move(packet)) { }
-
- void Read() override;
-
- uint8 Action = 0;
- uint32 TutorialBit = 0;
- };
-
- class WorldServerInfo final : public ServerPacket
- {
- public:
- WorldServerInfo() : ServerPacket(SMSG_WORLD_SERVER_INFO, 26) { }
-
- WorldPacket const* Write() override;
-
- Optional<uint32> IneligibleForLootMask; ///< Encountermask?
- uint32 WeeklyReset = 0; ///< UnixTime of last Weekly Reset Time
- Optional<uint32> InstanceGroupSize;
- uint8 IsTournamentRealm = 0;
- Optional<uint32> RestrictedAccountMaxLevel;
- Optional<uint32> RestrictedAccountMaxMoney;
- uint32 DifficultyID = 0;
- };
-
- class AreaTrigger final : public ClientPacket
- {
- public:
- AreaTrigger(WorldPacket&& packet) : ClientPacket(CMSG_AREATRIGGER, std::move(packet)) { }
-
- void Read() override;
-
- int32 AreaTriggerID = 0;
- bool Entered = false;
- bool FromClient = false;
- };
-
- class SetDungeonDifficulty final : public ClientPacket
- {
- public:
- SetDungeonDifficulty(WorldPacket&& packet) : ClientPacket(CMSG_SET_DUNGEON_DIFFICULTY, std::move(packet)) { }
-
- void Read() override;
-
- int32 DifficultyID;
- };
-
- class SetRaidDifficulty final : public ClientPacket
- {
- public:
- SetRaidDifficulty(WorldPacket&& packet) : ClientPacket(CMSG_SET_RAID_DIFFICULTY, std::move(packet)) { }
-
- void Read() override;
-
- int32 DifficultyID;
- uint8 Legacy;
- };
-
- class DungeonDifficultySet final : public ServerPacket
- {
- public:
- DungeonDifficultySet() : ServerPacket(SMSG_SET_DUNGEON_DIFFICULTY, 4) { }
-
- WorldPacket const* Write() override;
-
- int32 DifficultyID;
- };
-
- class RaidDifficultySet final : public ServerPacket
- {
- public:
- RaidDifficultySet() : ServerPacket(SMSG_SET_RAID_DIFFICULTY, 4 + 1) { }
-
- WorldPacket const* Write() override;
-
- int32 DifficultyID;
- uint8 Legacy;
- };
-
- class CorpseReclaimDelay : public ServerPacket
- {
- public:
- CorpseReclaimDelay() : ServerPacket(SMSG_CORPSE_RECLAIM_DELAY, 4) { }
-
- WorldPacket const* Write() override;
-
- uint32 Remaining = 0;
- };
-
- class DeathReleaseLoc : public ServerPacket
- {
- public:
- DeathReleaseLoc() : ServerPacket(SMSG_DEATH_RELEASE_LOC, 4 + (3 * 4)) { }
-
- WorldPacket const* Write() override;
-
- int32 MapID = 0;
- G3D::Vector3 Loc;
- };
-
- class PortGraveyard final : public ClientPacket
- {
- public:
- PortGraveyard(WorldPacket&& packet) : ClientPacket(CMSG_PORT_GRAVEYARD, std::move(packet)) { }
-
- void Read() override { }
- };
-
- class PreRessurect : public ServerPacket
- {
- public:
- PreRessurect() : ServerPacket(SMSG_PRE_RESSURECT, 18) { }
-
- WorldPacket const* Write() override;
-
- ObjectGuid PlayerGUID;
- };
-
- class ReclaimCorpse final : public ClientPacket
- {
- public:
- ReclaimCorpse(WorldPacket&& packet) : ClientPacket(CMSG_RECLAIM_CORPSE, std::move(packet)) { }
-
- void Read() override;
-
- ObjectGuid CorpseGUID;
- };
-
- class RepopRequest final : public ClientPacket
- {
- public:
- RepopRequest(WorldPacket&& packet) : ClientPacket(CMSG_REPOP_REQUEST, std::move(packet)) { }
-
- void Read() override;
-
- bool CheckInstance = false;
- };
-
- class RequestCemeteryList final : public ClientPacket
- {
- public:
- RequestCemeteryList(WorldPacket&& packet) : ClientPacket(CMSG_REQUEST_CEMETERY_LIST, std::move(packet)) { }
-
- void Read() override { }
- };
-
- class RequestCemeteryListResponse : public ServerPacket
- {
- public:
- RequestCemeteryListResponse() : ServerPacket(SMSG_REQUEST_CEMETERY_LIST_RESPONSE, 1) { }
-
- WorldPacket const* Write() override;
-
- bool IsGossipTriggered = false;
- std::vector<uint32> CemeteryID;
- };
-
- class ResurrectResponse final : public ClientPacket
- {
- public:
- ResurrectResponse(WorldPacket&& packet) : ClientPacket(CMSG_RESURRECT_RESPONSE, std::move(packet)) { }
-
- void Read() override;
-
- ObjectGuid Resurrecter;
- uint32 Response = 0;
- };
-
- class AreaTriggerNoCorpse : public ServerPacket
- {
- public:
- AreaTriggerNoCorpse() : ServerPacket(SMSG_AREA_TRIGGER_NO_CORPSE, 0) { }
-
- WorldPacket const* Write() override { return &_worldPacket; }
- };
- }
-}
-
-#endif // MiscPackets_h__
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MiscPackets_h__ +#define MiscPackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" +#include "WorldSession.h" +#include "G3D/Vector3.h" +#include "Object.h" + +namespace WorldPackets +{ + namespace Misc + { + class BindPointUpdate final : public ServerPacket + { + public: + BindPointUpdate() : ServerPacket(SMSG_BINDPOINTUPDATE, 20) { } + + WorldPacket const* Write() override; + + uint32 BindMapID = MAPID_INVALID; + G3D::Vector3 BindPosition; + uint32 BindAreaID = 0; + }; + + class InvalidatePlayer final : public ServerPacket + { + public: + InvalidatePlayer() : ServerPacket(SMSG_INVALIDATE_PLAYER, 18) { } + + WorldPacket const* Write() override; + + ObjectGuid Guid; + }; + + class LoginSetTimeSpeed final : public ServerPacket + { + public: + LoginSetTimeSpeed() : ServerPacket(SMSG_LOGIN_SETTIMESPEED, 20) { } + + WorldPacket const* Write() override; + + float NewSpeed = 0.0f; + int32 ServerTimeHolidayOffset = 0; + uint32 GameTime = 0; + uint32 ServerTime = 0; + int32 GameTimeHolidayOffset = 0; + }; + + class SetCurrency final : public ServerPacket + { + public: + SetCurrency() : ServerPacket(SMSG_SET_CURRENCY, 12) { } + + WorldPacket const* Write() override; + + bool SuppressChatLog = false; + Optional<int32> TrackedQuantity; + int32 Quantity = 0; + uint32 Flags = 0; + int32 Type = 0; + Optional<int32> WeeklyQuantity; + }; + + class SetSelection final : public ClientPacket + { + public: + SetSelection(WorldPacket&& packet) : ClientPacket(CMSG_SET_SELECTION, std::move(packet)) { } + + void Read() override; + + ObjectGuid Selection; ///< Target + }; + + class SetupCurrency final : public ServerPacket + { + public: + struct Record + { + int32 Type = 0; // ID from CurrencyTypes.dbc + int32 Quantity = 0; + Optional<int32> WeeklyQuantity; // Currency count obtained this Week. + Optional<int32> MaxWeeklyQuantity; // Weekly Currency cap. + Optional<int32> TrackedQuantity; + uint8 Flags = 0; // 0 = none, + }; + + SetupCurrency() : ServerPacket(SMSG_SETUP_CURRENCY, 22) { } + + WorldPacket const* Write() override; + + std::vector<Record> Data; + }; + + class ViolenceLevel final : public ClientPacket + { + public: + ViolenceLevel(WorldPacket&& packet) : ClientPacket(CMSG_VIOLENCE_LEVEL, std::move(packet)) { } + + void Read() override; + + int8 ViolenceLvl = -1; ///< 0 - no combat effects, 1 - display some combat effects, 2 - blood, 3 - bloody, 4 - bloodier, 5 - bloodiest + }; + + class TimeSyncRequest final : public ServerPacket + { + public: + TimeSyncRequest() : ServerPacket(SMSG_TIME_SYNC_REQ, 4) { } + + WorldPacket const* Write() override; + + uint32 SequenceIndex = 0; + }; + + class TimeSyncResponse final : public ClientPacket + { + public: + TimeSyncResponse(WorldPacket&& packet) : ClientPacket(CMSG_TIME_SYNC_RESPONSE, std::move(packet)) { } + + void Read() override; + + uint32 ClientTime = 0; // Client ticks in ms + uint32 SequenceIndex = 0; // Same index as in request + }; + + class TriggerCinematic final : public ServerPacket + { + public: + TriggerCinematic() : ServerPacket(SMSG_TRIGGER_CINEMATIC, 4) { } + + WorldPacket const* Write() override; + + uint32 CinematicID = 0; + }; + + class TriggerMovie final : public ServerPacket + { + public: + TriggerMovie() : ServerPacket(SMSG_TRIGGER_MOVIE, 4) { } + + WorldPacket const* Write() override; + + uint32 MovieID = 0; + }; + + class UITime final : public ServerPacket + { + public: + UITime() : ServerPacket(SMSG_WORLD_STATE_UI_TIMER_UPDATE, 4) { } + + WorldPacket const* Write() override; + + uint32 Time = 0; + }; + + class TutorialFlags : public ServerPacket + { + public: + TutorialFlags() : ServerPacket(SMSG_TUTORIAL_FLAGS, 32) + { + std::memset(TutorialData, 0, sizeof(TutorialData)); + } + + WorldPacket const* Write() override; + + uint32 TutorialData[MAX_ACCOUNT_TUTORIAL_VALUES]; + }; + + class TutorialSetFlag final : public ClientPacket + { + public: + TutorialSetFlag(WorldPacket&& packet) : ClientPacket(CMSG_TUTORIAL_FLAG, std::move(packet)) { } + + void Read() override; + + uint8 Action = 0; + uint32 TutorialBit = 0; + }; + + class WorldServerInfo final : public ServerPacket + { + public: + WorldServerInfo() : ServerPacket(SMSG_WORLD_SERVER_INFO, 26) { } + + WorldPacket const* Write() override; + + Optional<uint32> IneligibleForLootMask; ///< Encountermask? + uint32 WeeklyReset = 0; ///< UnixTime of last Weekly Reset Time + Optional<uint32> InstanceGroupSize; + uint8 IsTournamentRealm = 0; + Optional<uint32> RestrictedAccountMaxLevel; + Optional<uint32> RestrictedAccountMaxMoney; + uint32 DifficultyID = 0; + }; + + class AreaTrigger final : public ClientPacket + { + public: + AreaTrigger(WorldPacket&& packet) : ClientPacket(CMSG_AREATRIGGER, std::move(packet)) { } + + void Read() override; + + int32 AreaTriggerID = 0; + bool Entered = false; + bool FromClient = false; + }; + + class SetDungeonDifficulty final : public ClientPacket + { + public: + SetDungeonDifficulty(WorldPacket&& packet) : ClientPacket(CMSG_SET_DUNGEON_DIFFICULTY, std::move(packet)) { } + + void Read() override; + + int32 DifficultyID; + }; + + class SetRaidDifficulty final : public ClientPacket + { + public: + SetRaidDifficulty(WorldPacket&& packet) : ClientPacket(CMSG_SET_RAID_DIFFICULTY, std::move(packet)) { } + + void Read() override; + + int32 DifficultyID; + uint8 Legacy; + }; + + class DungeonDifficultySet final : public ServerPacket + { + public: + DungeonDifficultySet() : ServerPacket(SMSG_SET_DUNGEON_DIFFICULTY, 4) { } + + WorldPacket const* Write() override; + + int32 DifficultyID; + }; + + class RaidDifficultySet final : public ServerPacket + { + public: + RaidDifficultySet() : ServerPacket(SMSG_SET_RAID_DIFFICULTY, 4 + 1) { } + + WorldPacket const* Write() override; + + int32 DifficultyID; + uint8 Legacy; + }; + + class CorpseReclaimDelay : public ServerPacket + { + public: + CorpseReclaimDelay() : ServerPacket(SMSG_CORPSE_RECLAIM_DELAY, 4) { } + + WorldPacket const* Write() override; + + uint32 Remaining = 0; + }; + + class DeathReleaseLoc : public ServerPacket + { + public: + DeathReleaseLoc() : ServerPacket(SMSG_DEATH_RELEASE_LOC, 4 + (3 * 4)) { } + + WorldPacket const* Write() override; + + int32 MapID = 0; + G3D::Vector3 Loc; + }; + + class PortGraveyard final : public ClientPacket + { + public: + PortGraveyard(WorldPacket&& packet) : ClientPacket(CMSG_PORT_GRAVEYARD, std::move(packet)) { } + + void Read() override { } + }; + + class PreRessurect : public ServerPacket + { + public: + PreRessurect() : ServerPacket(SMSG_PRE_RESSURECT, 18) { } + + WorldPacket const* Write() override; + + ObjectGuid PlayerGUID; + }; + + class ReclaimCorpse final : public ClientPacket + { + public: + ReclaimCorpse(WorldPacket&& packet) : ClientPacket(CMSG_RECLAIM_CORPSE, std::move(packet)) { } + + void Read() override; + + ObjectGuid CorpseGUID; + }; + + class RepopRequest final : public ClientPacket + { + public: + RepopRequest(WorldPacket&& packet) : ClientPacket(CMSG_REPOP_REQUEST, std::move(packet)) { } + + void Read() override; + + bool CheckInstance = false; + }; + + class RequestCemeteryList final : public ClientPacket + { + public: + RequestCemeteryList(WorldPacket&& packet) : ClientPacket(CMSG_REQUEST_CEMETERY_LIST, std::move(packet)) { } + + void Read() override { } + }; + + class RequestCemeteryListResponse : public ServerPacket + { + public: + RequestCemeteryListResponse() : ServerPacket(SMSG_REQUEST_CEMETERY_LIST_RESPONSE, 1) { } + + WorldPacket const* Write() override; + + bool IsGossipTriggered = false; + std::vector<uint32> CemeteryID; + }; + + class ResurrectResponse final : public ClientPacket + { + public: + ResurrectResponse(WorldPacket&& packet) : ClientPacket(CMSG_RESURRECT_RESPONSE, std::move(packet)) { } + + void Read() override; + + ObjectGuid Resurrecter; + uint32 Response = 0; + }; + + class AreaTriggerNoCorpse : public ServerPacket + { + public: + AreaTriggerNoCorpse() : ServerPacket(SMSG_AREA_TRIGGER_NO_CORPSE, 0) { } + + WorldPacket const* Write() override { return &_worldPacket; } + }; + } +} + +#endif // MiscPackets_h__ diff --git a/src/server/game/Server/Packets/QueryPackets.cpp b/src/server/game/Server/Packets/QueryPackets.cpp index 2cd58f7b13c..1eb20e2f6e8 100644 --- a/src/server/game/Server/Packets/QueryPackets.cpp +++ b/src/server/game/Server/Packets/QueryPackets.cpp @@ -265,33 +265,33 @@ WorldPacket const* WorldPackets::Query::QueryGameObjectResponse::Write() return &_worldPacket; } -
-WorldPacket const* WorldPackets::Query::CorpseLocation::Write()
-{
- _worldPacket.WriteBit(Valid);
- _worldPacket.FlushBits();
-
- _worldPacket << ActualMapID;
- _worldPacket << Position.x;
- _worldPacket << Position.y;
- _worldPacket << Position.z;
- _worldPacket << MapID;
- _worldPacket << Transport;
-
- return &_worldPacket;
-}
+ +WorldPacket const* WorldPackets::Query::CorpseLocation::Write() +{ + _worldPacket.WriteBit(Valid); + _worldPacket.FlushBits(); + + _worldPacket << ActualMapID; + _worldPacket << Position.x; + _worldPacket << Position.y; + _worldPacket << Position.z; + _worldPacket << MapID; + _worldPacket << Transport; + + return &_worldPacket; +} void WorldPackets::Query::QueryCorpseTransport::Read() { _worldPacket >> Transport; } -
-WorldPacket const* WorldPackets::Query::CorpseTransportQuery::Write()
-{
- _worldPacket << Position.x;
- _worldPacket << Position.y;
- _worldPacket << Position.z;
- _worldPacket << Facing;
-
- return &_worldPacket;
-}
+ +WorldPacket const* WorldPackets::Query::CorpseTransportQuery::Write() +{ + _worldPacket << Position.x; + _worldPacket << Position.y; + _worldPacket << Position.z; + _worldPacket << Facing; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/QueryPackets.h b/src/server/game/Server/Packets/QueryPackets.h index 6e1c3ebe83b..0188ddcdb93 100644 --- a/src/server/game/Server/Packets/QueryPackets.h +++ b/src/server/game/Server/Packets/QueryPackets.h @@ -254,48 +254,48 @@ namespace WorldPackets bool Allow = false; GameObjectStats Stats; }; -
- class QueryCorpseLocationFromClient final : public ClientPacket
- {
- public:
- QueryCorpseLocationFromClient(WorldPacket&& packet) : ClientPacket(CMSG_QUERY_CORPSE_LOCATION_FROM_CLIENT, std::move(packet)) { }
-
- void Read() override { }
- };
-
- class CorpseLocation final : public ServerPacket
- {
- public:
- CorpseLocation() : ServerPacket(SMSG_CORPSE_LOCATION, 1 + (5 * 4) + 16) { }
-
- WorldPacket const* Write() override;
-
- ObjectGuid Transport;
- G3D::Vector3 Position;
- int32 ActualMapID = 0;
- int32 MapID = 0;
- bool Valid = false;
+ + class QueryCorpseLocationFromClient final : public ClientPacket + { + public: + QueryCorpseLocationFromClient(WorldPacket&& packet) : ClientPacket(CMSG_QUERY_CORPSE_LOCATION_FROM_CLIENT, std::move(packet)) { } + + void Read() override { } }; - class QueryCorpseTransport final : public ClientPacket
- {
- public:
- QueryCorpseTransport(WorldPacket&& packet) : ClientPacket(CMSG_QUERY_CORPSE_TRANSPORT , std::move(packet)) { }
-
- void Read() override;
-
- ObjectGuid Transport;
+ class CorpseLocation final : public ServerPacket + { + public: + CorpseLocation() : ServerPacket(SMSG_CORPSE_LOCATION, 1 + (5 * 4) + 16) { } + + WorldPacket const* Write() override; + + ObjectGuid Transport; + G3D::Vector3 Position; + int32 ActualMapID = 0; + int32 MapID = 0; + bool Valid = false; }; - class CorpseTransportQuery final : public ServerPacket
- {
- public:
- CorpseTransportQuery() : ServerPacket(SMSG_CORPSE_TRANSPORT_QUERY, 16) { }
-
- WorldPacket const* Write() override;
-
- G3D::Vector3 Position;
- float Facing = 0.0f;
+ class QueryCorpseTransport final : public ClientPacket + { + public: + QueryCorpseTransport(WorldPacket&& packet) : ClientPacket(CMSG_QUERY_CORPSE_TRANSPORT , std::move(packet)) { } + + void Read() override; + + ObjectGuid Transport; + }; + + class CorpseTransportQuery final : public ServerPacket + { + public: + CorpseTransportQuery() : ServerPacket(SMSG_CORPSE_TRANSPORT_QUERY, 16) { } + + WorldPacket const* Write() override; + + G3D::Vector3 Position; + float Facing = 0.0f; }; } } diff --git a/src/server/scripts/Commands/cs_rbac.cpp b/src/server/scripts/Commands/cs_rbac.cpp index d6f5f40a9c6..93593870975 100644 --- a/src/server/scripts/Commands/cs_rbac.cpp +++ b/src/server/scripts/Commands/cs_rbac.cpp @@ -1,383 +1,383 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/* ScriptData
-Name: rbac_commandscript
-%Complete: 100
-Comment: All role based access control related commands (including account related)
-Category: commandscripts
-EndScriptData */
-
-#include "AccountMgr.h"
-#include "Config.h"
-#include "Chat.h"
-#include "Language.h"
-#include "Player.h"
-#include "ScriptMgr.h"
-
-struct RBACCommandData
-{
- RBACCommandData(): id(0), realmId(0), rbac(NULL), needDelete(false) { }
- ~RBACCommandData()
- {
- if (needDelete)
- delete rbac;
- }
-
- uint32 id;
- int32 realmId;
- rbac::RBACData* rbac;
- bool needDelete;
-};
-
-class rbac_commandscript : public CommandScript
-{
-public:
- rbac_commandscript() : CommandScript("rbac_commandscript") { }
-
- ChatCommand* GetCommands() const
- {
- static ChatCommand rbacAccountCommandTable[] =
- {
- { "list", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_LIST, true, &HandleRBACPermListCommand, "", NULL },
- { "grant", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_GRANT, true, &HandleRBACPermGrantCommand, "", NULL },
- { "deny", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_DENY, true, &HandleRBACPermDenyCommand, "", NULL },
- { "revoke", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_REVOKE, true, &HandleRBACPermRevokeCommand, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
-
- static ChatCommand rbacCommandTable[] =
- {
- { "account", rbac::RBAC_PERM_COMMAND_RBAC_ACC, true, NULL, "", rbacAccountCommandTable },
- { "list", rbac::RBAC_PERM_COMMAND_RBAC_LIST, true, &HandleRBACListPermissionsCommand, "", NULL },
- { NULL, 0, false, NULL, "", NULL }
- };
-
- static ChatCommand commandTable[] =
- {
- { "rbac", rbac::RBAC_PERM_COMMAND_RBAC, true, NULL, "", rbacCommandTable },
- { NULL, 0, false, NULL, "", NULL }
- };
-
- return commandTable;
- }
-
- static RBACCommandData* ReadParams(ChatHandler* handler, char const* args, bool checkParams = true)
- {
- if (!args)
- return NULL;
-
- char* param1 = strtok((char*)args, " ");
- char* param2 = strtok(NULL, " ");
- char* param3 = strtok(NULL, " ");
-
- int32 realmId = -1;
- uint32 accountId = 0;
- std::string accountName;
- uint32 id = 0;
- RBACCommandData* data = NULL;
- rbac::RBACData* rdata = NULL;
- bool useSelectedPlayer = false;
-
- if (checkParams)
- {
- if (!param3)
- {
- if (param2)
- realmId = atoi(param2);
-
- if (param1)
- id = atoi(param1);
-
- useSelectedPlayer = true;
- }
- else
- {
- id = atoi(param2);
- realmId = atoi(param3);
- }
-
- if (!id)
- {
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, id);
- handler->SetSentErrorMessage(true);
- return NULL;
- }
-
- if (realmId < -1 || !realmId)
- {
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_REALM, realmId);
- handler->SetSentErrorMessage(true);
- return NULL;
- }
- }
- else if (!param1)
- useSelectedPlayer = true;
-
- if (useSelectedPlayer)
- {
- Player* player = handler->getSelectedPlayer();
- if (!player)
- return NULL;
-
- rdata = player->GetSession()->GetRBACData();
- accountId = rdata->GetId();
- AccountMgr::GetName(accountId, accountName);
- }
- else
- {
- accountName = param1;
-
- if (Utf8ToUpperOnlyLatin(accountName))
- accountId = AccountMgr::GetId(accountName);
-
- if (!accountId)
- {
- handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str());
- handler->SetSentErrorMessage(true);
- return NULL;
- }
- }
-
- if (checkParams && handler->HasLowerSecurityAccount(NULL, accountId, true))
- return NULL;
-
- data = new RBACCommandData();
-
- if (!rdata)
- {
- data->rbac = new rbac::RBACData(accountId, accountName, realmHandle.Index, AccountMgr::GetSecurity(accountId, realmHandle.Index));
- data->rbac->LoadFromDB();
- data->needDelete = true;
- }
- else
- data->rbac = rdata;
-
- data->id = id;
- data->realmId = realmId;
- return data;
- }
-
- static bool HandleRBACPermGrantCommand(ChatHandler* handler, char const* args)
- {
- RBACCommandData* command = ReadParams(handler, args);
-
- if (!command)
- {
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- rbac::RBACCommandResult result = command->rbac->GrantPermission(command->id, command->realmId);
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
-
- switch (result)
- {
- case rbac::RBAC_CANT_ADD_ALREADY_ADDED:
- handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_LIST, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_IN_DENIED_LIST:
- handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_DENIED_LIST, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_OK:
- handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_ID_DOES_NOT_EXISTS:
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
- break;
- default:
- break;
- }
-
- delete command;
-
- return true;
- }
-
- static bool HandleRBACPermDenyCommand(ChatHandler* handler, char const* args)
- {
- RBACCommandData* command = ReadParams(handler, args);
-
- if (!command)
- {
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- rbac::RBACCommandResult result = command->rbac->DenyPermission(command->id, command->realmId);
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
-
- switch (result)
- {
- case rbac::RBAC_CANT_ADD_ALREADY_ADDED:
- handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_LIST, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_IN_GRANTED_LIST:
- handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_GRANTED_LIST, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_OK:
- handler->PSendSysMessage(LANG_RBAC_PERM_DENIED, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_ID_DOES_NOT_EXISTS:
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
- break;
- default:
- break;
- }
-
- delete command;
-
- return true;
- }
-
- static bool HandleRBACPermRevokeCommand(ChatHandler* handler, char const* args)
- {
- RBACCommandData* command = ReadParams(handler, args);
-
- if (!command)
- {
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- rbac::RBACCommandResult result = command->rbac->RevokePermission(command->id, command->realmId);
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id);
-
- switch (result)
- {
- case rbac::RBAC_CANT_REVOKE_NOT_IN_LIST:
- handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED_NOT_IN_LIST, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_OK:
- handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED, command->id, permission->GetName().c_str(),
- command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str());
- break;
- case rbac::RBAC_ID_DOES_NOT_EXISTS:
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id);
- break;
- default:
- break;
- }
-
- delete command;
-
- return true;
- }
-
- static bool HandleRBACPermListCommand(ChatHandler* handler, char const* args)
- {
- RBACCommandData* command = ReadParams(handler, args, false);
-
- if (!command)
- {
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_GRANTED, command->rbac->GetId(), command->rbac->GetName().c_str());
- rbac::RBACPermissionContainer const& granted = command->rbac->GetGrantedPermissions();
- if (granted.empty())
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
- else
- {
- for (rbac::RBACPermissionContainer::const_iterator itr = granted.begin(); itr != granted.end(); ++itr)
- {
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
- }
- }
-
- handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_DENIED, command->rbac->GetId(), command->rbac->GetName().c_str());
- rbac::RBACPermissionContainer const& denied = command->rbac->GetDeniedPermissions();
- if (denied.empty())
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
- else
- {
- for (rbac::RBACPermissionContainer::const_iterator itr = denied.begin(); itr != denied.end(); ++itr)
- {
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
- }
- }
- handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_BY_SEC_LEVEL, command->rbac->GetId(), command->rbac->GetName().c_str(), command->rbac->GetSecurityLevel());
- rbac::RBACPermissionContainer const& defaultPermissions = sAccountMgr->GetRBACDefaultPermissions(command->rbac->GetSecurityLevel());
- if (defaultPermissions.empty())
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY));
- else
- {
- for (rbac::RBACPermissionContainer::const_iterator itr = defaultPermissions.begin(); itr != defaultPermissions.end(); ++itr)
- {
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr);
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
- }
- }
-
- delete command;
-
- return true;
- }
-
- static bool HandleRBACListPermissionsCommand(ChatHandler* handler, char const* args)
- {
- uint32 id = 0;
- if (char* param1 = strtok((char*)args, " "))
- id = atoi(param1);
-
- if (!id)
- {
- rbac::RBACPermissionsContainer const& permissions = sAccountMgr->GetRBACPermissionList();
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMISSIONS_HEADER));
- for (rbac::RBACPermissionsContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it)
- {
- rbac::RBACPermission const* permission = it->second;
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
- }
- }
- else
- {
- rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(id);
- if (!permission)
- {
- handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, id);
- handler->SetSentErrorMessage(true);
- return false;
- }
-
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMISSIONS_HEADER));
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str());
- handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMS_LINKED_HEADER));
- rbac::RBACPermissionContainer const& permissions = permission->GetLinkedPermissions();
- for (rbac::RBACPermissionContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it)
- if (rbac::RBACPermission const* rbacPermission = sAccountMgr->GetRBACPermission(*it))
- handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, rbacPermission->GetId(), rbacPermission->GetName().c_str());
- }
-
- return true;
- }
-};
-
-void AddSC_rbac_commandscript()
-{
- new rbac_commandscript();
-}
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* ScriptData +Name: rbac_commandscript +%Complete: 100 +Comment: All role based access control related commands (including account related) +Category: commandscripts +EndScriptData */ + +#include "AccountMgr.h" +#include "Config.h" +#include "Chat.h" +#include "Language.h" +#include "Player.h" +#include "ScriptMgr.h" + +struct RBACCommandData +{ + RBACCommandData(): id(0), realmId(0), rbac(NULL), needDelete(false) { } + ~RBACCommandData() + { + if (needDelete) + delete rbac; + } + + uint32 id; + int32 realmId; + rbac::RBACData* rbac; + bool needDelete; +}; + +class rbac_commandscript : public CommandScript +{ +public: + rbac_commandscript() : CommandScript("rbac_commandscript") { } + + ChatCommand* GetCommands() const + { + static ChatCommand rbacAccountCommandTable[] = + { + { "list", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_LIST, true, &HandleRBACPermListCommand, "", NULL }, + { "grant", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_GRANT, true, &HandleRBACPermGrantCommand, "", NULL }, + { "deny", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_DENY, true, &HandleRBACPermDenyCommand, "", NULL }, + { "revoke", rbac::RBAC_PERM_COMMAND_RBAC_ACC_PERM_REVOKE, true, &HandleRBACPermRevokeCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand rbacCommandTable[] = + { + { "account", rbac::RBAC_PERM_COMMAND_RBAC_ACC, true, NULL, "", rbacAccountCommandTable }, + { "list", rbac::RBAC_PERM_COMMAND_RBAC_LIST, true, &HandleRBACListPermissionsCommand, "", NULL }, + { NULL, 0, false, NULL, "", NULL } + }; + + static ChatCommand commandTable[] = + { + { "rbac", rbac::RBAC_PERM_COMMAND_RBAC, true, NULL, "", rbacCommandTable }, + { NULL, 0, false, NULL, "", NULL } + }; + + return commandTable; + } + + static RBACCommandData* ReadParams(ChatHandler* handler, char const* args, bool checkParams = true) + { + if (!args) + return NULL; + + char* param1 = strtok((char*)args, " "); + char* param2 = strtok(NULL, " "); + char* param3 = strtok(NULL, " "); + + int32 realmId = -1; + uint32 accountId = 0; + std::string accountName; + uint32 id = 0; + RBACCommandData* data = NULL; + rbac::RBACData* rdata = NULL; + bool useSelectedPlayer = false; + + if (checkParams) + { + if (!param3) + { + if (param2) + realmId = atoi(param2); + + if (param1) + id = atoi(param1); + + useSelectedPlayer = true; + } + else + { + id = atoi(param2); + realmId = atoi(param3); + } + + if (!id) + { + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, id); + handler->SetSentErrorMessage(true); + return NULL; + } + + if (realmId < -1 || !realmId) + { + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_REALM, realmId); + handler->SetSentErrorMessage(true); + return NULL; + } + } + else if (!param1) + useSelectedPlayer = true; + + if (useSelectedPlayer) + { + Player* player = handler->getSelectedPlayer(); + if (!player) + return NULL; + + rdata = player->GetSession()->GetRBACData(); + accountId = rdata->GetId(); + AccountMgr::GetName(accountId, accountName); + } + else + { + accountName = param1; + + if (Utf8ToUpperOnlyLatin(accountName)) + accountId = AccountMgr::GetId(accountName); + + if (!accountId) + { + handler->PSendSysMessage(LANG_ACCOUNT_NOT_EXIST, accountName.c_str()); + handler->SetSentErrorMessage(true); + return NULL; + } + } + + if (checkParams && handler->HasLowerSecurityAccount(NULL, accountId, true)) + return NULL; + + data = new RBACCommandData(); + + if (!rdata) + { + data->rbac = new rbac::RBACData(accountId, accountName, realmHandle.Index, AccountMgr::GetSecurity(accountId, realmHandle.Index)); + data->rbac->LoadFromDB(); + data->needDelete = true; + } + else + data->rbac = rdata; + + data->id = id; + data->realmId = realmId; + return data; + } + + static bool HandleRBACPermGrantCommand(ChatHandler* handler, char const* args) + { + RBACCommandData* command = ReadParams(handler, args); + + if (!command) + { + handler->SetSentErrorMessage(true); + return false; + } + + rbac::RBACCommandResult result = command->rbac->GrantPermission(command->id, command->realmId); + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id); + + switch (result) + { + case rbac::RBAC_CANT_ADD_ALREADY_ADDED: + handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_LIST, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_IN_DENIED_LIST: + handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED_IN_DENIED_LIST, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_OK: + handler->PSendSysMessage(LANG_RBAC_PERM_GRANTED, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_ID_DOES_NOT_EXISTS: + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id); + break; + default: + break; + } + + delete command; + + return true; + } + + static bool HandleRBACPermDenyCommand(ChatHandler* handler, char const* args) + { + RBACCommandData* command = ReadParams(handler, args); + + if (!command) + { + handler->SetSentErrorMessage(true); + return false; + } + + rbac::RBACCommandResult result = command->rbac->DenyPermission(command->id, command->realmId); + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id); + + switch (result) + { + case rbac::RBAC_CANT_ADD_ALREADY_ADDED: + handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_LIST, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_IN_GRANTED_LIST: + handler->PSendSysMessage(LANG_RBAC_PERM_DENIED_IN_GRANTED_LIST, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_OK: + handler->PSendSysMessage(LANG_RBAC_PERM_DENIED, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_ID_DOES_NOT_EXISTS: + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id); + break; + default: + break; + } + + delete command; + + return true; + } + + static bool HandleRBACPermRevokeCommand(ChatHandler* handler, char const* args) + { + RBACCommandData* command = ReadParams(handler, args); + + if (!command) + { + handler->SetSentErrorMessage(true); + return false; + } + + rbac::RBACCommandResult result = command->rbac->RevokePermission(command->id, command->realmId); + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(command->id); + + switch (result) + { + case rbac::RBAC_CANT_REVOKE_NOT_IN_LIST: + handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED_NOT_IN_LIST, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_OK: + handler->PSendSysMessage(LANG_RBAC_PERM_REVOKED, command->id, permission->GetName().c_str(), + command->realmId, command->rbac->GetId(), command->rbac->GetName().c_str()); + break; + case rbac::RBAC_ID_DOES_NOT_EXISTS: + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, command->id); + break; + default: + break; + } + + delete command; + + return true; + } + + static bool HandleRBACPermListCommand(ChatHandler* handler, char const* args) + { + RBACCommandData* command = ReadParams(handler, args, false); + + if (!command) + { + handler->SetSentErrorMessage(true); + return false; + } + + handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_GRANTED, command->rbac->GetId(), command->rbac->GetName().c_str()); + rbac::RBACPermissionContainer const& granted = command->rbac->GetGrantedPermissions(); + if (granted.empty()) + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY)); + else + { + for (rbac::RBACPermissionContainer::const_iterator itr = granted.begin(); itr != granted.end(); ++itr) + { + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr); + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str()); + } + } + + handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_DENIED, command->rbac->GetId(), command->rbac->GetName().c_str()); + rbac::RBACPermissionContainer const& denied = command->rbac->GetDeniedPermissions(); + if (denied.empty()) + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY)); + else + { + for (rbac::RBACPermissionContainer::const_iterator itr = denied.begin(); itr != denied.end(); ++itr) + { + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr); + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str()); + } + } + handler->PSendSysMessage(LANG_RBAC_LIST_HEADER_BY_SEC_LEVEL, command->rbac->GetId(), command->rbac->GetName().c_str(), command->rbac->GetSecurityLevel()); + rbac::RBACPermissionContainer const& defaultPermissions = sAccountMgr->GetRBACDefaultPermissions(command->rbac->GetSecurityLevel()); + if (defaultPermissions.empty()) + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_EMPTY)); + else + { + for (rbac::RBACPermissionContainer::const_iterator itr = defaultPermissions.begin(); itr != defaultPermissions.end(); ++itr) + { + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(*itr); + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str()); + } + } + + delete command; + + return true; + } + + static bool HandleRBACListPermissionsCommand(ChatHandler* handler, char const* args) + { + uint32 id = 0; + if (char* param1 = strtok((char*)args, " ")) + id = atoi(param1); + + if (!id) + { + rbac::RBACPermissionsContainer const& permissions = sAccountMgr->GetRBACPermissionList(); + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMISSIONS_HEADER)); + for (rbac::RBACPermissionsContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it) + { + rbac::RBACPermission const* permission = it->second; + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str()); + } + } + else + { + rbac::RBACPermission const* permission = sAccountMgr->GetRBACPermission(id); + if (!permission) + { + handler->PSendSysMessage(LANG_RBAC_WRONG_PARAMETER_ID, id); + handler->SetSentErrorMessage(true); + return false; + } + + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMISSIONS_HEADER)); + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, permission->GetId(), permission->GetName().c_str()); + handler->PSendSysMessage("%s", handler->GetTrinityString(LANG_RBAC_LIST_PERMS_LINKED_HEADER)); + rbac::RBACPermissionContainer const& permissions = permission->GetLinkedPermissions(); + for (rbac::RBACPermissionContainer::const_iterator it = permissions.begin(); it != permissions.end(); ++it) + if (rbac::RBACPermission const* rbacPermission = sAccountMgr->GetRBACPermission(*it)) + handler->PSendSysMessage(LANG_RBAC_LIST_ELEMENT, rbacPermission->GetId(), rbacPermission->GetName().c_str()); + } + + return true; + } +}; + +void AddSC_rbac_commandscript() +{ + new rbac_commandscript(); +} diff --git a/src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp b/src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp index 61b202fcfeb..0bc6a4f49a4 100644 --- a/src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp +++ b/src/server/scripts/Outland/BlackTemple/boss_warlord_najentus.cpp @@ -1,215 +1,215 @@ -/*
- * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "ScriptMgr.h"
-#include "ScriptedCreature.h"
-#include "black_temple.h"
-#include "Player.h"
-#include "SpellInfo.h"
-
-enum Texts
-{
- SAY_AGGRO = 0,
- SAY_NEEDLE = 1,
- SAY_SLAY = 2,
- SAY_SPECIAL = 3,
- SAY_ENRAGE = 4,
- SAY_DEATH = 5
-};
-
-enum Spells
-{
- SPELL_NEEDLE_SPINE = 39992,
- SPELL_TIDAL_BURST = 39878,
- SPELL_TIDAL_SHIELD = 39872,
- SPELL_IMPALING_SPINE = 39837,
- SPELL_CREATE_NAJENTUS_SPINE = 39956,
- SPELL_HURL_SPINE = 39948,
- SPELL_BERSERK = 26662
-
-};
-
-enum Events
-{
- EVENT_BERSERK = 1,
- EVENT_YELL = 2,
- EVENT_NEEDLE = 3,
- EVENT_SPINE = 4,
- EVENT_SHIELD = 5
-};
-
-enum EventGroups
-{
- GCD_CAST = 1,
- GCD_YELL = 2
-};
-
-class boss_najentus : public CreatureScript
-{
-public:
- boss_najentus() : CreatureScript("boss_najentus") { }
-
- struct boss_najentusAI : public BossAI
- {
- boss_najentusAI(Creature* creature) : BossAI(creature, DATA_HIGH_WARLORD_NAJENTUS)
- {
- }
-
- void Reset() override
- {
- _Reset();
- SpineTargetGUID.Clear();
- }
-
- void KilledUnit(Unit* /*victim*/) override
- {
- Talk(SAY_SLAY);
- events.DelayEvents(5000, GCD_YELL);
- }
-
- void JustDied(Unit* /*killer*/) override
- {
- _JustDied();
- Talk(SAY_DEATH);
- }
-
- void SpellHit(Unit* /*caster*/, const SpellInfo* spell) override
- {
- if (spell->Id == SPELL_HURL_SPINE && me->HasAura(SPELL_TIDAL_SHIELD))
- {
- me->RemoveAurasDueToSpell(SPELL_TIDAL_SHIELD);
- DoCast(me, SPELL_TIDAL_BURST, true);
- ResetTimer();
- }
- }
-
- void EnterCombat(Unit* /*who*/) override
- {
- _EnterCombat();
- Talk(SAY_AGGRO);
- events.ScheduleEvent(EVENT_BERSERK, 480000, GCD_CAST);
- events.ScheduleEvent(EVENT_YELL, 45000 + (rand32() % 76) * 1000, GCD_YELL);
- ResetTimer();
- }
-
- bool RemoveImpalingSpine()
- {
- if (!SpineTargetGUID)
- return false;
-
- Unit* target = ObjectAccessor::GetUnit(*me, SpineTargetGUID);
- if (target && target->HasAura(SPELL_IMPALING_SPINE))
- target->RemoveAurasDueToSpell(SPELL_IMPALING_SPINE);
- SpineTargetGUID.Clear();
- return true;
- }
-
- void ResetTimer(uint32 inc = 0)
- {
- events.RescheduleEvent(EVENT_NEEDLE, 10000 + inc, GCD_CAST);
- events.RescheduleEvent(EVENT_SPINE, 20000 + inc, GCD_CAST);
- events.RescheduleEvent(EVENT_SHIELD, 60000 + inc);
- }
-
- void ExecuteEvent(uint32 eventId) override
- {
- switch (eventId)
- {
- case EVENT_SHIELD:
- DoCast(me, SPELL_TIDAL_SHIELD, true);
- ResetTimer(45000);
- break;
- case EVENT_BERSERK:
- Talk(SAY_ENRAGE);
- DoCast(me, SPELL_BERSERK, true);
- events.DelayEvents(15000, GCD_YELL);
- break;
- case EVENT_SPINE:
- {
- Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1);
-
- if (!target)
- target = me->GetVictim();
-
- if (target)
- {
- DoCast(target, SPELL_IMPALING_SPINE, true);
- SpineTargetGUID = target->GetGUID();
- //must let target summon, otherwise you cannot click the spine
- target->SummonGameObject(GO_NAJENTUS_SPINE, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), me->GetOrientation(), 0, 0, 0, 0, 30);
- Talk(SAY_NEEDLE);
- events.DelayEvents(1500, GCD_CAST);
- events.DelayEvents(15000, GCD_YELL);
- }
- events.ScheduleEvent(EVENT_SPINE, 21000, GCD_CAST);
- return;
- }
- case EVENT_NEEDLE:
- {
- //DoCast(me, SPELL_NEEDLE_SPINE, true);
- std::list<Unit*> targets;
- SelectTargetList(targets, 3, SELECT_TARGET_RANDOM, 80, true);
- for (std::list<Unit*>::const_iterator i = targets.begin(); i != targets.end(); ++i)
- DoCast(*i, 39835, true);
- events.ScheduleEvent(EVENT_NEEDLE, urand(15000, 25000), GCD_CAST);
- events.DelayEvents(1500, GCD_CAST);
- return;
- }
- case EVENT_YELL:
- Talk(SAY_SPECIAL);
- events.ScheduleEvent(EVENT_YELL, urand(25000, 100000), GCD_YELL);
- events.DelayEvents(15000, GCD_YELL);
- break;
- default:
- break;
- }
- }
-
- private:
- ObjectGuid SpineTargetGUID;
- };
-
- CreatureAI* GetAI(Creature* creature) const override
- {
- return GetBlackTempleAI<boss_najentusAI>(creature);
- }
-};
-
-class go_najentus_spine : public GameObjectScript
-{
-public:
- go_najentus_spine() : GameObjectScript("go_najentus_spine") { }
-
- bool OnGossipHello(Player* player, GameObject* go) override
- {
- if (InstanceScript* instance = go->GetInstanceScript())
- if (Creature* Najentus = ObjectAccessor::GetCreature(*go, instance->GetGuidData(DATA_HIGH_WARLORD_NAJENTUS)))
- if (ENSURE_AI(boss_najentus::boss_najentusAI, Najentus->AI())->RemoveImpalingSpine())
- {
- player->CastSpell(player, SPELL_CREATE_NAJENTUS_SPINE, true);
- go->Delete();
- }
- return true;
- }
-
-};
-
-void AddSC_boss_najentus()
-{
- new boss_najentus();
- new go_najentus_spine();
-}
+/* + * Copyright (C) 2008-2015 TrinityCore <http://www.trinitycore.org/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "ScriptMgr.h" +#include "ScriptedCreature.h" +#include "black_temple.h" +#include "Player.h" +#include "SpellInfo.h" + +enum Texts +{ + SAY_AGGRO = 0, + SAY_NEEDLE = 1, + SAY_SLAY = 2, + SAY_SPECIAL = 3, + SAY_ENRAGE = 4, + SAY_DEATH = 5 +}; + +enum Spells +{ + SPELL_NEEDLE_SPINE = 39992, + SPELL_TIDAL_BURST = 39878, + SPELL_TIDAL_SHIELD = 39872, + SPELL_IMPALING_SPINE = 39837, + SPELL_CREATE_NAJENTUS_SPINE = 39956, + SPELL_HURL_SPINE = 39948, + SPELL_BERSERK = 26662 + +}; + +enum Events +{ + EVENT_BERSERK = 1, + EVENT_YELL = 2, + EVENT_NEEDLE = 3, + EVENT_SPINE = 4, + EVENT_SHIELD = 5 +}; + +enum EventGroups +{ + GCD_CAST = 1, + GCD_YELL = 2 +}; + +class boss_najentus : public CreatureScript +{ +public: + boss_najentus() : CreatureScript("boss_najentus") { } + + struct boss_najentusAI : public BossAI + { + boss_najentusAI(Creature* creature) : BossAI(creature, DATA_HIGH_WARLORD_NAJENTUS) + { + } + + void Reset() override + { + _Reset(); + SpineTargetGUID.Clear(); + } + + void KilledUnit(Unit* /*victim*/) override + { + Talk(SAY_SLAY); + events.DelayEvents(5000, GCD_YELL); + } + + void JustDied(Unit* /*killer*/) override + { + _JustDied(); + Talk(SAY_DEATH); + } + + void SpellHit(Unit* /*caster*/, const SpellInfo* spell) override + { + if (spell->Id == SPELL_HURL_SPINE && me->HasAura(SPELL_TIDAL_SHIELD)) + { + me->RemoveAurasDueToSpell(SPELL_TIDAL_SHIELD); + DoCast(me, SPELL_TIDAL_BURST, true); + ResetTimer(); + } + } + + void EnterCombat(Unit* /*who*/) override + { + _EnterCombat(); + Talk(SAY_AGGRO); + events.ScheduleEvent(EVENT_BERSERK, 480000, GCD_CAST); + events.ScheduleEvent(EVENT_YELL, 45000 + (rand32() % 76) * 1000, GCD_YELL); + ResetTimer(); + } + + bool RemoveImpalingSpine() + { + if (!SpineTargetGUID) + return false; + + Unit* target = ObjectAccessor::GetUnit(*me, SpineTargetGUID); + if (target && target->HasAura(SPELL_IMPALING_SPINE)) + target->RemoveAurasDueToSpell(SPELL_IMPALING_SPINE); + SpineTargetGUID.Clear(); + return true; + } + + void ResetTimer(uint32 inc = 0) + { + events.RescheduleEvent(EVENT_NEEDLE, 10000 + inc, GCD_CAST); + events.RescheduleEvent(EVENT_SPINE, 20000 + inc, GCD_CAST); + events.RescheduleEvent(EVENT_SHIELD, 60000 + inc); + } + + void ExecuteEvent(uint32 eventId) override + { + switch (eventId) + { + case EVENT_SHIELD: + DoCast(me, SPELL_TIDAL_SHIELD, true); + ResetTimer(45000); + break; + case EVENT_BERSERK: + Talk(SAY_ENRAGE); + DoCast(me, SPELL_BERSERK, true); + events.DelayEvents(15000, GCD_YELL); + break; + case EVENT_SPINE: + { + Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 1); + + if (!target) + target = me->GetVictim(); + + if (target) + { + DoCast(target, SPELL_IMPALING_SPINE, true); + SpineTargetGUID = target->GetGUID(); + //must let target summon, otherwise you cannot click the spine + target->SummonGameObject(GO_NAJENTUS_SPINE, target->GetPositionX(), target->GetPositionY(), target->GetPositionZ(), me->GetOrientation(), 0, 0, 0, 0, 30); + Talk(SAY_NEEDLE); + events.DelayEvents(1500, GCD_CAST); + events.DelayEvents(15000, GCD_YELL); + } + events.ScheduleEvent(EVENT_SPINE, 21000, GCD_CAST); + return; + } + case EVENT_NEEDLE: + { + //DoCast(me, SPELL_NEEDLE_SPINE, true); + std::list<Unit*> targets; + SelectTargetList(targets, 3, SELECT_TARGET_RANDOM, 80, true); + for (std::list<Unit*>::const_iterator i = targets.begin(); i != targets.end(); ++i) + DoCast(*i, 39835, true); + events.ScheduleEvent(EVENT_NEEDLE, urand(15000, 25000), GCD_CAST); + events.DelayEvents(1500, GCD_CAST); + return; + } + case EVENT_YELL: + Talk(SAY_SPECIAL); + events.ScheduleEvent(EVENT_YELL, urand(25000, 100000), GCD_YELL); + events.DelayEvents(15000, GCD_YELL); + break; + default: + break; + } + } + + private: + ObjectGuid SpineTargetGUID; + }; + + CreatureAI* GetAI(Creature* creature) const override + { + return GetBlackTempleAI<boss_najentusAI>(creature); + } +}; + +class go_najentus_spine : public GameObjectScript +{ +public: + go_najentus_spine() : GameObjectScript("go_najentus_spine") { } + + bool OnGossipHello(Player* player, GameObject* go) override + { + if (InstanceScript* instance = go->GetInstanceScript()) + if (Creature* Najentus = ObjectAccessor::GetCreature(*go, instance->GetGuidData(DATA_HIGH_WARLORD_NAJENTUS))) + if (ENSURE_AI(boss_najentus::boss_najentusAI, Najentus->AI())->RemoveImpalingSpine()) + { + player->CastSpell(player, SPELL_CREATE_NAJENTUS_SPINE, true); + go->Delete(); + } + return true; + } + +}; + +void AddSC_boss_najentus() +{ + new boss_najentus(); + new go_najentus_spine(); +} diff --git a/src/server/scripts/Spells/spell_dk.cpp b/src/server/scripts/Spells/spell_dk.cpp index 96ced5c7017..00071c4804e 100644 --- a/src/server/scripts/Spells/spell_dk.cpp +++ b/src/server/scripts/Spells/spell_dk.cpp @@ -87,7 +87,7 @@ class spell_dk_anti_magic_shell : public SpellScriptLoader PrepareAuraScript(spell_dk_anti_magic_shell_AuraScript); public: - spell_dk_anti_magic_shell_AuraScript() + spell_dk_anti_magic_shell_AuraScript() { absorbPct = 0; maxHealth = 0; |