Leviathan  0.8.0.0
Leviathan game engine
Leviathan::NetworkClientInterface Class Referenceabstract

Class that encapsulates common networking functionality required by client programs. More...

#include <NetworkClientInterface.h>

+ Inheritance diagram for Leviathan::NetworkClientInterface:

Public Types

enum  CLIENT_CONNECTION_STATE { CLIENT_CONNECTION_STATE::None, CLIENT_CONNECTION_STATE::WaitingForOpening, CLIENT_CONNECTION_STATE::Connected, CLIENT_CONNECTION_STATE::Closed }
 

Public Member Functions

DLLEXPORT NetworkClientInterface ()
 
virtual DLLEXPORT ~NetworkClientInterface ()
 
virtual DLLEXPORT void HandleRequestPacket (std::shared_ptr< NetworkRequest > request, Connection &connection) override
 Called by ConnectionInfo to handle incoming packets. More...
 
virtual DLLEXPORT void HandleResponseOnlyPacket (std::shared_ptr< NetworkResponse > message, Connection &connection) override
 Called by ConnectionInfo when it receives a response without a matching request object. More...
 
DLLEXPORT bool JoinServer (std::shared_ptr< Connection > connectiontouse)
 Connects the client to a server. More...
 
DLLEXPORT void DisconnectFromServer (const std::string &reason, bool connectiontimedout=false)
 Disconnects the client from the server or does nothing. More...
 
virtual DLLEXPORT std::vector< std::shared_ptr< Connection > > & GetClientConnections () override
 If this is a server returns all the clients. More...
 
DLLEXPORT void OnUpdateFullSynchronizationState (size_t variablesgot, size_t expectedvariables)
 Called directly by SyncedVariables to update the status string. More...
 
DLLEXPORT void SendCommandStringToServer (const std::string &messagestr)
 Sends a command string to the server. More...
 
virtual DLLEXPORT void CloseDown () override
 Closes all client related things. More...
 
DLLEXPORT bool IsConnected () const
 Returns true if the client is connected to a server. More...
 
virtual DLLEXPORT int GetOurID () const
 Returns the ID that the server has assigned to us. More...
 
virtual DLLEXPORT std::shared_ptr< ConnectionGetServerConnection ()
 Returns the active server connection or NULL. More...
 
DLLEXPORT void MarkForNotifyReceivedStates ()
 Marks a keep alive to be sent on next tick. More...
 
DLLEXPORT void TickIt () override
 Updates status of the client to server connections. More...
 
auto GetServerConnectionState () const
 
- Public Member Functions inherited from Leviathan::NetworkInterface
DLLEXPORT NetworkInterface (NETWORKED_TYPE type)
 
virtual DLLEXPORT ~NetworkInterface ()
 
virtual DLLEXPORT bool PreHandleResponse (std::shared_ptr< NetworkResponse > response, SentNetworkThing *originalrequest, Connection &connection)
 Called by ConnectionInfo to verify that a response is good. More...
 
virtual DLLEXPORT bool CanConnectionTerminate (Connection &connection)
 Called by Connection just before terminating an inactive connection. More...
 
DLLEXPORT void VerifyType (NETWORKED_TYPE type) const
 Asserts if types don't match. More...
 
NetworkHandlerGetOwner ()
 

Protected Member Functions

virtual DLLEXPORT void _OnDisconnectFromServer (const std::string &reasonstring, bool donebyus)
 
virtual DLLEXPORT void _OnStartConnectToServer ()
 
virtual DLLEXPORT void _OnFailedToConnectToServer (const std::string &reason)
 
virtual DLLEXPORT void _OnSuccessfullyConnectedToServer ()
 
virtual DLLEXPORT void _OnCloseDown ()
 
virtual DLLEXPORT void _OnNewConnectionStatusMessage (const std::string &message)
 Called when this class generates a new update message. More...
 
virtual DLLEXPORT void _OnProperlyConnected ()
 Called when the server has confirmed the join and we are a player on the server. More...
 
virtual DLLEXPORT void _OnStartApplicationConnect ()=0
 Called when the player is on the server and everything that the Engine is concerned about is done. More...
 
