Leviathan  0.8.0.0
Leviathan game engine
NetworkRequest.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2016 Henri Hyyryläinen
3 #pragma once
4 // ------------------------------------ //
5 #include "Define.h"
6 // ------------------------------------ //
7 #include "Common/SFMLPackets.h"
8 #include "CommonNetwork.h"
9 #include "Exceptions.h"
10 
12 
13 #include <memory>
14 
15 namespace Leviathan{
16 
18 
20  Connect,
21 
23  Security,
24 
28 
32 
34 
36 
38 
40 
43 
46  JoinServer,
47 
49 
51 
55 
58 
60  Echo,
61 
70 
72  Custom
73 };
74 
79 public:
80 
81  NetworkRequest(NETWORK_REQUEST_TYPE type, uint32_t idforresponse = 0) :
82  Type(type), IDForResponse(idforresponse)
83  {
84 
85  }
86 
87  virtual ~NetworkRequest(){};
88 
89  inline void AddDataToPacket(sf::Packet &packet) const{
90 
91  packet << static_cast<uint16_t>(Type);
92 
93  _SerializeCustom(packet);
94  }
95 
96  inline NETWORK_REQUEST_TYPE GetType() const{
97  return Type;
98  }
99 
100  inline uint32_t GetIDForResponse() const {
101  return IDForResponse;
102  }
103 
104  DLLEXPORT static std::shared_ptr<NetworkRequest> LoadFromPacket(sf::Packet &packet,
105  uint32_t messagenumber);
106 
107 protected:
108 
110  DLLEXPORT virtual void _SerializeCustom(sf::Packet &packet) const = 0;
111 
113 
114  const uint32_t IDForResponse = 0;
115 };
116 
118  public:
119  RequestCustom(std::shared_ptr<GameSpecificPacketData> actualrequest) :
121  ActualRequest(actualrequest)
122  {}
123 
124  void _SerializeCustom(sf::Packet &packet) const override{
125 
126  LEVIATHAN_ASSERT(0, "_SerializeCustom called on RequestCustom");
127  }
128 
129  RequestCustom(GameSpecificPacketHandler &handler, sf::Packet &packet) :
131  {
132  ActualRequest = handler.ReadGameSpecificPacketFromPacket(false, packet);
133 
134  if(!ActualRequest){
135 
136  throw InvalidArgument("invalid packet format for user defined request");
137  }
138  }
139 
140  inline void AddDataToPacket(GameSpecificPacketHandler &handler, sf::Packet &packet){
141 
142  packet << static_cast<uint16_t>(Type);
143 
144  handler.PassGameSpecificDataToPacket(ActualRequest.get(), packet);
145  }
146 
147  std::shared_ptr<GameSpecificPacketData> ActualRequest;
148 };
149 
153 class RequestNone : public NetworkRequest {
154 public:
156  NetworkRequest(actualtype)
157  {}
158 
159  void _SerializeCustom(sf::Packet &packet) const override{
160  }
161 
162  RequestNone(NETWORK_REQUEST_TYPE actualtype, uint32_t idforresponse, sf::Packet &packet) :
163  NetworkRequest(actualtype, idforresponse)
164  {
165  }
166 };
167 
168 
169 
170 // This file is generated by the script GenerateRequest.rb
171 // and contains implementations for all the response types
172 #include "../Generated/RequestImpl.h"
173 
174 
175 }
176 
177 #ifdef LEAK_INTO_GLOBAL
179 #endif
180 
NETWORK_REQUEST_TYPE GetType() const
Only one side of the connection can send this request, usually the client.
void _SerializeCustom(sf::Packet &packet) const override
Base classes serialize their data.
All values above this are application specific types.
RequestCustom(std::shared_ptr< GameSpecificPacketData > actualrequest)
Sent when a player requests the server to connect a NetworkedInput.
DLLEXPORT std::shared_ptr< GameSpecificPacketData > ReadGameSpecificPacketFromPacket(bool responsepacket, sf::Packet &packet)
void AddDataToPacket(GameSpecificPacketHandler &handler, sf::Packet &packet)
RequestNone(NETWORK_REQUEST_TYPE actualtype, uint32_t idforresponse, sf::Packet &packet)
void AddDataToPacket(sf::Packet &packet) const
const NETWORK_REQUEST_TYPE Type
RequestCustom(GameSpecificPacketHandler &handler, sf::Packet &packet)
The receiving side is now allowed to open a remote console with the token.
uint32_t GetIDForResponse() const
unsigned short uint16_t
Definition: core.h:39
DLLEXPORT void PassGameSpecificDataToPacket(GameSpecificPacketData *datatosend, sf::Packet &packet)
Handles construction of all game specific packets.
Empty request for ones that require no data.
Sent by servers to ping (time the time a client takes to respond) clients.
#define DLLEXPORT
Definition: Include.h:118
std::shared_ptr< GameSpecificPacketData > ActualRequest
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
void _SerializeCustom(sf::Packet &packet) const override
Base classes serialize their data.
unsigned int uint32_t
Definition: core.h:40
RequestNone(NETWORK_REQUEST_TYPE actualtype)
NetworkRequest(NETWORK_REQUEST_TYPE type, uint32_t idforresponse=0)