Leviathan  0.8.0.0
Leviathan game engine
GameSpecificPacketHandler.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2016 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 #include "../Common/SFMLPackets.h"
7 #include <memory>
8 
9 namespace Leviathan{
10 
13  public:
16 
20  };
21 
24  public:
27 
28 
32  };
33 
34 
37  public:
41 
44  bool IsRequest;
45 
48 
51 
57  };
58 
61  public:
62  DLLEXPORT BaseGameSpecificPacketFactory(int typenumber, bool isrequesttype);
64 
67  DLLEXPORT virtual bool SerializeToPacket(GameSpecificPacketData* data, sf::Packet &packet) = 0;
70  DLLEXPORT virtual std::shared_ptr<GameSpecificPacketData>
71  UnSerializeObjectFromPacket(sf::Packet &packet) = 0;
72 
77  };
78 
81  public:
84 
85 
87  sf::Packet &packet);
88 
89  DLLEXPORT std::shared_ptr<GameSpecificPacketData> ReadGameSpecificPacketFromPacket(
90  bool responsepacket, sf::Packet &packet);
91 
94 
95 
97  protected:
98 
99  std::shared_ptr<BaseGameSpecificPacketFactory> _FindFactoryForType(int typenumber,
100  bool requesttype);
101 
102  void _CheckVectorSorting();
103  // ------------------------------------ //
104 
107  std::vector<std::shared_ptr<BaseGameSpecificPacketFactory>> AllPacketFactories;
108 
111 
112 
114  };
115 
116 }
117 
118 #ifdef LEAK_INTO_GLOBAL
120 #endif
121 
virtual DLLEXPORT bool SerializeToPacket(GameSpecificPacketData *data, sf::Packet &packet)=0
Function for factories to pass their object data to a packet when requested.
Base class for all user defined response packets.
virtual DLLEXPORT std::shared_ptr< GameSpecificPacketData > UnSerializeObjectFromPacket(sf::Packet &packet)=0
Called when a factory needs to extract data from a packet.
static DLLEXPORT GameSpecificPacketHandler * Get()
DLLEXPORT GameSpecificPacketHandler(NetworkInterface *usetoreport)
bool HandlesRequests
Specifies are the TypeIDNumbers corresponding to request or response packets.
DLLEXPORT std::shared_ptr< GameSpecificPacketData > ReadGameSpecificPacketFromPacket(bool responsepacket, sf::Packet &packet)
BaseGameSpecificResponsePacket * ResponseBaseData
Base object pointer if this wasn&#39;t a request.
BaseGameSpecificRequestPacket * RequestBaseData
Base object pointer if this is a request.
DLLEXPORT void PassGameSpecificDataToPacket(GameSpecificPacketData *datatosend, sf::Packet &packet)
Handles construction of all game specific packets.
int TypeIDNumber
The integer identifying when this factory needs to be used.
DLLEXPORT GameSpecificPacketData(BaseGameSpecificResponsePacket *newddata)
std::shared_ptr< BaseGameSpecificPacketFactory > _FindFactoryForType(int typenumber, bool requesttype)
std::vector< std::shared_ptr< BaseGameSpecificPacketFactory > > AllPacketFactories
Stores a list of custom type factories.
Base class that is passed to the list of type handlers to GameSpecificPacketHandler.
#define DLLEXPORT
Definition: Include.h:115
Class that contains all data associated with a game specific packet.
static GameSpecificPacketHandler * Staticaccess
bool IsVectorSorted
Marks whether or not the vector is indexed.
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT BaseGameSpecificPacketFactory(int typenumber, bool isrequesttype)
Class that encapsulates common networking functionality that is required by all networked programs...
Base class for all user defined request packets.
DLLEXPORT void RegisterNewTypeFactory(BaseGameSpecificPacketFactory *newdfactoryobject)
Adds a new type that can be handled.