- Protected Member Functions inherited from Leviathan::NetworkInterface
virtual bool _CustomHandleRequestPacket (std::shared_ptr< NetworkRequest > request, Connection &connection)
 
virtual bool _CustomHandleResponseOnlyPacket (std::shared_ptr< NetworkResponse > message, Connection &connection)
 
DLLEXPORT bool _HandleDefaultRequest (std::shared_ptr< NetworkRequest > request, Connection &connectiontosendresult)
 Utility function for subclasses to call for default handling. More...
 
DLLEXPORT bool _HandleDefaultResponseOnly (std::shared_ptr< NetworkResponse > message, Connection &connection)
 Utility function for subclasses to call for default handling of non-request responses. More...
 
DLLEXPORT void SetOwner (NetworkHandler *owner)
 

Protected Attributes

std::vector< std::shared_ptr< SentRequest > > OurSentRequests
 This vector holds the made requests to allow using the response to do stuff. More...
 
CLIENT_CONNECTION_STATE ConnectState = CLIENT_CONNECTION_STATE::None
 
std::shared_ptr< ConnectionServerConnection
 
bool UsingHeartbeats = false
 Marks whether heartbeats are in use. More...
 
WantedClockType::time_point LastReceivedHeartbeat
 The last time a heartbeat packet was received. More...
 
WantedClockType::time_point LastSentHeartbeat
 The last time a heartbeat was sent. More...
 
bool KeepAliveQueued = false
 True when a keep alive should be sent on next tick. More...
 
float SecondsWithoutConnection = 0.f
 Holds the time for how long we have been without a heartbeat. More...
 
int OurPlayerID = -1
 Our player id, this is required for some requests. More...
 
- Protected Attributes inherited from Leviathan::NetworkInterface
NETWORKED_TYPE OurNetworkType
 
NetworkHandlerOwner = nullptr
 

Detailed Description

Class that encapsulates common networking functionality required by client programs.

More specific version of NetworkInterface and should be included additionally in client network interface classes.

See also
NetworkInterface

Definition at line 22 of file NetworkClientInterface.h.

Member Enumeration Documentation

◆ CLIENT_CONNECTION_STATE

Enumerator
None 

Not connected to a server.

WaitingForOpening 

JoinServer has been called and the client is now waiting for the connection object to become open

Connected 

Properly connected.

Closed 

Client is leaving a server.

Definition at line 24 of file NetworkClientInterface.h.

24  {
25 
27  None,
28 
31  WaitingForOpening,
32 
34  Connected,
35 
37  Closed
38  };
In this mode the View doesn&#39;t take any input under any circumstances.
Moves to this state once handshake is complete.

Constructor & Destructor Documentation

◆ NetworkClientInterface()

DLLEXPORT Leviathan::NetworkClientInterface::NetworkClientInterface ( )

Definition at line 23 of file NetworkClientInterface.cpp.

◆ ~NetworkClientInterface()

DLLEXPORT Leviathan::NetworkClientInterface::~NetworkClientInterface ( )
virtual

Definition at line 28 of file NetworkClientInterface.cpp.

28  {
29 
30 }

Member Function Documentation

◆ _OnCloseDown()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnCloseDown ( )
inlineprotectedvirtual

Definition at line 121 of file NetworkClientInterface.h.

121 {}

◆ _OnDisconnectFromServer()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnDisconnectFromServer ( const std::string &  reasonstring,
bool  donebyus 
)
inlineprotectedvirtual

Reimplemented in Pong::PongNetHandler.

Definition at line 113 of file NetworkClientInterface.h.

115  {
116  }

◆ _OnFailedToConnectToServer()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnFailedToConnectToServer ( const std::string &  reason)
inlineprotectedvirtual

Definition at line 118 of file NetworkClientInterface.h.

118 {}

◆ _OnNewConnectionStatusMessage()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnNewConnectionStatusMessage ( const std::string &  message)
inlineprotectedvirtual

Called when this class generates a new update message.

Reimplemented in Pong::PongNetHandler.

Definition at line 124 of file NetworkClientInterface.h.

124 {}

◆ _OnProperlyConnected()

DLLEXPORT void Leviathan::NetworkClientInterface::_OnProperlyConnected ( )
protectedvirtual

Called when the server has confirmed the join and we are a player on the server.

