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 explicit WorldPacket(std::vector<uint8>&& buffer, ConnectionType connection) : ByteBuffer(std::move(buffer)),
44 m_opcode(UNKNOWN_OPCODE), _connection(connection) { }
45
46 WorldPacket(WorldPacket const& right) = default;
47
48 WorldPacket(WorldPacket&& packet) noexcept = default;
49
50 WorldPacket& operator=(WorldPacket const& right) = default;
51
52 WorldPacket& operator=(WorldPacket&& right) noexcept = default;
53
54 void Initialize(uint32 opcode, size_t newres = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT)
55 {
56 clear();
57 _storage.reserve(newres);
58 m_opcode = opcode;
59 _connection = connection;
60 }
61
62 uint32 GetOpcode() const { return m_opcode; }
63 void SetOpcode(uint32 opcode) { m_opcode = opcode; }
64
66
68 void SetReceiveTime(TimePoint receivedTime) { m_receivedTime = receivedTime; }
69
70 protected:
73 TimePoint m_receivedTime; // only set for a specific set of opcodes, for performance reasons.
74};
75
76#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:640
void clear()
Definition ByteBuffer.h:121
ConnectionType GetConnection() const
Definition WorldPacket.h:65
void Initialize(uint32 opcode, size_t newres=200, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition WorldPacket.h:54
uint32 m_opcode
Definition WorldPacket.h:71
WorldPacket(WorldPacket const &right)=default
TimePoint GetReceivedTime() const
Definition WorldPacket.h:67
void SetReceiveTime(TimePoint receivedTime)
Definition WorldPacket.h:68
WorldPacket(std::vector< uint8 > &&buffer, ConnectionType connection)
Definition WorldPacket.h:43
WorldPacket & operator=(WorldPacket &&right) noexcept=default
WorldPacket & operator=(WorldPacket const &right)=default
WorldPacket(uint32 opcode, size_t res, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition WorldPacket.h:41
uint32 GetOpcode() const
Definition WorldPacket.h:62
WorldPacket(WorldPacket &&packet) noexcept=default
TimePoint m_receivedTime
Definition WorldPacket.h:73
ConnectionType _connection
Definition WorldPacket.h:72
WorldPacket(uint32 opcode, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition WorldPacket.h:32
WorldPacket(uint32 opcode, size_t res, Resize, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition WorldPacket.h:38
void SetOpcode(uint32 opcode)
Definition WorldPacket.h:63
WorldPacket(uint32 opcode, size_t res, Reserve, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition WorldPacket.h:35
STL namespace.