summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-client/Networking
diff options
context:
space:
mode:
Diffstat (limited to 'csgo-loader/csgo-client/Networking')
-rw-r--r--csgo-loader/csgo-client/Networking/TCPClient.cpp33
-rw-r--r--csgo-loader/csgo-client/Networking/TCPClient.hpp8
2 files changed, 26 insertions, 15 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
diff --git a/csgo-loader/csgo-client/Networking/TCPClient.hpp b/csgo-loader/csgo-client/Networking/TCPClient.hpp
index f057cdc..4e3e089 100644
--- a/csgo-loader/csgo-client/Networking/TCPClient.hpp
+++ b/csgo-loader/csgo-client/Networking/TCPClient.hpp
@@ -10,10 +10,12 @@
// std::min
#include <algorithm>
-namespace Networking {
+namespace Networking
+{
// A TCPClient is essentially the same as the TCPConnection counterpart on the server,
// however, it independently handles connection.
- class TCPClient {
+ class TCPClient
+ {
WSADATA m_WinSocks;
SOCKET m_Socket;
sockaddr_in m_Context;
@@ -25,7 +27,7 @@ namespace Networking {
// Connects to a remote server.
// Also handles the initial handshake between server and client.
bool Start(uint32_t ServerAddress, uint16_t ServerPort);
-
+
// Kills the client.
void Kill();