TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Packet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 
23 namespace WorldPackets
24 {
26  {
27  public:
28  Packet(WorldPacket&& worldPacket) : _worldPacket(std::move(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 
46  class ServerPacket : public Packet
47  {
48  public:
49  ServerPacket(OpcodeServer opcode, size_t initialSize = 200, ConnectionType connection = CONNECTION_TYPE_DEFAULT) : Packet(WorldPacket(opcode, initialSize, connection)) { }
50 
51  void Read() override final { ASSERT(!"Read not implemented for server packets."); }
52 
53  void Clear() { _worldPacket.clear(); }
54  WorldPacket&& Move() { return std::move(_worldPacket); }
55 
57  };
58 
59  class ClientPacket : public Packet
60  {
61  public:
62  ClientPacket(WorldPacket&& packet) : Packet(std::move(packet)) { }
63  ClientPacket(OpcodeClient expectedOpcode, WorldPacket&& packet) : Packet(std::move(packet)) { ASSERT(GetOpcode() == expectedOpcode); }
64 
65  WorldPacket const* Write() override final
66  {
67  ASSERT(!"Write not allowed for client packets.");
68  // Shut up some compilers
69  return nullptr;
70  }
71 
73  };
74 }
75 
76 #endif // PacketBaseWorld_h__
ConnectionType GetConnection() const
Definition: Packet.h:40
ServerPacket(OpcodeServer opcode, size_t initialSize=200, ConnectionType connection=CONNECTION_TYPE_DEFAULT)
Definition: Packet.h:49
STL namespace.
uint32 GetOpcode() const
Definition: WorldPacket.h:79
WorldPacket _worldPacket
Definition: Packet.h:43
void Clear()
Definition: Packet.h:53
Definition: Packet.h:59
OpcodeServer GetOpcode() const
Definition: Packet.h:56
OpcodeServer
Definition: Opcodes.h:725
Definition: Packet.h:46
Definition: Packet.h:25
void Read() overridefinal
Definition: Packet.h:51
WorldPacket const * GetRawPacket() const
Definition: Packet.h:38
Vector2int16 & operator=(const Any &a)
OpcodeClient GetOpcode() const
Definition: Packet.h:72
Definition: BattlegroundMgr.h:57
size_t GetSize() const
Definition: Packet.h:39
#define TC_GAME_API
Definition: Define.h:134
#define ASSERT
Definition: Errors.h:55
OpcodeClient
Definition: Opcodes.h:46
ClientPacket(WorldPacket &&packet)
Definition: Packet.h:62
ClientPacket(OpcodeClient expectedOpcode, WorldPacket &&packet)
Definition: Packet.h:63
void clear()
Definition: ByteBuffer.h:134
Definition: WorldPacket.h:26
Packet(WorldPacket &&worldPacket)
Definition: Packet.h:28
ConnectionType
Definition: Opcodes.h:29
Definition: Opcodes.h:35
WorldPacket && Move()
Definition: Packet.h:54
WorldPacket const * Write() overridefinal
Definition: Packet.h:65