Leviathan  0.8.0.0
Leviathan game engine
Leviathan::NetworkRequest Class Referenceabstract

#include <NetworkRequest.h>

+ Inheritance diagram for Leviathan::NetworkRequest:

Public Member Functions

 NetworkRequest (NETWORK_REQUEST_TYPE type, uint32_t idforresponse=0)
 
virtual ~NetworkRequest ()
 
void AddDataToPacket (sf::Packet &packet) const
 
NETWORK_REQUEST_TYPE GetType () const
 
uint32_t GetIDForResponse () const
 

Static Public Member Functions

static DLLEXPORT std::shared_ptr< NetworkRequestLoadFromPacket (sf::Packet &packet, uint32_t messagenumber)
 

Protected Member Functions

virtual DLLEXPORT void _SerializeCustom (sf::Packet &packet) const =0
 Base classes serialize their data. More...
 

Protected Attributes

const NETWORK_REQUEST_TYPE Type
 
const uint32_t IDForResponse = 0
 

Detailed Description

Base class for all request objects

Note
Even though it cannot be required by the base class, sub classes should implement a constructor taking in an sf::Packet object

Definition at line 78 of file NetworkRequest.h.

Constructor & Destructor Documentation

◆ NetworkRequest()

Leviathan::NetworkRequest::NetworkRequest ( NETWORK_REQUEST_TYPE  type,
uint32_t  idforresponse = 0 
)
inline

Definition at line 81 of file NetworkRequest.h.

81  :
82  Type(type), IDForResponse(idforresponse)
83  {
84 
85  }
const uint32_t IDForResponse
const NETWORK_REQUEST_TYPE Type

◆ ~NetworkRequest()

virtual Leviathan::NetworkRequest::~NetworkRequest ( )
inlinevirtual

Definition at line 87 of file NetworkRequest.h.

87 {};

Member Function Documentation

◆ _SerializeCustom()

virtual DLLEXPORT void Leviathan::NetworkRequest::_SerializeCustom ( sf::Packet &  packet) const
protectedpure virtual

Base classes serialize their data.

Implemented in Leviathan::RequestNone, and Leviathan::RequestCustom.

◆ AddDataToPacket()

void Leviathan::NetworkRequest::AddDataToPacket ( sf::Packet &  packet) const
inline

Definition at line 89 of file NetworkRequest.h.

89  {
90 
91  packet << static_cast<uint16_t>(Type);
92 
93  _SerializeCustom(packet);
94  }
virtual DLLEXPORT void _SerializeCustom(sf::Packet &packet) const =0
Base classes serialize their data.
const NETWORK_REQUEST_TYPE Type

◆ GetIDForResponse()

uint32_t Leviathan::NetworkRequest::GetIDForResponse ( ) const
inline

Definition at line 100 of file NetworkRequest.h.

100  {
101  return IDForResponse;
102  }
const uint32_t IDForResponse

◆ GetType()

NETWORK_REQUEST_TYPE Leviathan::NetworkRequest::GetType ( ) const
inline

Definition at line 96 of file NetworkRequest.h.

96  {
97  return Type;
98  }
const NETWORK_REQUEST_TYPE Type

◆ LoadFromPacket()

DLLEXPORT std::shared_ptr< NetworkRequest > NetworkRequest::LoadFromPacket ( sf::Packet &  packet,
uint32_t  messagenumber 
)
static

Definition at line 12 of file NetworkRequest.cpp.

14 {
15  // Get the heading data //
16  uint16_t tmpval;
17  packet >> tmpval;
18 
19  if(!packet)
20  throw InvalidArgument("packet has invalid format");
21 
22  const NETWORK_REQUEST_TYPE requesttype = static_cast<NETWORK_REQUEST_TYPE>(tmpval);
23 
24  // Try to create the additional data if required for this type //
25  switch(requesttype){
27  return std::make_shared<RequestNone>(requesttype, messagenumber, packet);
29  return std::make_shared<RequestConnect>(messagenumber, packet);
31  return std::make_shared<RequestSecurity>(messagenumber, packet);
33  return std::make_shared<RequestAuthenticate>(messagenumber, packet);
35  return std::make_shared<RequestJoinServer>(messagenumber, packet);
36  default:
37  {
38  Logger::Get()->Warning("NetworkRequest: unused type: "+
39  Convert::ToString(static_cast<int>(requesttype)));
40  throw InvalidArgument("packet has request type that is missing from "
41  "switch(requesttype)");
42  }
43  break;
44  }
45 }
Only one side of the connection can send this request, usually the client.
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
unsigned short uint16_t
Definition: core.h:39
static std::string ToString(const T &val)
Definition: Convert.h:72
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
Sent by servers to ping (time the time a client takes to respond) clients.

Member Data Documentation

◆ IDForResponse

const uint32_t Leviathan::NetworkRequest::IDForResponse = 0
protected

Definition at line 114 of file NetworkRequest.h.

◆ Type

const NETWORK_REQUEST_TYPE Leviathan::NetworkRequest::Type
protected

Definition at line 112 of file NetworkRequest.h.


The documentation for this class was generated from the following files: