refactor(Core/Packet): Character packets (#9546)

* Character

* Update CharacterHandler.cpp
This commit is contained in:
IntelligentQuantum
2022-01-06 15:25:00 +03:30
committed by GitHub
parent 43ea4aa2df
commit 93322bcb4d
8 changed files with 228 additions and 51 deletions

View File

@@ -18,6 +18,7 @@
#ifndef AllPackets_h__
#define AllPackets_h__
#include "CharacterPackets.h"
#include "MiscPackets.h"
#include "WorldStatePackets.h"
#include "TotemPackets.h"

View File

@@ -0,0 +1,49 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 "CharacterPackets.h"
void WorldPackets::Character::ShowingCloak::Read()
{
_worldPacket >> ShowCloak;
}
void WorldPackets::Character::ShowingHelm::Read()
{
_worldPacket >> ShowHelm;
}
WorldPacket const* WorldPackets::Character::LogoutResponse::Write()
{
_worldPacket << uint32(LogoutResult);
_worldPacket << uint8(Instant);
return &_worldPacket;
}
void WorldPackets::Character::PlayedTimeClient::Read()
{
_worldPacket >> TriggerScriptEvent;
}
WorldPacket const* WorldPackets::Character::PlayedTime::Write()
{
_worldPacket << uint32(TotalTime);
_worldPacket << uint32(LevelTime);
_worldPacket << uint8(TriggerScriptEvent);
return &_worldPacket;
}

View File

@@ -0,0 +1,122 @@
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by the
* Free Software Foundation; either version 3 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 Affero 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 CharacterPackets_h__
#define CharacterPackets_h__
#include "Packet.h"
namespace WorldPackets
{
namespace Character
{
class ShowingCloak final : public ClientPacket
{
public:
ShowingCloak(WorldPacket&& packet) : ClientPacket(CMSG_SHOWING_CLOAK, std::move(packet)) { }
void Read() override;
bool ShowCloak = false;
};
class ShowingHelm final : public ClientPacket
{
public:
ShowingHelm(WorldPacket&& packet) : ClientPacket(CMSG_SHOWING_HELM, std::move(packet)) { }
void Read() override;
bool ShowHelm = false;
};
class LogoutRequest final : public ClientPacket
{
public:
LogoutRequest(WorldPacket&& packet) : ClientPacket(std::move(packet)) { }
void Read() override { }
};
class LogoutResponse final : public ServerPacket
{
public:
LogoutResponse() : ServerPacket(SMSG_LOGOUT_RESPONSE, 4 + 1) { }
WorldPacket const* Write() override;
uint32 LogoutResult = 0;
bool Instant = false;
};
class LogoutComplete final : public ServerPacket
{
public:
LogoutComplete() : ServerPacket(SMSG_LOGOUT_COMPLETE, 0) { }
WorldPacket const* Write() override { return &_worldPacket; }
};
class LogoutCancel final : public ClientPacket
{
public:
LogoutCancel(WorldPacket&& packet) : ClientPacket(std::move(packet)) { }
void Read() override { }
};
class LogoutCancelAck final : public ServerPacket
{
public:
LogoutCancelAck() : ServerPacket(SMSG_LOGOUT_CANCEL_ACK, 0) { }
WorldPacket const* Write() override { return &_worldPacket; }
};
class PlayerLogout final : public ClientPacket
{
public:
PlayerLogout(WorldPacket&& packet) : ClientPacket(std::move(packet)) { }
void Read() override { }
};
class PlayedTimeClient final : public ClientPacket
{
public:
PlayedTimeClient(WorldPacket&& packet) : ClientPacket(CMSG_PLAYED_TIME, std::move(packet)) { }
void Read() override;
bool TriggerScriptEvent = false;
};
class PlayedTime final : public ServerPacket
{
public:
PlayedTime() : ServerPacket(SMSG_PLAYED_TIME, 9) { }
WorldPacket const* Write() override;
uint32 TotalTime = 0;
uint32 LevelTime = 0;
bool TriggerScriptEvent = false;
};
}
}
#endif // CharacterPackets_h__

View File

@@ -22,6 +22,7 @@
#include "WorldSession.h"
#include "AccountMgr.h"
#include "BattlegroundMgr.h"
#include "CharacterPackets.h"
#include "Common.h"
#include "DatabaseEnv.h"
#include "Group.h"
@@ -687,8 +688,7 @@ void WorldSession::LogoutPlayer(bool save)
//! Send the 'logout complete' packet to the client
//! Client will respond by sending 3x CMSG_CANCEL_TRADE, which we currently dont handle
WorldPacket data(SMSG_LOGOUT_COMPLETE, 0);
SendPacket(&data);
SendPacket(WorldPackets::Character::LogoutComplete().Write());
LOG_DEBUG("network", "SESSION: Sent SMSG_LOGOUT_COMPLETE Message");
//! Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline
@@ -699,7 +699,7 @@ void WorldSession::LogoutPlayer(bool save)
m_playerLogout = false;
m_playerSave = false;
LogoutRequest(0);
SetLogoutStartTime(0);
}
/// Kick a player out of the World

View File

@@ -71,6 +71,16 @@ namespace lfg
namespace WorldPackets
{
namespace Character
{
class LogoutCancel;
class LogoutRequest;
class ShowingCloak;
class ShowingHelm;
class PlayerLogout;
class PlayedTimeClient;
}
namespace Totem
{
class TotemDestroyed;
@@ -342,7 +352,7 @@ public:
bool isLogingOut() const { return _logoutTime || m_playerLogout; }
/// Engage the logout process for the user
void LogoutRequest(time_t requestTime)
void SetLogoutStartTime(time_t requestTime)
{
_logoutTime = requestTime;
}
@@ -515,7 +525,7 @@ public: // opcodes handlers
void SendSetPlayerDeclinedNamesResult(DeclinedNameResult result, ObjectGuid guid);
// played time
void HandlePlayedTime(WorldPacket& recvPacket);
void HandlePlayedTime(WorldPackets::Character::PlayedTimeClient& packet);
// new
void HandleMoveUnRootAck(WorldPacket& recvPacket);
@@ -535,8 +545,8 @@ public: // opcodes handlers
void HandleMountSpecialAnimOpcode(WorldPacket& recvdata);
// character view
void HandleShowingHelmOpcode(WorldPacket& recvData);
void HandleShowingCloakOpcode(WorldPacket& recvData);
void HandleShowingHelmOpcode(WorldPackets::Character::ShowingHelm& packet);
void HandleShowingCloakOpcode(WorldPackets::Character::ShowingCloak& packet);
// repair
void HandleRepairItemOpcode(WorldPacket& recvPacket);
@@ -554,9 +564,9 @@ public: // opcodes handlers
void HandleLootReleaseOpcode(WorldPacket& recvPacket);
void HandleLootMasterGiveOpcode(WorldPacket& recvPacket);
void HandleWhoOpcode(WorldPacket& recvPacket);
void HandleLogoutRequestOpcode(WorldPacket& recvPacket);
void HandlePlayerLogoutOpcode(WorldPacket& recvPacket);
void HandleLogoutCancelOpcode(WorldPacket& recvPacket);
void HandleLogoutRequestOpcode(WorldPackets::Character::LogoutRequest& logoutRequest);
void HandlePlayerLogoutOpcode(WorldPackets::Character::PlayerLogout& playerLogout);
void HandleLogoutCancelOpcode(WorldPackets::Character::LogoutCancel& logoutCancel);
// GM Ticket opcodes
void HandleGMTicketCreateOpcode(WorldPacket& recvPacket);