Leviathan  0.8.0.0
Leviathan game engine
RemoteConsole.h
Go to the documentation of this file.
1 #pragma once
2 // ------------------------------------ //
3 #include "Define.h"
4 // ------------------------------------ //
6 #include "TimeIncludes.h"
7 
8 #include "SFML/Network/IpAddress.hpp"
9 
10 #include <memory>
11 
12 namespace Leviathan{
13 
15  friend RemoteConsole;
16 public:
17  DLLEXPORT RemoteConsoleSession(const std::string &name,
18  std::shared_ptr<Connection> connection, int32_t token) :
19  ConnectionName(name), SessionToken(token), CorrespondingConnection(connection),
20  IsOpened(true), TerminateSession(false)
21  { }
23 
25 
28 
29 private:
30  std::string ConnectionName;
31  int SessionToken;
32  std::shared_ptr<Connection> CorrespondingConnection;
33 
35  bool IsOpened;
36 
40  bool TerminateSession;
41 };
42 
43 
45 class RemoteConsole : public ThreadSafe{
46  friend Engine;
47 
48  struct RemoteConsoleExpect{
49  RemoteConsoleExpect(const std::string &name, int token, bool onlylocalhost,
50  const MillisecondDuration &timeout);
51 
52 
53  std::string ConnectionName;
54  int SessionToken;
55  bool OnlyLocalhost;
56 
57  WantedClockType::time_point TimeoutTime;
58  };
59 public:
62 
67  DLLEXPORT void UpdateStatus();
68 
69 
70  // Handle functions for interface to use //
71  DLLEXPORT void HandleRemoteConsoleRequestPacket(std::shared_ptr<NetworkRequest> request,
72  std::shared_ptr<Connection> connection);
73  DLLEXPORT void HandleRemoteConsoleResponse(std::shared_ptr<NetworkResponse> response,
74  Connection &connection, std::shared_ptr<NetworkRequest> potentialrequest);
75 
77  DLLEXPORT void OfferConnectionTo(std::shared_ptr<Connection> connectiontouse,
78  const std::string &connectionname, int token);
79 
84 
85 
88 
89 
92  DLLEXPORT std::shared_ptr<Connection> GetConnectionForRemoteConsoleSession(
93  const std::string &name);
94 
98  DLLEXPORT void SetCloseIfNoRemoteConsole(bool state);
99 
107  Connection &connection);
108 
111  DLLEXPORT bool CanOpenNewConnection(std::shared_ptr<Connection> connection,
112  std::shared_ptr<NetworkRequest> request);
113 
114  DLLEXPORT void ExpectNewConnection(int SessionToken, const std::string &assignname = "",
115  bool onlylocalhost = false, const MillisecondDuration &timeout =
116  std::chrono::seconds(30));
117 
118 protected:
119 
121  void SetAllowClose();
122 
123 private:
124 
125 
126  // ------------------------------------ //
127  // We need to store the requests until we get a response //
128  std::vector<std::shared_ptr<NetworkRequest>> WaitingRequests;
129 
130  std::vector<std::shared_ptr<RemoteConsoleSession>> RemoteConsoleConnections;
131 
132  std::vector<std::shared_ptr<RemoteConsoleExpect>> AwaitingConnections;
133 
136  bool CloseIfNoRemoteConsole;
137 
139  bool CanClose;
140 };
141 
142 }
DLLEXPORT RemoteConsoleSession(const std::string &name, std::shared_ptr< Connection > connection, int32_t token)
Definition: RemoteConsole.h:17
DLLEXPORT bool IsAwaitingConnections()
Returns true if connections are marked as awaiting.
DLLEXPORT void HandleRemoteConsoleRequestPacket(std::shared_ptr< NetworkRequest > request, std::shared_ptr< Connection > connection)
DLLEXPORT bool CanOpenNewConnection(std::shared_ptr< Connection > connection, std::shared_ptr< NetworkRequest > request)
Returns true if request from connection is allowed to open a remote console session.
Allows the inherited object to be locked.
Definition: ThreadSafe.h:137
DLLEXPORT void UpdateStatus()
Called before packets are handled.
DLLEXPORT void ExpectNewConnection(int SessionToken, const std::string &assignname="", bool onlylocalhost=false, const MillisecondDuration &timeout=std::chrono::seconds(30))
DLLEXPORT void KillConnection()
Sets the connection as closing.
The main class of the Leviathan Game Engine.
Definition: Engine.h:37
DLLEXPORT RemoteConsoleSession * GetRemoteConsoleSessionForConnection(Lock &guard, Connection &connection)
Gets a matching RemoteConsoleSession from Connection.
DLLEXPORT void HandleRemoteConsoleResponse(std::shared_ptr< NetworkResponse > response, Connection &connection, std::shared_ptr< NetworkRequest > potentialrequest)
DLLEXPORT void SetCloseIfNoRemoteConsole(bool state)
Sets the remote console to close the game if there are no connections.
DLLEXPORT size_t GetActiveConnectionCount()
Returns active number of connections.
std::chrono::duration< int64_t, std::milli > MillisecondDuration
Definition: TimeIncludes.h:14
DLLEXPORT std::shared_ptr< Connection > GetConnectionForRemoteConsoleSession(const std::string &name)
Gets the corresponding Connection object from a RemoteConsoleSession session indicated by name.
Class that handles a single connection to another instance.
Definition: Connection.h:105
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
Class used to handle remote server commands and receiving messages.
Definition: RemoteConsole.h:45
DLLEXPORT void OfferConnectionTo(std::shared_ptr< Connection > connectiontouse, const std::string &connectionname, int token)
Does everything needed to allow the client on the connection to connect to us.
DLLEXPORT Connection * GetConnection()
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:18
void SetAllowClose()
Called by Engine after command line has been processed.