diff options
| author | boris <wzn@moneybot.cc> | 2018-12-20 21:38:04 +1300 |
|---|---|---|
| committer | boris <wzn@moneybot.cc> | 2018-12-20 21:38:04 +1300 |
| commit | a5acd4c9a3b24c9d5af3a8f504e5af053fa7fa09 (patch) | |
| tree | 27bc30d3f35e5daaaa15ee6de066119df8d352c7 /csgo-loader/csgo-server/Networking/TCPServer.hpp | |
| parent | 77b52da44b263df4884be2f35f885d8edccbb6fa (diff) | |
yo is this loss
Diffstat (limited to 'csgo-loader/csgo-server/Networking/TCPServer.hpp')
| -rw-r--r-- | csgo-loader/csgo-server/Networking/TCPServer.hpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.hpp b/csgo-loader/csgo-server/Networking/TCPServer.hpp index adb6e7c..388bdc2 100644 --- a/csgo-loader/csgo-server/Networking/TCPServer.hpp +++ b/csgo-loader/csgo-server/Networking/TCPServer.hpp @@ -16,16 +16,19 @@ // std::thread
#include <thread>
-namespace Networking {
+namespace Networking
+{
// Base connection class, used to handle multiple connections in a thread-based model.
- class TCPConnection {
+ class TCPConnection
+ {
SOCKET m_Socket;
Wrapper::Encryption m_Encryption;
const char *m_IpAddress;
public:
// Initialiser for TCPConnection class.
TCPConnection(SOCKET Connection, const char *IpAddress, Wrapper::Encryption &RSA) :
- m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress) {
+ m_Encryption(RSA), m_Socket(Connection), m_IpAddress(IpAddress)
+ {
printf("[=>] %s connected!\n", IpAddress);
}
@@ -40,12 +43,14 @@ namespace Networking { ByteArray ReceiveBytes();
// Overload for getting the socket, in case we need to expose it.
- SOCKET operator()() {
+ SOCKET operator()()
+ {
return m_Socket;
}
// Expose the encryption key for the connection.
- ByteArray GetEncryptionKey() {
+ ByteArray GetEncryptionKey()
+ {
return m_Encryption.GetKey();
}
};
@@ -53,7 +58,8 @@ namespace Networking { // Basic TCP server. Supports custom connection handling (pass a lambda to the handler list).
using ConnectionHandler = std::function<void(TCPConnection &)>;
- class TCPServer {
+ class TCPServer
+ {
WSADATA m_WinSocks;
SOCKET m_Socket;
sockaddr_in m_Context;
@@ -64,9 +70,10 @@ namespace Networking { public:
// Default constructor, nothing needed for now.
TCPServer() = default;
-
+
// Handle destruction of server once it goes out of scope.
- ~TCPServer() {
+ ~TCPServer()
+ {
// If we have a socket, close it.
if(m_Socket)
closesocket(m_Socket);
@@ -80,7 +87,8 @@ namespace Networking { void AcceptConnection();
// Overload for adding connection handlers, C# style support for events.
- void operator+=(std::function<void(TCPConnection &)> Function) {
+ void operator+=(std::function<void(TCPConnection &)> Function)
+ {
m_ConnectionHandler = Function;
}
};
|