By default this will synchronize game variables and call the _OnLobbyJoin function (which can then handle match joining)

Todo:
Do what this should do

Definition at line 380 of file NetworkClientInterface.cpp.

380  {
381 
382  // Send the request //
383  LOG_WRITE("TODO: rewrite how _OnProperlyConnected works");
384  // We are now completely connected from the engine's point of view so let the
385  // application know
387  return;
388 
389  DEBUG_BREAK;
390  //shared_ptr<NetworkRequest> tmprequest(
391  // new NetworkRequest(NETWORKREQUESTTYPE_GETALLSYNCVALUES));
392 
393  // Prepare for sync //
394  //Owner->GetSyncedVariables()->PrepareForFullSync();
395  //SyncedVariables::Get()->PrepareForFullSync();
396 
397  //auto receivedata = ServerConnection->SendPacketToConnection(tmprequest, 3);
398 
399  // Add a on completion function //
400  DEBUG_BREAK;
401  // std::bind<void>([](shared_ptr<SentNetworkThing> maderequest,
402  // NetworkClientInterface* iptr) -> void
403  //{
404  // // Check the status //
405  // if(!maderequest->GetStatus() || !maderequest->GotResponse){
406  // // Terminate the connection //
407  // DEBUG_BREAK;
408  // return;
409  // }
410 
411  // // This will have the maximum number of variables we are going to receive //
412  // NetworkResponseDataForServerAllow* tmpresponse = maderequest->GotResponse->
413  // GetResponseDataForServerAllowResponse();
414  //
415  // if(!tmpresponse){
416 
417  // Logger::Get()->Warning("NetworkClientInterface: connect sync: variable sync "
418  // "request returned and invalid response, expected ServerAllow, unknown count "
419  // "of synced variables");
420  // } else {
421 
422  // // Set the maximum number of things //
423  // size_t toreceive = Convert::StringTo<size_t>(tmpresponse->Message);
424 
425  // SyncedVariables::Get()->SetExpectedNumberOfVariablesReceived(toreceive);
426 
427  // Logger::Get()->Info("NetworkClientInterface: sync variables: now expecting "+
428  // Convert::ToString(toreceive)+" variables");
429  // }
430 
431 
432  //
433  // // We are now syncing the variables //
434  // iptr->_OnNewConnectionStatusMessage("Syncing variables, waiting for response...");
435 
436  // // Queue task that checks when it is done //
437  // Engine::Get()->GetThreadingManager()->QueueTask(shared_ptr<QueuedTask>(
438  // new ConditionalTask(std::bind<void>([](NetworkClientInterface* iptr) -> void
439  // {
440  // // Set the status to almost done //
441  // iptr->_OnNewConnectionStatusMessage("Finalizing connection");
442 
443  // // We are now completely connected from the engine's point of view so let the
444  // // application know
445  // iptr->_OnStartApplicationConnect();
446 
447  // }, iptr), std::bind<bool>([]() -> bool
448  // {
449  // return SyncedVariables::Get()->IsSyncDone();
450  // }))));
451 
452 
453  //}, receivedata, this)
454 }
virtual DLLEXPORT void _OnStartApplicationConnect()=0
Called when the player is on the server and everything that the Engine is concerned about is done...
#define LOG_WRITE(x)
Definition: Define.h:84

◆ _OnStartApplicationConnect()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnStartApplicationConnect ( )
protectedpure virtual

Called when the player is on the server and everything that the Engine is concerned about is done.

Note
Here the application's connect data should be sent. The application specific connection routine should be done here

Implemented in Pong::PongNetHandler.

◆ _OnStartConnectToServer()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnStartConnectToServer ( )
inlineprotectedvirtual

Definition at line 117 of file NetworkClientInterface.h.

117 {}

◆ _OnSuccessfullyConnectedToServer()

virtual DLLEXPORT void Leviathan::NetworkClientInterface::_OnSuccessfullyConnectedToServer ( )
inlineprotectedvirtual

Definition at line 119 of file NetworkClientInterface.h.

119 {}

◆ CloseDown()

DLLEXPORT void Leviathan::NetworkClientInterface::CloseDown ( )
overridevirtual

Closes all client related things.

Implements Leviathan::NetworkInterface.

