Skip to content
Permalink
Browse files

Core/PacketIO: convert some packets to to new packet class (#24100)

* Core/PacketIO: updated SMSG_INVALIDATE_PLAYER, SMSG_BINDER_CONFIRM, SMSG_BIND_POINT_UPDATE, SMSG_PLAYER_BOUND and SMSG_LOGIN_SET_TIME_SPEED

* small corrections
  • Loading branch information
ForesterDev committed Feb 1, 2020
1 parent a9e5347 commit ba1e5cd4134af429635068f323a2179c57a3c5eb
@@ -19,6 +19,7 @@
#include "ArenaTeam.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "MiscPackets.h"
#include "Player.h"
#include "Timer.h"
#include "World.h"
@@ -130,9 +131,8 @@ void CharacterCache::UpdateCharacterData(ObjectGuid const& guid, std::string con
if (race)
itr->second.Race = *race;

WorldPacket data(SMSG_INVALIDATE_PLAYER, 8);
data << guid;
sWorld->SendGlobalMessage(&data);
WorldPackets::Misc::InvalidatePlayer packet(guid);
sWorld->SendGlobalMessage(packet.Write());

// Correct name -> pointer storage
_characterCacheByNameStore.erase(oldName);
@@ -62,6 +62,7 @@
#include "LootMgr.h"
#include "Mail.h"
#include "MapManager.h"
#include "MiscPackets.h"
#include "MotionMaster.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
@@ -9440,9 +9441,8 @@ uint32 Player::GetXPRestBonus(uint32 xp)

void Player::SetBindPoint(ObjectGuid guid) const
{
WorldPacket data(SMSG_BINDER_CONFIRM, 8);
data << uint64(guid);
SendDirectMessage(&data);
WorldPackets::Misc::BinderConfirm packet(guid);
SendDirectMessage(packet.Write());
}

void Player::SendTalentWipeConfirm(ObjectGuid guid) const
CharacterDatabase.Execute(stmt);
}

void Player::SendBindPointUpdate()
{
WorldPackets::Misc::BindPointUpdate packet;
packet.BindPosition = Position(m_homebindX, m_homebindY, m_homebindZ);
packet.BindMapID = m_homebindMapId;
packet.BindAreaID = m_homebindAreaId;
SendDirectMessage(packet.Write());
}

uint32 Player::GetUInt32ValueFromArray(Tokenizer const& data, uint16 index)
{
if (index >= data.size())
void Player::SendInitialPacketsBeforeAddToMap()
{
/// Pass 'this' as argument because we're not stored in ObjectAccessor yet
/// SMSG_CONTACT_LIST
GetSocial()->SendSocialList(this, SOCIAL_FLAG_ALL);

// guild bank list wtf?

// Homebind
WorldPacket data(SMSG_BINDPOINTUPDATE, 5*4);
data << m_homebindX << m_homebindY << m_homebindZ;
data << (uint32) m_homebindMapId;
data << (uint32) m_homebindAreaId;
SendDirectMessage(&data);
/// SMSG_BINDPOINTUPDATE
SendBindPointUpdate();

// SMSG_SET_PROFICIENCY
// SMSG_SET_PCT_SPELL_MODIFIER
// SMSG_SET_FLAT_SPELL_MODIFIER
// SMSG_UPDATE_AURA_DURATION

/// SMSG_TALENTS_INFO
SendTalentsInfoData(false);

// SMSG_INSTANCE_DIFFICULTY
data.Initialize(SMSG_INSTANCE_DIFFICULTY, 4+4);
/// SMSG_INSTANCE_DIFFICULTY
WorldPacket data(SMSG_INSTANCE_DIFFICULTY, 4+4);
data << uint32(GetMap()->GetDifficulty());
data << uint32(GetMap()->GetEntry()->IsDynamicDifficultyMap() && GetMap()->IsHeroic()); // Raid dynamic difficulty
SendDirectMessage(&data);

/// SMSG_INITIAL_SPELLS
SendInitialSpells();
/// SMSG_SEND_UNLEARN_SPELLS
SendUnlearnSpells();

/// SMSG_ACTION_BUTTONS
SendInitialActionButtons();

/// SMSG_INITIALIZE_FACTIONS
m_reputationMgr->SendInitialReputations();

/// SMSG_ALL_ACHIEVEMENT_DATA
m_achievementMgr->SendAllAchievementData();

/// SMSG_EQUIPMENT_SET_LIST
SendEquipmentSetList();

data.Initialize(SMSG_LOGIN_SETTIMESPEED, 4 + 4 + 4);
data.AppendPackedTime(GameTime::GetGameTime());
data << float(0.01666667f); // game speed
data << uint32(0); // added in 3.1.2
SendDirectMessage(&data);
/// SMSG_LOGIN_SET_TIME_SPEED
static float const TimeSpeed = 0.01666667f;
WorldPackets::Misc::LoginSetTimeSpeed loginSetTimeSpeed;
loginSetTimeSpeed.NewSpeed = TimeSpeed;
loginSetTimeSpeed.GameTime = GameTime::GetGameTime();
loginSetTimeSpeed.GameTimeHolidayOffset = 0; /// @todo
SendDirectMessage(loginSetTimeSpeed.Write());

GetReputationMgr().SendForceReactions(); // SMSG_SET_FORCED_REACTIONS
/// SMSG_SET_FORCED_REACTIONS
GetReputationMgr().SendForceReactions();

// SMSG_TALENTS_INFO x 2 for pet (unspent points and talents in separate packets...)
// SMSG_PET_GUIDS
// SMSG_UPDATE_WORLD_STATE
// SMSG_POWER_UPDATE

/// SMSG_RESYNC_RUNES
ResyncRunes();

SetMovedUnit(this);
@@ -1983,6 +1983,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
void Recall() { TeleportTo(m_recall_location); }

void SetHomebind(WorldLocation const& loc, uint32 areaId);
void SendBindPointUpdate();

// Homebind coordinates
uint32 m_homebindMapId;
@@ -17,6 +17,46 @@

#include "MiscPackets.h"

WorldPacket const* WorldPackets::Misc::BindPointUpdate::Write()
{
_worldPacket << BindPosition;
_worldPacket << uint32(BindMapID);
_worldPacket << uint32(BindAreaID);

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::PlayerBound::Write()
{
_worldPacket << BinderID;
_worldPacket << uint32(AreaID);

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::BinderConfirm::Write()
{
_worldPacket << Unit;

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::InvalidatePlayer::Write()
{
_worldPacket << Guid;

return &_worldPacket;
}

WorldPacket const* WorldPackets::Misc::LoginSetTimeSpeed::Write()
{
_worldPacket.AppendPackedTime(GameTime);
_worldPacket << float(NewSpeed);
_worldPacket << uint32(GameTimeHolidayOffset);

return &_worldPacket;
}

WorldPackets::Misc::Weather::Weather() : ServerPacket(SMSG_WEATHER, 4 + 4 + 1) { }

WorldPackets::Misc::Weather::Weather(WeatherState weatherID, float intensity /*= 0.0f*/, bool abrupt /*= false*/)
@@ -19,6 +19,7 @@
#define MiscPackets_h__

#include "Packet.h"
#include "Position.h"
#include "ObjectGuid.h"
#include "Weather.h"

@@ -28,6 +29,64 @@ namespace WorldPackets
{
namespace Misc
{
class BindPointUpdate final : public ServerPacket
{
public:
BindPointUpdate() : ServerPacket(SMSG_BIND_POINT_UPDATE, 20) { }

WorldPacket const* Write() override;

uint32 BindMapID = 0;
TaggedPosition<Position::XYZ> BindPosition;
uint32 BindAreaID = 0;
};

class PlayerBound final : public ServerPacket
{
public:
PlayerBound() : ServerPacket(SMSG_PLAYER_BOUND, 8 + 4) { }
PlayerBound(ObjectGuid binderId, uint32 areaId) : ServerPacket(SMSG_PLAYER_BOUND, 8 + 4), BinderID(binderId), AreaID(areaId) { }

WorldPacket const* Write() override;

ObjectGuid BinderID;
uint32 AreaID = 0;
};

class BinderConfirm final : public ServerPacket
{
public:
BinderConfirm() : ServerPacket(SMSG_BINDER_CONFIRM, 8) { }
BinderConfirm(ObjectGuid unit) : ServerPacket(SMSG_BINDER_CONFIRM, 8), Unit(unit) { }

WorldPacket const* Write() override;

ObjectGuid Unit;
};

class InvalidatePlayer final : public ServerPacket
{
public:
InvalidatePlayer() : ServerPacket(SMSG_INVALIDATE_PLAYER, 8) { }
InvalidatePlayer(ObjectGuid guid) : ServerPacket(SMSG_INVALIDATE_PLAYER, 8), Guid(guid) { }

WorldPacket const* Write() override;

ObjectGuid Guid;
};

class LoginSetTimeSpeed final : public ServerPacket
{
public:
LoginSetTimeSpeed() : ServerPacket(SMSG_LOGIN_SET_TIME_SPEED, 12) { }

WorldPacket const* Write() override;

float NewSpeed = 0.0f;
uint32 GameTime = 0;
int32 GameTimeHolidayOffset = 0;
};

class TC_GAME_API Weather final : public ServerPacket
{
public:
@@ -194,7 +194,7 @@ void OpcodeTable::Initialize()
/*0x03F*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_TRANSFER_PENDING, STATUS_NEVER);
/*0x040*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_TRANSFER_ABORTED, STATUS_NEVER);
/*0x041*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_CHARACTER_LOGIN_FAILED, STATUS_NEVER);
/*0x042*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOGIN_SETTIMESPEED, STATUS_NEVER);
/*0x042*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_LOGIN_SET_TIME_SPEED, STATUS_NEVER);
/*0x043*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_GAMETIME_UPDATE, STATUS_NEVER);
/*0x044*/ DEFINE_HANDLER(CMSG_GAMETIME_SET, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
/*0x045*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_GAMETIME_SET, STATUS_NEVER);
@@ -469,10 +469,10 @@ void OpcodeTable::Initialize()
/*0x152*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_BREAK_TARGET, STATUS_NEVER);
/*0x153*/ DEFINE_HANDLER(CMSG_SAVE_PLAYER, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
/*0x154*/ DEFINE_HANDLER(CMSG_SETDEATHBINDPOINT, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
/*0x155*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_BINDPOINTUPDATE, STATUS_NEVER);
/*0x155*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_BIND_POINT_UPDATE, STATUS_NEVER);
/*0x156*/ DEFINE_HANDLER(CMSG_GETDEATHBINDZONE, STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL );
/*0x157*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_BINDZONEREPLY, STATUS_NEVER);
/*0x158*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_PLAYERBOUND, STATUS_NEVER);
/*0x158*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_PLAYER_BOUND, STATUS_NEVER);
/*0x159*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_CLIENT_CONTROL_UPDATE, STATUS_NEVER);
/*0x15A*/ DEFINE_HANDLER(CMSG_REPOP_REQUEST, STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleRepopRequestOpcode );
/*0x15B*/ DEFINE_SERVER_OPCODE_HANDLER(SMSG_RESURRECT_REQUEST, STATUS_NEVER);
@@ -92,7 +92,7 @@ enum Opcodes : uint16
SMSG_TRANSFER_PENDING = 0x03F,
SMSG_TRANSFER_ABORTED = 0x040,
SMSG_CHARACTER_LOGIN_FAILED = 0x041,
SMSG_LOGIN_SETTIMESPEED = 0x042,
SMSG_LOGIN_SET_TIME_SPEED = 0x042,
SMSG_GAMETIME_UPDATE = 0x043,
CMSG_GAMETIME_SET = 0x044,
SMSG_GAMETIME_SET = 0x045,
@@ -367,10 +367,10 @@ enum Opcodes : uint16
SMSG_BREAK_TARGET = 0x152,
CMSG_SAVE_PLAYER = 0x153,
CMSG_SETDEATHBINDPOINT = 0x154,
SMSG_BINDPOINTUPDATE = 0x155,
SMSG_BIND_POINT_UPDATE = 0x155,
CMSG_GETDEATHBINDZONE = 0x156,
SMSG_BINDZONEREPLY = 0x157,
SMSG_PLAYERBOUND = 0x158,
SMSG_PLAYER_BOUND = 0x158,
SMSG_CLIENT_CONTROL_UPDATE = 0x159,
CMSG_REPOP_REQUEST = 0x15A,
SMSG_RESURRECT_REQUEST = 0x15B,
@@ -5407,22 +5407,14 @@ void Spell::EffectBind(SpellEffIndex effIndex)
homeLoc = player->GetWorldLocation();

player->SetHomebind(homeLoc, areaId);

// binding
WorldPacket data(SMSG_BINDPOINTUPDATE, 4 * 3 + 4 + 4);
data << TaggedPosition<Position::XYZ>(homeLoc);
data << uint32(homeLoc.GetMapId());
data << uint32(areaId);
player->SendDirectMessage(&data);
player->SendBindPointUpdate();

TC_LOG_DEBUG("spells", "EffectBind: New homebind X: %f, Y: %f, Z: %f, MapId: %u, AreaId: %u",
homeLoc.GetPositionX(), homeLoc.GetPositionY(), homeLoc.GetPositionZ(), homeLoc.GetMapId(), areaId);

// zone update
data.Initialize(SMSG_PLAYERBOUND, 8 + 4);
data << uint64(m_caster->GetGUID());
data << uint32(areaId);
player->SendDirectMessage(&data);
WorldPackets::Misc::PlayerBound packet(m_caster->GetGUID(), areaId);
player->SendDirectMessage(packet.Write());
}

void Spell::EffectSummonRaFFriend(SpellEffIndex effIndex)

0 comments on commit ba1e5cd

Please sign in to comment.
You can’t perform that action at this time.