summaryrefslogtreecommitdiff
path: root/csgo-loader/csgo-client/Networking/TCPClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'csgo-loader/csgo-client/Networking/TCPClient.cpp')
-rw-r--r--csgo-loader/csgo-client/Networking/TCPClient.cpp44
1 files changed, 30 insertions, 14 deletions
diff --git a/csgo-loader/csgo-client/Networking/TCPClient.cpp b/csgo-loader/csgo-client/Networking/TCPClient.cpp
index 11d4677..9ac3c3e 100644
--- a/csgo-loader/csgo-client/Networking/TCPClient.cpp
+++ b/csgo-loader/csgo-client/Networking/TCPClient.cpp
@@ -40,23 +40,45 @@ namespace Networking
break;
}
+ // Stay in sync with client.
+ ByteArray Array = { 1 };
+ SendRawBytes(Array);
+
return ReceivedBytes;
}
void TCPClient::SendBytes(ByteArray &Bytes)
{
// Encrypt outgoing data.
- ByteArray Encrypted = m_Encryption.Encrypt(Bytes);
+ ByteArray EncryptionKey;
+ EncryptionKey.insert(
+ EncryptionKey.begin(),
+ m_EncryptionKey,
+ m_EncryptionKey + sizeof m_EncryptionKey
+ );
+
+ Wrapper::Encryption Encryption; Encryption.Start(EncryptionKey);
+
+ ByteArray Encrypted = Encryption.Encrypt(Bytes);
SendRawBytes(Encrypted);
}
ByteArray TCPClient::ReceiveBytes()
{
+ // Decrypt incoming data.
ByteArray ReceivedBytes = ReceiveRawBytes();
- // Decrypt incoming data.
- ByteArray Decrypted = m_Encryption.Decrypt(ReceivedBytes);
+ ByteArray EncryptionKey;
+ EncryptionKey.insert(
+ EncryptionKey.begin(),
+ m_EncryptionKey,
+ m_EncryptionKey + sizeof m_EncryptionKey
+ );
+
+ Wrapper::Encryption Encryption; Encryption.Start(EncryptionKey);
+
+ ByteArray Decrypted = Encryption.Decrypt(ReceivedBytes);
return Decrypted;
}
@@ -79,16 +101,6 @@ namespace Networking
m_Context.sin_addr.s_addr = ServerAddress;
m_Context.sin_family = AF_INET;
m_Context.sin_port = htons(ServerPort);
-
- // Allow the socket to time-out.
- timeval timeout;
- timeout.tv_sec = 5;
-
- if(setsockopt(m_Socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof timeout) == INVALID_SOCKET)
- return false;
-
- if(setsockopt(m_Socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof timeout) == INVALID_SOCKET)
- return false;
// Attempt connection.
if(connect(m_Socket, (sockaddr *)&m_Context, sizeof m_Context))
@@ -96,7 +108,11 @@ namespace Networking
// Initialise encryption wrapper.
ByteArray EncryptionKey = ReceiveRawBytes();
- m_Encryption.Start(EncryptionKey);
+
+ if(EncryptionKey.empty())
+ return false;
+
+ std::memcpy(m_EncryptionKey, EncryptionKey.data(), EncryptionKey.size());
return true;
}