Cuberite
A lightweight, fast and extensible game server for Minecraft
LuaServerHandle.h
Go to the documentation of this file.
1 
2 // LuaServerHandle.h
3 
4 // Declares the cLuaServerHandle class wrapping the cServerHandle functionality for Lua API
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "../OSSupport/Network.h"
13 #include "LuaState.h"
14 
15 
16 
17 
18 
19 // fwd:
20 class cLuaTCPLink;
21 typedef std::shared_ptr<cLuaTCPLink> cLuaTCPLinkPtr;
22 typedef std::vector<cLuaTCPLinkPtr> cLuaTCPLinkPtrs;
23 class cLuaServerHandle;
24 typedef std::shared_ptr<cLuaServerHandle> cLuaServerHandlePtr;
25 
26 
27 
28 
31 {
32 public:
35  cLuaServerHandle(UInt16 a_Port, cLuaState::cTableRefPtr && a_Callbacks);
36 
37  virtual ~cLuaServerHandle() override;
38 
41  void SetServerHandle(cServerHandlePtr a_ServerHandle, cLuaServerHandlePtr a_Self);
42 
44  void Close(void);
45 
47  bool IsListening(void);
48 
50  void RemoveLink(cLuaTCPLink * a_Link);
51 
54  void Release(void);
55 
56 protected:
59 
63 
66 
69 
73 
76 
77 
78  // cNetwork::cListenCallbacks overrides:
79  virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString & a_RemoteIPAddress, UInt16 a_RemotePort) override;
80  virtual void OnAccepted(cTCPLink & a_Link) override;
81  virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
82 };
83 
84 
85 
86 
std::shared_ptr< cLuaServerHandle > cLuaServerHandlePtr
std::vector< cLuaTCPLinkPtr > cLuaTCPLinkPtrs
std::shared_ptr< cLuaTCPLink > cLuaTCPLinkPtr
unsigned short UInt16
Definition: Globals.h:158
std::shared_ptr< cServerHandle > cServerHandlePtr
Definition: Network.h:28
std::string AString
Definition: StringUtils.h:11
void SetServerHandle(cServerHandlePtr a_ServerHandle, cLuaServerHandlePtr a_Self)
Called by cNetwork::Listen()'s binding.
cLuaServerHandle(UInt16 a_Port, cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the server handle, wrapping the (listen-) callbacks that are in the specifi...
bool IsListening(void)
Returns true if the server is currently listening.
void Close(void)
Terminates all connections and closes the listening socket.
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when the socket fails to listen on the specified port.
void Release(void)
Called when Lua garbage-collects the object.
cServerHandlePtr m_ServerHandle
The cServerHandle around which this instance is wrapped.
virtual cTCPLink::cCallbacksPtr OnIncomingConnection(const AString &a_RemoteIPAddress, UInt16 a_RemotePort) override
Called when the TCP server created with Listen() receives a new incoming connection.
void RemoveLink(cLuaTCPLink *a_Link)
Removes the link from the list of links that the server is currently tracking.
cLuaServerHandlePtr m_Self
SharedPtr to self, given out to newly created links.
cLuaTCPLinkPtrs m_Connections
All connections that are currently active in this server.
cCriticalSection m_CSConnections
Protects m_Connections against multithreaded access.
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
UInt16 m_Port
The port on which the server is listening.
virtual void OnAccepted(cTCPLink &a_Link) override
Called when the TCP server created with Listen() creates a new link for an incoming connection.
virtual ~cLuaServerHandle() override
std::unique_ptr< cTableRef > cTableRefPtr
Definition: LuaState.h:419
Interface that provides the methods available on a single TCP connection.
Definition: Network.h:42
std::shared_ptr< cCallbacks > cCallbacksPtr
Definition: Network.h:71
Callbacks used when listening for incoming connections as a server.
Definition: Network.h:254