feat(Core/Packets): Port packet handling from TrinityCore (#5617)

* feat(Core/Packets): Port packet handling from TrinityCore

* 1

* 2

* 3

* 1

* 2

* #3670

* 3

* 1

* codestyle

* fix msvc warnings
This commit is contained in:
Kargatum
2021-05-22 05:10:46 +07:00
committed by GitHub
parent 537ebe87aa
commit 63a273507c
29 changed files with 2768 additions and 1868 deletions

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-AGPL3
* Copyright (C) 2021+ WarheadCore <https://github.com/WarheadCore>
*/
#ifndef PacketBaseWorld_h__
#define PacketBaseWorld_h__
#include "WorldPacket.h"
namespace WorldPackets
{
class AC_GAME_API Packet
{
public:
Packet(WorldPacket&& worldPacket);
virtual ~Packet() = default;
Packet(Packet const& right) = delete;
Packet& operator=(Packet const& right) = delete;
virtual WorldPacket const* Write() = 0;
virtual void Read() = 0;
WorldPacket const* GetRawPacket() const { return &_worldPacket; }
size_t GetSize() const { return _worldPacket.size(); }
protected:
WorldPacket _worldPacket;
};
class AC_GAME_API ServerPacket : public Packet
{
public:
ServerPacket(OpcodeServer opcode, size_t initialSize = 200);
void Read() final;
void Clear() { _worldPacket.clear(); }
WorldPacket&& Move() { return std::move(_worldPacket); }
void ShrinkToFit() { _worldPacket.shrink_to_fit(); }
OpcodeServer GetOpcode() const { return OpcodeServer(_worldPacket.GetOpcode()); }
};
class AC_GAME_API ClientPacket : public Packet
{
public:
ClientPacket(WorldPacket&& packet);
ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet);
WorldPacket const* Write() final;
OpcodeClient GetOpcode() const { return OpcodeClient(_worldPacket.GetOpcode()); }
};
}
#endif // PacketBaseWorld_h__