summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-server/Networking/TCPServer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'csgo-loader/csgo-server/Networking/TCPServer.cpp')
-rw-r--r--csgo-loader/csgo-server/Networking/TCPServer.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/csgo-loader/csgo-server/Networking/TCPServer.cpp b/csgo-loader/csgo-server/Networking/TCPServer.cpp
index c381c85..d93a710 100644
--- a/csgo-loader/csgo-server/Networking/TCPServer.cpp
+++ b/csgo-loader/csgo-server/Networking/TCPServer.cpp
@@ -4,7 +4,7 @@ namespace Networking
{
void TCPConnection::Close()
{
- printf("[ <= ] disconnected\n");
+ printf("[ <= ] %s disconnected!\n", m_IpAddress);
if(m_Socket)
closesocket(m_Socket);
@@ -18,12 +18,10 @@ namespace Networking
// Send data.
int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0);
- if(m_IpAddress)
-
- printf("[ => ] %zd bytes\n", Bytes.size());
+ printf("[ => ] Sending %zd bytes to %s.\n", Bytes.size(), m_IpAddress);
if(Result == -1)
- printf("[ => ] %zd bytes failed (%d)\n", Bytes.size(), WSAGetLastError());
+ printf("[ E! ] Failed to send %zd bytes to %s. (Socket %04Ix)\n", Bytes.size(), m_IpAddress, m_Socket);
}
ByteArray TCPConnection::ReceiveRawBytes()
@@ -43,7 +41,7 @@ namespace Networking
// Emplace all received bytes.
for(int n = 0; n < Received; ++n)
{
- ReceivedBytes.emplace_back(RecvBuffer[n]);
+ ReceivedBytes.push_back(RecvBuffer[n]);
}
// No more bytes left to receive.
@@ -51,7 +49,7 @@ namespace Networking
break;
}
- printf("[ <= ] %zd bytes\n", ReceivedBytes.size());
+ printf("[ <= ] Received %zd bytes from %s.\n", ReceivedBytes.size(), m_IpAddress);
return ReceivedBytes;
}
@@ -90,8 +88,8 @@ namespace Networking
// Set up server context.
m_Context.sin_addr.s_addr = INADDR_ANY;
- m_Context.sin_family = AF_INET;
- m_Context.sin_port = htons(ServerPort);
+ m_Context.sin_family = AF_INET;
+ m_Context.sin_port = htons(ServerPort);
int32_t Bind = bind(m_Socket, (sockaddr *)&m_Context, sizeof sockaddr_in);
@@ -99,7 +97,7 @@ namespace Networking
return false;
// Start listening.
- printf("[INFO] Server listening on port %d.\n", ServerPort);
+ printf("[ i! ] Server listening on port %d.\n", ServerPort);
listen(m_Socket, 1);
return true;
@@ -121,23 +119,17 @@ namespace Networking
Encryption.Start();
// Attempt handshake with client.
- TCPConnection Connection(IncomingSocket, inet_ntoa(IncomingConnection.sin_addr), Encryption);
+ const char *IpAddress = inet_ntoa(IncomingConnection.sin_addr);
+ TCPConnection Connection(IncomingSocket, IpAddress, Encryption);
ByteArray EncryptionKey = Connection.GetEncryptionKey();
Connection.SendRawBytes(EncryptionKey);
- // Print out handshake header
- printf("[ => ] Handshake: ");
-
- for(auto &It : EncryptionKey)
- printf("%02x ", It);
-
- printf("\n");
-
// Detach a thread to handle the connection.
std::thread thread([&]
{
- // smol fix :^)
+ // Fix for crashing when there is no connection handler
+ // (literally happened to me once)
if(m_ConnectionHandler)
m_ConnectionHandler(Connection);