Definition at line 464 of file NetworkClientInterface.cpp.

464  {
465 
466  _OnCloseDown();
467 
468  if(ServerConnection){
469 
470  DisconnectFromServer("Game closing");
471  }
472 }
DLLEXPORT void DisconnectFromServer(const std::string &reason, bool connectiontimedout=false)
Disconnects the client from the server or does nothing.
std::shared_ptr< Connection > ServerConnection

◆ DisconnectFromServer()

DLLEXPORT void Leviathan::NetworkClientInterface::DisconnectFromServer ( const std::string &  reason,
bool  connectiontimedout = false 
)

Disconnects the client from the server or does nothing.

Todo:
Add a check to not close the connection if it is used by RemoteConsole

Definition at line 128 of file NetworkClientInterface.cpp.

130 {
131  // Return if no connection //
132  if(!ServerConnection){
133 
134  LOG_WARNING("NetworkClientInterface: DisconnectFromServer: not connected "
135  "to any servers");
136  return;
137  }
138 
139  LOG_INFO("Client: disconnected from server, reason: " + reason);
140 
141  // Discard waiting requests //
142  OurSentRequests.clear();
143 
144  // Send disconnect message to server //
145  _OnNewConnectionStatusMessage("Disconnected from " +
146  ServerConnection->GenerateFormatedAddressString() + ", reason: " +reason);
147 
148  // TODO: clear synced variables
149  //Owner->GetSyncedVariables()->Clear();
150 
151  // Close connection //
152  LOG_WRITE("TODO: send disconnect reason to server");
154  ServerConnection.reset();
155 
157  OurPlayerID = -1;
158 
159  _OnDisconnectFromServer(reason, connectiontimedout ? false: true);
160 }
#define LOG_INFO(x)
Definition: Define.h:81
std::vector< std::shared_ptr< SentRequest > > OurSentRequests
This vector holds the made requests to allow using the response to do stuff.
virtual DLLEXPORT void _OnNewConnectionStatusMessage(const std::string &message)
Called when this class generates a new update message.
int OurPlayerID
Our player id, this is required for some requests.
#define LOG_WARNING(x)
Definition: Define.h:82
#define LOG_WRITE(x)
Definition: Define.h:84
virtual DLLEXPORT void _OnDisconnectFromServer(const std::string &reasonstring, bool donebyus)
std::shared_ptr< Connection > ServerConnection
virtual DLLEXPORT void CloseConnection(Connection &connection)
Marks a connection as closing.

◆ GetClientConnections()

DLLEXPORT std::vector< std::shared_ptr< Leviathan::Connection > > & Leviathan::NetworkClientInterface::GetClientConnections ( )
overridevirtual

If this is a server returns all the clients.

Implements Leviathan::NetworkInterface.

Definition at line 163 of file NetworkClientInterface.cpp.

164 {
165  LOG_FATAL("Calling GetClientConnections on a client interface");
166  throw Exception("Calling GetClientConnections on a client interface");
167 }
#define LOG_FATAL(x)
Definition: Define.h:85
Base class for all exceptions thrown by Leviathan.
Definition: Exceptions.h:10

◆ GetOurID()

DLLEXPORT int Leviathan::NetworkClientInterface::GetOurID ( ) const
virtual

Returns the ID that the server has assigned to us.

Definition at line 557 of file NetworkClientInterface.cpp.

557  {
558  return OurPlayerID;
559 }
int OurPlayerID
Our player id, this is required for some requests.

◆ GetServerConnection()

DLLEXPORT std::shared_ptr< Connection > Leviathan::NetworkClientInterface::GetServerConnection ( )
virtual

Returns the active server connection or NULL.

Definition at line 562 of file NetworkClientInterface.cpp.

563 {
564  return ServerConnection;
565 }
std::shared_ptr< Connection > ServerConnection

◆ GetServerConnectionState()

auto Leviathan::NetworkClientInterface::GetServerConnectionState ( ) const
inline

Definition at line 106 of file NetworkClientInterface.h.

107  {
108  return ConnectState;
109  }

◆ HandleRequestPacket()

DLLEXPORT void Leviathan::NetworkClientInterface::HandleRequestPacket ( std::shared_ptr< NetworkRequest request,
Connection connection 
)
overridevirtual

