TrinityCore
WorldPacket.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 TRINITYCORE_WORLDPACKET_H
19#define TRINITYCORE_WORLDPACKET_H
20
21#include "ByteBuffer.h"
22#include "Opcodes.h"
23#include "Duration.h"
24
25class WorldPacket : public ByteBuffer
26{
27 public:
28 // just container for later use
30 {
31 }
32
34 m_opcode(opcode), _connection(connection) { }
35
37 m_opcode(opcode), _connection(connection) { }
38
39 WorldPacket(uint32 opcode, size_t res, Resize, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : ByteBuffer(res, Resize{}),
40 m_opcode(opcode), _connection(connection) { }
41
42 WorldPacket(uint32 opcode, size_t res, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : WorldPacket(opcode, res, Reserve{}, connection) { }
43
44 WorldPacket(WorldPacket&& packet) noexcept : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), _connection(packet._connection), m_receivedTime(packet.m_receivedTime)
45 {
46 }
47
48 WorldPacket(WorldPacket const& right) = default;
49
51 {
52 if (this != &right)
53 {
54 m_opcode = right.m_opcode;
57 }
58
59 return *this;
60 }
61
63 {
64 if (this != &right)
65 {
66 m_opcode = right.m_opcode;
67 _connection = right._connection;
68 ByteBuffer::operator=(std::move(right));
69 }
70
71 return *this;
72 }
73
74 WorldPacket(MessageBuffer&& buffer, ConnectionType connection) : ByteBuffer(std::move(buffer)), m_opcode(UNKNOWN_OPCODE), _connection(connection) { }
75
76 void Initialize(uint32 opcode, size_t newres = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT)
77 {
78 clear();
79 _storage.reserve(newres);
80 m_opcode = opcode;
81 _connection = connection;
82 }
83
84 uint32 GetOpcode() const { return m_opcode; }
85 void SetOpcode(uint32 opcode) { m_opcode = opcode; }
86
88
90 void SetReceiveTime(TimePoint receivedTime) { m_receivedTime = receivedTime; }
91
92 protected:
95 TimePoint m_receivedTime; // only set for a specific set of opcodes, for performance reasons.
96};
97
98#endif
uint32_t uint32
Definition: Define.h:142
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition: Duration.h:41
std::vector< uint8 > _storage
Definition: ByteBuffer.h:636
ByteBuffer & operator=(ByteBuffer const &right)
Definition: ByteBuffer.h:103
void clear()
Definition: ByteBuffer.h:133
ConnectionType GetConnection() const
Definition: WorldPacket.h:87
void Initialize(uint32 opcode, size_t newres=200, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:76
uint32 m_opcode
Definition: WorldPacket.h:93
WorldPacket(WorldPacket const &right)=default
TimePoint GetReceivedTime() const
Definition: WorldPacket.h:89
void SetReceiveTime(TimePoint receivedTime)
Definition: WorldPacket.h:90
WorldPacket(uint32 opcode, size_t res, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:42
uint32 GetOpcode() const
Definition: WorldPacket.h:84
WorldPacket & operator=(WorldPacket const &right)
Definition: WorldPacket.h:50
WorldPacket(MessageBuffer &&buffer, ConnectionType connection)
Definition: WorldPacket.h:74
TimePoint m_receivedTime
Definition: WorldPacket.h:95
ConnectionType _connection
Definition: WorldPacket.h:94
WorldPacket(uint32 opcode, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:33
WorldPacket & operator=(WorldPacket &&right) noexcept
Definition: WorldPacket.h:62
WorldPacket(uint32 opcode, size_t res, Resize, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:39
void SetOpcode(uint32 opcode)
Definition: WorldPacket.h:85
WorldPacket(uint32 opcode, size_t res, Reserve, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: WorldPacket.h:36
WorldPacket(WorldPacket &&packet) noexcept
Definition: WorldPacket.h:44
ConnectionType
Definition: Opcodes.h:29
@ CONNECTION_TYPE_DEFAULT
Definition: Opcodes.h:34
@ UNKNOWN_OPCODE
Definition: Opcodes.h:41
STL namespace.