summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-client/Networking/TCPClient.cpp
diff options
context:
space:
mode:
authorboris <wzn@moneybot.cc>2018-12-20 21:38:04 +1300
committerboris <wzn@moneybot.cc>2018-12-20 21:38:04 +1300
commita5acd4c9a3b24c9d5af3a8f504e5af053fa7fa09 (patch)
tree27bc30d3f35e5daaaa15ee6de066119df8d352c7 /csgo-loader/csgo-client/Networking/TCPClient.cpp
parent77b52da44b263df4884be2f35f885d8edccbb6fa (diff)
yo is this loss
Diffstat (limited to 'csgo-loader/csgo-client/Networking/TCPClient.cpp')
-rw-r--r--csgo-loader/csgo-client/Networking/TCPClient.cpp33
1 files changed, 21 insertions, 12 deletions
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 <Networking/TCPClient.hpp>
#include <UserExperience/UserInterface.hpp>
-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