Called by ConnectionInfo to handle incoming packets.

This function is responsible for interpreting the packet data and generating a response. If the response could take a long time to generate it is recommended to queue a task to the ThreadingManager.

Note
The connection parameter shouldn't be stored directly since it can become invalid after this function returns. Get a shared pointer from NetworkHandler instead

Implements Leviathan::NetworkInterface.

Definition at line 32 of file NetworkClientInterface.cpp.

34 {
35 
36  if (_HandleDefaultRequest(request, connection))
37  return;
38 
39  // switch (request->GetType()) {
40  // }
41 
42  if (_CustomHandleRequestPacket(request, connection))
43  return;
44 
45  LOG_ERROR("NetworkClientInterface: failed to handle request of type: " +
46  Convert::ToString(static_cast<int>(request->GetType())));
47 }
#define LOG_ERROR(x)
Definition: Define.h:83
DLLEXPORT bool _HandleDefaultRequest(std::shared_ptr< NetworkRequest > request, Connection &connectiontosendresult)
Utility function for subclasses to call for default handling.
static std::string ToString(const T &val)
Definition: Convert.h:72
virtual bool _CustomHandleRequestPacket(std::shared_ptr< NetworkRequest > request, Connection &connection)

◆ HandleResponseOnlyPacket()

DLLEXPORT void Leviathan::NetworkClientInterface::HandleResponseOnlyPacket ( std::shared_ptr< NetworkResponse message,
Connection connection 
)
overridevirtual

Called by ConnectionInfo when it receives a response without a matching request object.

This is called when the host on the connection sends a response without a matching request. Usually the other program instance wants us to do something without expecting a response, for example they could want us to add a new message to our inbox without expecting a response (other than an ack which is automatically sent) from us. The function can optionally ignore keepalive acks (to reduce spam between clients) by setting dontmarkasreceived as true. This function shouldn't throw any exceptions.

Implements Leviathan::NetworkInterface.

Definition at line 49 of file NetworkClientInterface.cpp.

51 {
52  LEVIATHAN_ASSERT(message, "_HandleClientResponseOnly message is null");
53 
54  if (_HandleDefaultResponseOnly(message, connection))
55  return;
56 
57  switch (message->GetType()) {
59  {
60  // We got a heartbeat //
61  _OnHeartbeat();
62  // Avoid spamming keep alive packets //
63  //dontmarkasreceived = true;
64  return;
65  }
67  {
68  // We need to start sending heartbeats //
69  _OnStartHeartbeats();
70  return;
71  }
73  {
74  auto data = static_cast<ResponseCacheUpdated*>(message.get());
75 
76  if (!Owner->GetCache()->HandleUpdatePacket(data)) {
77 
78  LOG_WARNING("NetworkClientInterface: applying AI cache "
79  "update failed");
80  }
81 
82  return;
83  }
84  default:
85  break;
86  }
87 
88  if (_CustomHandleResponseOnlyPacket(message, connection))
89  return;
90 
91  LOG_ERROR("NetworkClientInterface: failed to handle response of type: " +
92  Convert::ToString(static_cast<int>(message->GetType())));
93 }
#define LOG_ERROR(x)
Definition: Define.h:83
DLLEXPORT bool _HandleDefaultResponseOnly(std::shared_ptr< NetworkResponse > message, Connection &connection)
Utility function for subclasses to call for default handling of non-request responses.
Contains an updated cache variable.
#define LOG_WARNING(x)
Definition: Define.h:82
DLLEXPORT bool HandleUpdatePacket(ResponseCacheUpdated *data)
Handles an update packet.
virtual bool _CustomHandleResponseOnlyPacket(std::shared_ptr< NetworkResponse > message, Connection &connection)
static std::string ToString(const T &val)
Definition: Convert.h:72
Marks that the client is required to send heartbeats.
NetworkCache * GetCache()

◆ IsConnected()

DLLEXPORT bool Leviathan::NetworkClientInterface::IsConnected ( ) const

Returns true if the client is connected to a server.

This will be true when the server has responded to our join request and allowed us to join, we aren't actually yet playing on the server

Definition at line 498 of file NetworkClientInterface.cpp.

◆ JoinServer()

