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