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 "Common.h"
22#include "Opcodes.h"
23#include "ByteBuffer.h"
24#include "Duration.h"
25
26class WorldPacket : public ByteBuffer
27{
28 public:
29 // just container for later use
33
34 WorldPacket(uint16 opcode, size_t res = 200) : ByteBuffer(res),
35 m_opcode(opcode) { }
36
37 WorldPacket(WorldPacket&& packet) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode)
38 {
39 }
40
41 WorldPacket(WorldPacket&& packet, TimePoint receivedTime) : ByteBuffer(std::move(packet)), m_opcode(packet.m_opcode), m_receivedTime(receivedTime)
42 {
43 }
44
45 WorldPacket(WorldPacket const& right) : ByteBuffer(right), m_opcode(right.m_opcode)
46 {
47 }
48
50 {
51 if (this != &right)
52 {
53 m_opcode = right.m_opcode;
55 }
56
57 return *this;
58 }
59
61 {
62 if (this != &right)
63 {
64 m_opcode = right.m_opcode;
65 ByteBuffer::operator=(std::move(right));
66 }
67
68 return *this;
69 }
70
71 WorldPacket(uint16 opcode, MessageBuffer&& buffer) : ByteBuffer(std::move(buffer)), m_opcode(opcode) { }
72
73 void Initialize(uint16 opcode, size_t newres = 200)
74 {
75 clear();
76 _storage.reserve(newres);
77 m_opcode = opcode;
78 }
79
80 uint16 GetOpcode() const { return m_opcode; }
81 void SetOpcode(uint16 opcode) { m_opcode = opcode; }
82
84
85 protected:
87 TimePoint m_receivedTime; // only set for a specific set of opcodes, for performance reasons.
88};
89
90#endif
uint16_t uint16
Definition Define.h:134
std::chrono::steady_clock::time_point TimePoint
time_point shorthand typedefs
Definition Duration.h:36
std::vector< uint8 > _storage
Definition ByteBuffer.h:493
ByteBuffer & operator=(ByteBuffer const &right)
Definition ByteBuffer.h:95
void clear()
Definition ByteBuffer.h:123
WorldPacket(uint16 opcode, MessageBuffer &&buffer)
Definition WorldPacket.h:71
WorldPacket(WorldPacket const &right)
Definition WorldPacket.h:45
WorldPacket(WorldPacket &&packet, TimePoint receivedTime)
Definition WorldPacket.h:41
TimePoint GetReceivedTime() const
Definition WorldPacket.h:83
uint16 m_opcode
Definition WorldPacket.h:86
uint16 GetOpcode() const
Definition WorldPacket.h:80
WorldPacket & operator=(WorldPacket &&right)
Definition WorldPacket.h:60
WorldPacket(uint16 opcode, size_t res=200)
Definition WorldPacket.h:34
WorldPacket & operator=(WorldPacket const &right)
Definition WorldPacket.h:49
void Initialize(uint16 opcode, size_t newres=200)
Definition WorldPacket.h:73
TimePoint m_receivedTime
Definition WorldPacket.h:87
void SetOpcode(uint16 opcode)
Definition WorldPacket.h:81
WorldPacket(WorldPacket &&packet)
Definition WorldPacket.h:37
@ NULL_OPCODE
Definition Opcodes.h:1346
STL namespace.