DLLEXPORT bool Leviathan::NetworkClientInterface::JoinServer ( std::shared_ptr< Connection connectiontouse)

Connects the client to a server.

Returns
Returns true when successfully started the join process, false if already connected (and DisconnectFromServer should be called)
Parameters
connectiontouseThe connection object should be retrieved by calling NetworkHandler::GetOrCreatePointerToConnection

Definition at line 95 of file NetworkClientInterface.cpp.

97 {
98  // Fail if already connected //
99  if(ServerConnection){
100 
101  LOG_ERROR("NetworkClientInterface: JoinServer: trying to join a server "
102  "while connected to another");
103  DisconnectFromServer("Trying to connect to another server");
104  return false;
105  }
106 
107  // Store the connection //
108  ServerConnection = connectiontouse;
109 
110  KeepAliveQueued = false;
111  UsingHeartbeats = false;
112 
114 
115  // Send message //
116  _OnNewConnectionStatusMessage("Trying to connect to a server on "+ServerConnection->
117  GenerateFormatedAddressString());
118 
119  auto sentthing = ServerConnection->SendPacketToConnection(
120  std::make_shared<RequestJoinServer>(-1), RECEIVE_GUARANTEE::Critical);
121 
122  // Monitor result
123  OurSentRequests.push_back(sentthing);
124 
125  return true;
126 }
bool KeepAliveQueued
True when a keep alive should be sent on next tick.
std::vector< std::shared_ptr< SentRequest > > OurSentRequests
This vector holds the made requests to allow using the response to do stuff.
#define LOG_ERROR(x)
Definition: Define.h:83
virtual DLLEXPORT void _OnNewConnectionStatusMessage(const std::string &message)
Called when this class generates a new update message.
DLLEXPORT void DisconnectFromServer(const std::string &reason, bool connectiontimedout=false)
Disconnects the client from the server or does nothing.
bool UsingHeartbeats
Marks whether heartbeats are in use.
std::shared_ptr< Connection > ServerConnection

◆ MarkForNotifyReceivedStates()

DLLEXPORT void NetworkClientInterface::MarkForNotifyReceivedStates ( )

Marks a keep alive to be sent on next tick.

Definition at line 567 of file NetworkClientInterface.cpp.

567  {
568 
569  KeepAliveQueued = true;
570 }
bool KeepAliveQueued
True when a keep alive should be sent on next tick.

◆ OnUpdateFullSynchronizationState()

DLLEXPORT void Leviathan::NetworkClientInterface::OnUpdateFullSynchronizationState ( size_t  variablesgot,
size_t  expectedvariables 
)

Called directly by SyncedVariables to update the status string.

Definition at line 456 of file NetworkClientInterface.cpp.

458 {
459 
460  _OnNewConnectionStatusMessage("Syncing variables, "+Convert::ToString(variablesgot)+
461  "/"+Convert::ToString(expectedvariables));
462 }
virtual DLLEXPORT void _OnNewConnectionStatusMessage(const std::string &message)
Called when this class generates a new update message.
static std::string ToString(const T &val)
Definition: Convert.h:72

◆ SendCommandStringToServer()

DLLEXPORT void Leviathan::NetworkClientInterface::SendCommandStringToServer ( const std::string &  messagestr)

Sends a command string to the server.

It should always be assumed that this function works. If it doesn't it is guaranteed that the client kicks itself because the connection is lost.

Exceptions
ExceptionInvalidStateif not connected to a server The maximum length is MAX_SERVERCOMMAND_LENGTH should be around 550 characters.
ExceptionInvalidArgumentwhen the message string is too long

Definition at line 474 of file NetworkClientInterface.cpp.

476 {
477  // Make sure that we are connected to a server //
479 
480  throw InvalidState("cannot send command because we aren't connected to a server");
481  }
482 
483  // Check the length //
484  if(messagestr.length() >= MAX_SERVERCOMMAND_LENGTH){
485 
486  throw InvalidArgument("server command is too long");
487  }
488 
489  // Send it //
490  auto sendthing = ServerConnection->SendPacketToConnection(
491  std::make_shared<RequestRequestCommandExecution>(messagestr),
493 
494  // The packet may not fail so we need to monitor the response //
495  OurSentRequests.push_back(sendthing);
496 }
std::vector< std::shared_ptr< SentRequest > > OurSentRequests
This vector holds the made requests to allow using the response to do stuff.
constexpr auto MAX_SERVERCOMMAND_LENGTH
Definition: Define.h:32
std::shared_ptr< Connection > ServerConnection

