Cuberite
A lightweight, fast and extensible game server for Minecraft
LuaTCPLink.h
Go to the documentation of this file.
1 
2 // LuaTCPLink.h
3 
4 // Declares the cLuaTCPLink class representing a Lua wrapper for the cTCPLink class and the callbacks it needs
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:
21 typedef std::weak_ptr<cLuaServerHandle> cLuaServerHandleWPtr;
22 
23 
24 
25 
26 
30 {
31 public:
33  cLuaTCPLink(cLuaState::cTableRefPtr && a_Callbacks);
34 
37 
38  virtual ~cLuaTCPLink() override;
39 
42  bool Send(const AString & a_Data);
43 
45  AString GetLocalIP(void) const;
46 
48  UInt16 GetLocalPort(void) const;
49 
51  AString GetRemoteIP(void) const;
52 
54  UInt16 GetRemotePort(void) const;
55 
59  void Shutdown(void);
60 
63  void Close(void);
64 
71  const AString & a_OwnCertData,
72  const AString & a_OwnPrivKeyData,
73  const AString & a_OwnPrivKeyPassword
74  );
75 
85  const AString & a_OwnCertData,
86  const AString & a_OwnPrivKeyData,
87  const AString & a_OwnPrivKeyPassword,
88  const AString & a_StartTLSData
89  );
90 
91 protected:
92 
95 
99 
102 
105  void Terminated(void);
106 
109  void ReceivedCleartextData(const char * a_Data, size_t a_NumBytes);
110 
111  // cNetwork::cConnectCallbacks overrides:
112  virtual void OnConnected(cTCPLink & a_Link) override;
113  virtual void OnError(int a_ErrorCode, const AString & a_ErrorMsg) override;
114 
115  // cTCPLink::cCallbacks overrides:
116  virtual void OnLinkCreated(cTCPLinkPtr a_Link) override;
117  virtual void OnReceivedData(const char * a_Data, size_t a_Length) override;
118  virtual void OnRemoteClosed(void) override;
119  // The OnError() callback is shared with cNetwork::cConnectCallbacks
120 };
121 
122 
123 
124 
virtual void OnReceivedData(const char *a_Data, size_t a_Length) override
Called when there&#39;s data incoming from the remote peer.
Definition: LuaTCPLink.cpp:310
std::unique_ptr< cTableRef > cTableRefPtr
Definition: LuaState.h:420
AString StartTLSServer(const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword, const AString &a_StartTLSData)
Starts a TLS handshake as a server connection.
Definition: LuaTCPLink.cpp:204
AString GetRemoteIP(void) const
Returns the IP address of the remote endpoint of the connection.
Definition: LuaTCPLink.cpp:102
void Terminated(void)
Common code called when the link is considered as terminated.
Definition: LuaTCPLink.cpp:237
bool Send(const AString &a_Data)
Sends the data contained in the string to the remote peer.
Definition: LuaTCPLink.cpp:51
UInt16 GetLocalPort(void) const
Returns the port used by the local endpoint of the connection.
Definition: LuaTCPLink.cpp:85
void Shutdown(void)
Closes the link gracefully.
Definition: LuaTCPLink.cpp:136
cLuaServerHandleWPtr m_Server
The server that is responsible for this link, if any.
Definition: LuaTCPLink.h:101
void ReceivedCleartextData(const char *a_Data, size_t a_NumBytes)
Called by the SSL context when there&#39;s incoming data available in the cleartext.
Definition: LuaTCPLink.cpp:267
std::shared_ptr< cTCPLink > cTCPLinkPtr
Definition: Network.h:17
virtual ~cLuaTCPLink() override
Definition: LuaTCPLink.cpp:35
cTCPLinkPtr m_Link
The underlying link representing the connection.
Definition: LuaTCPLink.h:98
cLuaTCPLink(cLuaState::cTableRefPtr &&a_Callbacks)
Creates a new instance of the link, wrapping the callbacks that are in the specified table...
Definition: LuaTCPLink.cpp:16
std::weak_ptr< cLuaServerHandle > cLuaServerHandleWPtr
Definition: LuaTCPLink.h:20
void Close(void)
Drops the connection without any more processing.
Definition: LuaTCPLink.cpp:150
virtual void OnLinkCreated(cTCPLinkPtr a_Link) override
Called when the cTCPLink for the connection is created.
Definition: LuaTCPLink.cpp:300
virtual void OnError(int a_ErrorCode, const AString &a_ErrorMsg) override
Called when an error is detected on the connection.
Definition: LuaTCPLink.cpp:287
unsigned short UInt16
Definition: Globals.h:114
std::string AString
Definition: StringUtils.h:13
Interface that provides the methods available on a single TCP connection.
Definition: Network.h:33
UInt16 GetRemotePort(void) const
Returns the port used by the remote endpoint of the connection.
Definition: LuaTCPLink.cpp:119
Callbacks used for connecting to other servers as a client.
Definition: Network.h:227
AString StartTLSClient(const AString &a_OwnCertData, const AString &a_OwnPrivKeyData, const AString &a_OwnPrivKeyPassword)
Starts a TLS handshake as a client connection.
Definition: LuaTCPLink.cpp:166
AString GetLocalIP(void) const
Returns the IP address of the local endpoint of the connection.
Definition: LuaTCPLink.cpp:68
cLuaState::cTableRefPtr m_Callbacks
The Lua table that holds the callbacks to be invoked.
Definition: LuaTCPLink.h:94
virtual void OnRemoteClosed(void) override
Called when the remote end closes the connection.
Definition: LuaTCPLink.cpp:320
virtual void OnConnected(cTCPLink &a_Link) override
Called when the Connect call succeeds.
Definition: LuaTCPLink.cpp:277