Leviathan  0.8.0.0
Leviathan game engine
NetworkResponse.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"
8 #include "CommonNetwork.h"
10 #include "Exceptions.h"
11 
13 
14 #include <memory>
15 
16 namespace Leviathan{
17 
20 
22  Connect,
23 
26  Security,
27 
30 
34 
36  Keepalive,
37 
41 
43 
45 
47 
50 
53 
70 
73 
77 
80 
83 
86 
89 
92 
99 
102 
104  CacheUpdated,
105 
107  CacheRemoved,
108 
112 
114  WorldFrozen,
115 
118 
121 
124  Custom,
125 
127  None
128 };
129 
130 
136 public:
137 
139  Type(type), ResponseID(responseid)
140  {
141  LEVIATHAN_ASSERT(responseid != static_cast<uint32_t>(-1),
142  "Response should use 0 if in response to anything");
143  }
144 
145  virtual ~NetworkResponse(){};
146 
147  inline void AddDataToPacket(sf::Packet &packet) const{
148 
149  packet << static_cast<uint16_t>(Type) << ResponseID;
150 
151  _SerializeCustom(packet);
152  }
153 
155 
156  return Type;
157  }
158 
159  inline auto GetResponseID() const {
160  return ResponseID;
161  }
162 
163  DLLEXPORT static std::shared_ptr<NetworkResponse> LoadFromPacket(sf::Packet &packet);
164 
167  DLLEXPORT static void LimitResponseSize(ResponseIdentification &response,
168  uint32_t maxsize);
169 
170 protected:
171 
173  DLLEXPORT virtual void _SerializeCustom(sf::Packet &packet) const = 0;
174 
177 
178  const uint32_t ResponseID = 0;
179 };
180 
183 public:
185  std::shared_ptr<GameSpecificPacketData> actualresponse) :
187  ActualResponse(actualresponse)
188  {}
189 
190  void _SerializeCustom(sf::Packet &packet) const override{
191 
192  LEVIATHAN_ASSERT(0, "_SerializeCustom called on ResponseCustom");
193  }
194 
195  inline void AddDataToPacket(GameSpecificPacketHandler &handler, sf::Packet &packet){
196 
197  packet << ResponseID << static_cast<uint16_t>(Type);
198 
199  handler.PassGameSpecificDataToPacket(ActualResponse.get(), packet);
200  }
201 
203  uint32_t responseid, sf::Packet &packet) :
205  {
206  ActualResponse = handler.ReadGameSpecificPacketFromPacket(true, packet);
207  if(!ActualResponse){
208 
209  throw InvalidArgument("invalid packet format for user defined response");
210  }
211  }
212 
213  std::shared_ptr<GameSpecificPacketData> ActualResponse;
214 };
215 
220 public:
221  ResponseNone(NETWORK_RESPONSE_TYPE actualtype, uint32_t responseid = 0) :
222  NetworkResponse(actualtype, responseid)
223  {}
224 
225  void _SerializeCustom(sf::Packet &packet) const override{
226  }
227 
228  ResponseNone(NETWORK_RESPONSE_TYPE actualtype, uint32_t responseid, sf::Packet &packet) :
229  NetworkResponse(actualtype, responseid)
230  {
231  }
232 
233 };
234 
235 
236 // This file is generated by the script GenerateResponse.rb
237 // and contains implementations for all the response types
238 #include "../Generated/ResponseImpl.h"
239 
240 }
241 
242 #ifdef LEAK_INTO_GLOBAL
244 #endif
245 
Used for BaseGameSpecificResponsePacket storing.
Only one side of the connection can send this request, usually the client.
All values above this are application specific types.
ResponseCustom(GameSpecificPacketHandler &handler, uint32_t responseid, sf::Packet &packet)
void AddDataToPacket(sf::Packet &packet) const
NetworkResponse(NETWORK_RESPONSE_TYPE type, uint32_t responseid)
DLLEXPORT std::shared_ptr< GameSpecificPacketData > ReadGameSpecificPacketFromPacket(bool responsepacket, sf::Packet &packet)
ResponseNone(NETWORK_RESPONSE_TYPE actualtype, uint32_t responseid, sf::Packet &packet)
Contains an updated cache variable.
Sent by a server when a request is allowed.
NETWORK_RESPONSE_TYPE
Defines the type of response that the packet contains.
Sends a update/new SyncedValue.
NETWORK_RESPONSE_TYPE GetType() const
Client sents this when they want input to be destroyed.
Sent when the server changes physics frozen state.
Empty response, used for keeping alive/nothing.
Contains (list) an ID for entity to be deleted.
const NETWORK_RESPONSE_TYPE Type
Type of response. Specifies which subclass this object is.
unsigned short uint16_t
Definition: core.h:39
void _SerializeCustom(sf::Packet &packet) const override
Base classes serialize their data.
ResponseCustom(uint32_t responseid, std::shared_ptr< GameSpecificPacketData > actualresponse)
Contains the name of a removed cache variable.
Contains SyncedResource update notification.
DLLEXPORT void PassGameSpecificDataToPacket(GameSpecificPacketData *datatosend, sf::Packet &packet)
Handles construction of all game specific packets.
std::shared_ptr< GameSpecificPacketData > ActualResponse
void _SerializeCustom(sf::Packet &packet) const override
Base classes serialize their data.
#define DLLEXPORT
Definition: Include.h:118
Contains control state updates regarding a NetworkedInput.
Empty keep alive response.
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
unsigned int uint32_t
Definition: core.h:40
Marks that the client is required to send heartbeats.
ResponseNone(NETWORK_RESPONSE_TYPE actualtype, uint32_t responseid=0)
void AddDataToPacket(GameSpecificPacketHandler &handler, sf::Packet &packet)
Sent by a server when it disallows a made request.
A new entity was created on the server.
Sent in response to a NETWORK_REQUEST_TYPE::Connect.