Leviathan  0.8.0.0
Leviathan game engine
NetworkInterface.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 #include "CommonNetwork.h"
7 
8 #include <memory>
9 #include <vector>
10 
11 namespace Leviathan {
12 
13 
19  friend NetworkHandler;
20 
21 public:
23  DLLEXPORT virtual ~NetworkInterface();
24 
26  DLLEXPORT virtual std::vector<std::shared_ptr<Connection>>& GetClientConnections() = 0;
27 
36  DLLEXPORT virtual void HandleRequestPacket(
37  const std::shared_ptr<NetworkRequest>& request, Connection& connection) = 0;
38 
45  DLLEXPORT virtual bool PreHandleResponse(const std::shared_ptr<NetworkResponse>& response,
46  SentNetworkThing* originalrequest, Connection& connection);
47 
48 
62  const std::shared_ptr<NetworkResponse>& message, Connection& connection) = 0;
63 
64 
70  DLLEXPORT virtual bool CanConnectionTerminate(Connection& connection);
71 
72 
77  DLLEXPORT virtual void TickIt() = 0;
78 
79 
81  DLLEXPORT virtual void CloseDown() = 0;
82 
84  DLLEXPORT void VerifyType(NETWORKED_TYPE type) const;
85 
87  {
88 
89  return Owner;
90  }
91 
92 protected:
94  const std::shared_ptr<NetworkRequest>& request, Connection& connection)
95  {
96  return false;
97  }
98 
100  const std::shared_ptr<NetworkResponse>& message, Connection& connection)
101  {
102  return false;
103  }
104 
109  const std::shared_ptr<NetworkRequest>& request, Connection& connectiontosendresult);
110 
116  const std::shared_ptr<NetworkResponse>& message, Connection& connection);
117 
118  DLLEXPORT void SetOwner(NetworkHandler* owner);
119 
120  // ------------------------------------ //
121 
123  NetworkHandler* Owner = nullptr;
124 };
125 
126 } // namespace Leviathan
virtual DLLEXPORT std::vector< std::shared_ptr< Connection > > & GetClientConnections()=0
If this is a server returns all the clients.
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.
virtual bool _CustomHandleRequestPacket(const std::shared_ptr< NetworkRequest > &request, Connection &connection)
NetworkHandler * GetOwner()
DLLEXPORT void VerifyType(NETWORKED_TYPE type) const
Asserts if types don't match.
DLLEXPORT NetworkInterface(NETWORKED_TYPE type)
virtual DLLEXPORT void TickIt()=0
Should be used to update various network interfaces.
DLLEXPORT bool _HandleDefaultResponseOnly(const std::shared_ptr< NetworkResponse > &message, Connection &connection)
Utility function for subclasses to call for default handling of non-request responses.
virtual DLLEXPORT void HandleResponseOnlyPacket(const std::shared_ptr< NetworkResponse > &message, Connection &connection)=0
Called by ConnectionInfo when it receives a response without a matching request object.
virtual DLLEXPORT bool CanConnectionTerminate(Connection &connection)
Called by Connection just before terminating an inactive connection.
virtual DLLEXPORT void CloseDown()=0
Called when the program is closing.
NETWORKED_TYPE
Type of networked application.
Definition: CommonNetwork.h:22
DLLEXPORT void SetOwner(NetworkHandler *owner)
Class that handles a single connection to another instance.
Definition: Connection.h:105
DLLEXPORT bool _HandleDefaultRequest(const std::shared_ptr< NetworkRequest > &request, Connection &connectiontosendresult)
Utility function for subclasses to call for default handling.
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Handles everything related to connections.
Class that encapsulates common networking functionality that is required by all networked programs.
virtual DLLEXPORT void HandleRequestPacket(const std::shared_ptr< NetworkRequest > &request, Connection &connection)=0
Called by ConnectionInfo to handle incoming packets.
virtual bool _CustomHandleResponseOnlyPacket(const std::shared_ptr< NetworkResponse > &message, Connection &connection)
Represents a sent packet and holds all kinds of data for it.