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 receivedmessagenumber=0)
 
virtual ~NetworkRequest ()
 
void AddDataToPacket (sf::Packet &packet) const
 
NETWORK_REQUEST_TYPE GetType () const
 
DLLEXPORT std::string GetTypeStr () const
 
uint32_t GetMessageNumber () const
 
uint32_t GetIDForResponse () const
 The id number for a response to this is the same as the message number that this request is in. More...
 

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 MessageNumber = 0
 This is only valid when this is received. More...
 

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 81 of file NetworkRequest.h.

Constructor & Destructor Documentation

◆ NetworkRequest()

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

Definition at line 83 of file NetworkRequest.h.

83  :
84  Type(type), MessageNumber(receivedmessagenumber)
85  {}
const NETWORK_REQUEST_TYPE Type
const uint32_t MessageNumber
This is only valid when this is received.

◆ ~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.

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

The id number for a response to this is the same as the message number that this request is in.

Definition at line 111 of file NetworkRequest.h.

112  {
113  return MessageNumber;
114  }
const uint32_t MessageNumber
This is only valid when this is received.

◆ GetMessageNumber()

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

Definition at line 104 of file NetworkRequest.h.

105  {
106  return MessageNumber;
107  }
const uint32_t MessageNumber
This is only valid when this is received.

◆ GetType()

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

Definition at line 96 of file NetworkRequest.h.

97  {
98  return Type;
99  }
const NETWORK_REQUEST_TYPE Type

◆ GetTypeStr()

DLLEXPORT std::string NetworkRequest::GetTypeStr ( ) const
Returns
Name of this type. For prettier debug printing

Definition at line 47 of file NetworkRequest.cpp.

48 {
49  switch(Type) {
50  case NETWORK_REQUEST_TYPE::Connect: return "RequestConnect";
51  case NETWORK_REQUEST_TYPE::Security: return "RequestSecurity";
52  case NETWORK_REQUEST_TYPE::Authenticate: return "RequestAuthenticate";
53  case NETWORK_REQUEST_TYPE::Identification: return "RequestIdentification";
54  case NETWORK_REQUEST_TYPE::Serverstatus: return "RequestServerstatus";
55  case NETWORK_REQUEST_TYPE::RemoteConsoleOpen: return "RequestRemoteConsoleOpen";
56  case NETWORK_REQUEST_TYPE::RemoteConsoleAccess: return "RequestRemoteConsoleAccess";
57  case NETWORK_REQUEST_TYPE::CloseRemoteConsole: return "RequestCloseRemoteConsole";
58  case NETWORK_REQUEST_TYPE::DoRemoteConsoleOpen: return "RequestDoRemoteConsoleOpen";
59  case NETWORK_REQUEST_TYPE::JoinServer: return "RequestJoinServer";
60  case NETWORK_REQUEST_TYPE::JoinGame: return "RequestJoinGame";
61  case NETWORK_REQUEST_TYPE::GetSingleSyncValue: return "RequestGetSingleSyncValue";
62  case NETWORK_REQUEST_TYPE::GetAllSyncValues: return "RequestGetAllSyncValues";
64  return "RequestRequestCommandExecution";
65  case NETWORK_REQUEST_TYPE::ConnectInput: return "RequestConnectInput";
66  case NETWORK_REQUEST_TYPE::Echo: return "RequestEcho";
67  case NETWORK_REQUEST_TYPE::WorldClockSync: return "RequestWorldClockSync";
68  default: break;
69  }
70 
72 
73  return "RequestCustom(+" +
74  std::to_string(
75  static_cast<int>(Type) - static_cast<int>(NETWORK_REQUEST_TYPE::Custom)) +
76  ")";
77 
78  } else {
79 
80  return std::to_string(static_cast<int>(Type));
81  }
82 }
Only one side of the connection can send this request, usually the client.
All values above this are application specific types.
Sent when a player requests the server to connect a NetworkedInput.
const NETWORK_REQUEST_TYPE Type
The receiving side is now allowed to open a remote console with the token.
Sent by servers to ping (time the time a client takes to respond) clients.

◆ 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);
37  return std::make_shared<RequestJoinGame>(messagenumber, packet);
38  default: {
39  Logger::Get()->Warning("NetworkRequest: unused type: " +
40  Convert::ToString(static_cast<int>(requesttype)));
41  throw InvalidArgument("packet has request type that is missing from "
42  "switch(requesttype)");
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

◆ MessageNumber

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

This is only valid when this is received.

Definition at line 126 of file NetworkRequest.h.

◆ Type

const NETWORK_REQUEST_TYPE Leviathan::NetworkRequest::Type
protected

Definition at line 123 of file NetworkRequest.h.


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