From a5acd4c9a3b24c9d5af3a8f504e5af053fa7fa09 Mon Sep 17 00:00:00 2001 From: boris Date: Thu, 20 Dec 2018 21:38:04 +1300 Subject: yo is this loss --- csgo-loader/csgo-client/Networking/TCPClient.cpp | 33 +++++++++++++++--------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'csgo-loader/csgo-client/Networking/TCPClient.cpp') diff --git a/csgo-loader/csgo-client/Networking/TCPClient.cpp b/csgo-loader/csgo-client/Networking/TCPClient.cpp index 3bdea21..8065c50 100644 --- a/csgo-loader/csgo-client/Networking/TCPClient.cpp +++ b/csgo-loader/csgo-client/Networking/TCPClient.cpp @@ -1,11 +1,13 @@ #include #include -namespace Networking { +namespace Networking +{ // We will only receive up to 256 bytes per cycle. constexpr int BufferSize = 256; - void TCPClient::SendRawBytes(ByteArray &Bytes) { + void TCPClient::SendRawBytes(ByteArray &Bytes) + { // Send data. int32_t Result = send(m_Socket, (char *)Bytes.data(), (int)Bytes.size(), 0); @@ -13,12 +15,14 @@ namespace Networking { INFO_ASSERT("[000F:00002B00] Server closed the connection suddenly."); } - ByteArray TCPClient::ReceiveRawBytes() { + ByteArray TCPClient::ReceiveRawBytes() + { ByteArray ReceivedBytes; uint8_t RecvBuffer[BufferSize]; // Attempt to receive a packet. - while(true) { + while(true) + { int32_t Received = recv(m_Socket, (char*)RecvBuffer, BufferSize, 0); // No more bytes left to receive. @@ -26,7 +30,8 @@ namespace Networking { break; // Emplace all received bytes. - for(int n = 0; n < Received; ++n) { + for(int n = 0; n < Received; ++n) + { ReceivedBytes.push_back(RecvBuffer[n]); } @@ -38,14 +43,16 @@ namespace Networking { return ReceivedBytes; } - void TCPClient::SendBytes(ByteArray &Bytes) { + void TCPClient::SendBytes(ByteArray &Bytes) + { // Encrypt outgoing data. ByteArray Encrypted = m_Encryption.Encrypt(Bytes); SendRawBytes(Encrypted); } - ByteArray TCPClient::ReceiveBytes() { + ByteArray TCPClient::ReceiveBytes() + { ByteArray ReceivedBytes = ReceiveRawBytes(); // Decrypt incoming data. @@ -54,7 +61,8 @@ namespace Networking { return Decrypted; } - bool TCPClient::Start(uint32_t ServerAddress, uint16_t ServerPort) { + bool TCPClient::Start(uint32_t ServerAddress, uint16_t ServerPort) + { const int32_t version = 0x101; // Initialise WinSocks. @@ -69,8 +77,8 @@ namespace Networking { // Set up client context. m_Context.sin_addr.s_addr = ServerAddress; - m_Context.sin_family = AF_INET; - m_Context.sin_port = htons(ServerPort); + m_Context.sin_family = AF_INET; + m_Context.sin_port = htons(ServerPort); // Attempt connection. if(connect(m_Socket, (sockaddr *)&m_Context, sizeof m_Context)) @@ -93,10 +101,11 @@ namespace Networking { return true; } - void TCPClient::Kill() { + void TCPClient::Kill() + { if(m_Socket) closesocket(m_Socket); - + WSACleanup(); } } \ No newline at end of file -- cgit v1.2.3