◆ TickIt()

DLLEXPORT void Leviathan::NetworkClientInterface::TickIt ( )
overridevirtual

Updates status of the client to server connections.

Note
Should be called by NetworkInterface::TickIt

Implements Leviathan::NetworkInterface.

Definition at line 214 of file NetworkClientInterface.cpp.

214  {
215 
216  _TickServerConnectionState();
217 
218  sentrequestloopbegin:
219 
220  // Check status of requests //
221  for(auto iter = OurSentRequests.begin(); iter != OurSentRequests.end(); ){
222 
223  // Check can we handle it //
224  if((*iter)->IsFinalized()){
225  // Handle the request //
226  if(!(*iter)->GetStatus() || !(*iter)->GotResponse){
227  // It failed //
228 
229  Logger::Get()->Warning("NetworkClientInterface: request to server failed, "
230  "possibly retrying:");
231 
232  // Store a copy and delete from the vector //
233  auto& tmpsendthing = *iter;
234  iter = OurSentRequests.erase(iter);
235 
236  _ProcessFailedRequest(tmpsendthing, tmpsendthing->GotResponse);
237 
238  // We need to loop again, because our iterator is now invalid, because
239  // quite often failed things are retried
240  goto sentrequestloopbegin;
241  }
242 
243  Logger::Get()->Info("Received a response to client request");
244 
245  // Handle it //
246  _ProcessCompletedRequest(*iter, (*iter)->GotResponse);
247 
248  // This is now received/handled //
249  iter = OurSentRequests.erase(iter);
250  continue;
251  }
252 
253  // Can't handle, continue looping //
254  ++iter;
255  }
256 }
std::vector< std::shared_ptr< SentRequest > > OurSentRequests
This vector holds the made requests to allow using the response to do stuff.
DLLEXPORT void Info(const std::string &data) override
Definition: Logger.cpp:164
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106

Member Data Documentation

◆ ConnectState

CLIENT_CONNECTION_STATE Leviathan::NetworkClientInterface::ConnectState = CLIENT_CONNECTION_STATE::None
protected

Definition at line 175 of file NetworkClientInterface.h.

◆ KeepAliveQueued

bool Leviathan::NetworkClientInterface::KeepAliveQueued = false
protected

True when a keep alive should be sent on next tick.

Definition at line 188 of file NetworkClientInterface.h.

◆ LastReceivedHeartbeat

WantedClockType::time_point Leviathan::NetworkClientInterface::LastReceivedHeartbeat
protected

The last time a heartbeat packet was received.

Definition at line 182 of file NetworkClientInterface.h.

◆ LastSentHeartbeat

WantedClockType::time_point Leviathan::NetworkClientInterface::LastSentHeartbeat
protected

The last time a heartbeat was sent.

Definition at line 185 of file NetworkClientInterface.h.

◆ OurPlayerID

int Leviathan::NetworkClientInterface::OurPlayerID = -1
protected

Our player id, this is required for some requests.

Definition at line 196 of file NetworkClientInterface.h.

◆ OurSentRequests

std::vector<std::shared_ptr<SentRequest> > Leviathan::NetworkClientInterface::OurSentRequests
protected

This vector holds the made requests to allow using the response to do stuff.

Definition at line 173 of file NetworkClientInterface.h.

◆ SecondsWithoutConnection

float Leviathan::NetworkClientInterface::SecondsWithoutConnection = 0.f
protected

Holds the time for how long we have been without a heartbeat.

Definition at line 192 of file NetworkClientInterface.h.

◆ ServerConnection

std::shared_ptr<Connection> Leviathan::NetworkClientInterface::ServerConnection
protected

Definition at line 176 of file NetworkClientInterface.h.

◆ UsingHeartbeats

bool Leviathan::NetworkClientInterface::UsingHeartbeats = false
protected

Marks whether heartbeats are in use.

Definition at line 179 of file NetworkClientInterface.h.


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