TrinityCore
Packet.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef PacketBaseWorld_h__
19#define PacketBaseWorld_h__
20
21#include "WorldPacket.h"
22
23namespace WorldPackets
24{
26 {
27 public:
28 Packet(WorldPacket&& worldPacket);
29
30 virtual ~Packet() = default;
31
32 Packet(Packet const& right) = delete;
33 Packet& operator=(Packet const& right) = delete;
34
35 virtual WorldPacket const* Write() = 0;
36 virtual void Read() = 0;
37
38 WorldPacket const* GetRawPacket() const { return &_worldPacket; }
39 size_t GetSize() const { return _worldPacket.size(); }
40 ConnectionType GetConnection() const { return _worldPacket.GetConnection(); }
41
42 protected:
44 };
45
47 {
48 public:
49 ServerPacket(OpcodeServer opcode, size_t initialSize = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT);
50
51 void Read() override final;
52
53 void Clear() { _worldPacket.clear(); }
54 WorldPacket&& Move() { return std::move(_worldPacket); }
55 void ShrinkToFit() { _worldPacket.shrink_to_fit(); }
56
57 OpcodeServer GetOpcode() const { return OpcodeServer(_worldPacket.GetOpcode()); }
58 };
59
61 {
62 public:
63 ClientPacket(WorldPacket&& packet);
64 ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet);
65
66 WorldPacket const* Write() override final;
67
68 OpcodeClient GetOpcode() const { return OpcodeClient(_worldPacket.GetOpcode()); }
69 };
70
71 class Null final : public ClientPacket
72 {
73 public:
74 Null(WorldPacket&& packet) : ClientPacket(std::move(packet)) { }
75
76 void Read() override { _worldPacket.rfinish(); }
77 };
78}
79
80#endif // PacketBaseWorld_h__
#define TC_GAME_API
Definition: Define.h:123
void rfinish()
Definition: ByteBuffer.h:407
OpcodeClient GetOpcode() const
Definition: Packet.h:68
void Read() override
Definition: Packet.h:76
Null(WorldPacket &&packet)
Definition: Packet.h:74
Packet(Packet const &right)=delete
virtual ~Packet()=default
Packet & operator=(Packet const &right)=delete
size_t GetSize() const
Definition: Packet.h:39
virtual void Read()=0
ConnectionType GetConnection() const
Definition: Packet.h:40
WorldPacket const * GetRawPacket() const
Definition: Packet.h:38
WorldPacket _worldPacket
Definition: Packet.h:43
virtual WorldPacket const * Write()=0
OpcodeServer GetOpcode() const
Definition: Packet.h:57
WorldPacket && Move()
Definition: Packet.h:54
ConnectionType
Definition: Opcodes.h:29
OpcodeClient
Definition: Opcodes.h:46
OpcodeServer
Definition: Opcodes.h:901
@ CONNECTION_TYPE_DEFAULT
Definition: Opcodes.h:34
STL namespace.