Leviathan  0.8.0.0
Leviathan game engine
Leviathan::NetworkMasterServerInterface Class Reference

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

#include <NetworkMasterServerInterface.h>

+ Inheritance diagram for Leviathan::NetworkMasterServerInterface:

Public Member Functions

DLLEXPORT NetworkMasterServerInterface ()
 
DLLEXPORT ~NetworkMasterServerInterface ()
 
virtual DLLEXPORT void HandleRequestPacket (const std::shared_ptr< NetworkRequest > &request, Connection &connection) override
 Called by ConnectionInfo to handle incoming packets. More...
 
virtual DLLEXPORT void HandleResponseOnlyPacket (const std::shared_ptr< NetworkResponse > &message, Connection &connection) override
 Called by ConnectionInfo when it receives a response without a matching request object. More...
 
DLLEXPORT void TickIt () override
 Should be used to update various network interfaces. More...
 
virtual DLLEXPORT void CloseDown () override
 Call this before shutting down the server to kick all players properly. More...
 
virtual DLLEXPORT std::vector< std::shared_ptr< Connection > > & GetClientConnections () override
 If this is a server returns all the clients. More...
 
- Public Member Functions inherited from Leviathan::NetworkInterface
DLLEXPORT NetworkInterface (NETWORKED_TYPE type)
 
virtual DLLEXPORT ~NetworkInterface ()
 
virtual DLLEXPORT bool PreHandleResponse (const 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 ()
 

Additional Inherited Members

- Protected Member Functions inherited from Leviathan::NetworkInterface
virtual bool _CustomHandleRequestPacket (const std::shared_ptr< NetworkRequest > &request, Connection &connection)
 
virtual bool _CustomHandleResponseOnlyPacket (const std::shared_ptr< NetworkResponse > &message, Connection &connection)
 
DLLEXPORT bool _HandleDefaultRequest (const std::shared_ptr< NetworkRequest > &request, Connection &connectiontosendresult)
 Utility function for subclasses to call for default handling. More...
 
DLLEXPORT bool _HandleDefaultResponseOnly (const 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 inherited from Leviathan::NetworkInterface
NETWORKED_TYPE OurNetworkType
 
NetworkHandlerOwner = nullptr
 

Detailed Description

Class that encapsulates common networking functionality required by server programs.

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

See also
NetworkInterface

Definition at line 20 of file NetworkMasterServerInterface.h.

Constructor & Destructor Documentation

◆ NetworkMasterServerInterface()

DLLEXPORT Leviathan::NetworkMasterServerInterface::NetworkMasterServerInterface ( )

◆ ~NetworkMasterServerInterface()

DLLEXPORT Leviathan::NetworkMasterServerInterface::~NetworkMasterServerInterface ( )

Definition at line 15 of file NetworkMasterServerInterface.cpp.

15 {}

Member Function Documentation

◆ CloseDown()

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

Call this before shutting down the server to kick all players properly.

Todo:
Actually call this, maybe make this an event listener

Implements Leviathan::NetworkInterface.

Definition at line 55 of file NetworkMasterServerInterface.cpp.

55 {}

◆ GetClientConnections()

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

If this is a server returns all the clients.

Implements Leviathan::NetworkInterface.

Definition at line 58 of file NetworkMasterServerInterface.cpp.

59 {
60  DEBUG_BREAK;
61  LEVIATHAN_ASSERT(false, "GetClientConnections called on a master server");
62  throw Exception("GetClientConnections called on a master server");
63 }
Base class for all exceptions thrown by Leviathan.
Definition: Exceptions.h:10
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:102

◆ HandleRequestPacket()

DLLEXPORT void Leviathan::NetworkMasterServerInterface::HandleRequestPacket ( const 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 17 of file NetworkMasterServerInterface.cpp.

19 {
20  LEVIATHAN_ASSERT(request, "request is null");
21 
22  if(_HandleDefaultRequest(request, connection))
23  return;
24 
25  // switch (request->GetType()) {
26  // }
27 
28  if(_CustomHandleRequestPacket(request, connection))
29  return;
30 
31  LOG_ERROR("NetworkMasterServerInterface: failed to handle request of type: " +
32  Convert::ToString(static_cast<int>(request->GetType())));
33 }
NETWORK_REQUEST_TYPE GetType() const
#define LOG_ERROR(x)
Definition: Define.h:94
virtual bool _CustomHandleRequestPacket(const std::shared_ptr< NetworkRequest > &request, Connection &connection)
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:102
static std::string ToString(const T &val)
Definition: Convert.h:72
DLLEXPORT bool _HandleDefaultRequest(const std::shared_ptr< NetworkRequest > &request, Connection &connectiontosendresult)
Utility function for subclasses to call for default handling.

◆ HandleResponseOnlyPacket()

DLLEXPORT void Leviathan::NetworkMasterServerInterface::HandleResponseOnlyPacket ( const 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 35 of file NetworkMasterServerInterface.cpp.

37 {
38  LEVIATHAN_ASSERT(message, "message is null");
39 
40  if(_HandleDefaultResponseOnly(message, connection))
41  return;
42 
43  // switch (message->GetType()) {
44  // }
45 
46  if(_CustomHandleResponseOnlyPacket(message, connection))
47  return;
48 
49  LOG_ERROR("NetworkMasterServerInterface: failed to handle response of type: " +
50  Convert::ToString(static_cast<int>(message->GetType())));
51 }
#define LOG_ERROR(x)
Definition: Define.h:94
NETWORK_RESPONSE_TYPE GetType() const
DLLEXPORT bool _HandleDefaultResponseOnly(const std::shared_ptr< NetworkResponse > &message, Connection &connection)
Utility function for subclasses to call for default handling of non-request responses.
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:102
static std::string ToString(const T &val)
Definition: Convert.h:72
virtual bool _CustomHandleResponseOnlyPacket(const std::shared_ptr< NetworkResponse > &message, Connection &connection)

◆ TickIt()

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

Should be used to update various network interfaces.

Note
This NetworkInterface doesn't need any ticking, but NetworkClientInterface does
See also
NetworkClientInterface::UpdateClientStatus

Implements Leviathan::NetworkInterface.

Definition at line 53 of file NetworkMasterServerInterface.cpp.

53 {}

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