2023-08-18 07:33:13 +02:00
|
|
|
#include "client.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
2023-09-07 09:21:00 +02:00
|
|
|
#define TEST_STEAM_64_ID 123456789;
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
global::Client::Client( std::shared_ptr<global::ThreadPool> ThreadPool, LPTSTR PipeName )
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-08-22 19:32:25 +02:00
|
|
|
this->thread_pool = ThreadPool;
|
|
|
|
this->pipe = std::make_shared<global::Pipe>( PipeName );
|
|
|
|
}
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
|
|
|
* Request an item from the server
|
|
|
|
*/
|
2023-09-10 12:20:35 +02:00
|
|
|
void global::Client::ServerReceive(PVOID Buffer, SIZE_T Size)
|
2023-08-22 19:32:25 +02:00
|
|
|
{
|
2023-09-10 12:20:35 +02:00
|
|
|
this->pipe->ReadPipe( Buffer, Size );
|
2023-08-18 07:33:13 +02:00
|
|
|
}
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
|
|
|
* Send an item to the server
|
|
|
|
*/
|
2023-09-07 19:49:36 +02:00
|
|
|
void global::Client::ServerSend(PVOID Buffer, SIZE_T Size, INT RequestId )
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-08-22 19:32:25 +02:00
|
|
|
mutex.lock();
|
2023-08-18 07:33:13 +02:00
|
|
|
|
2023-09-08 21:06:13 +02:00
|
|
|
SIZE_T total_header_size = sizeof( global::headers::CLIENT_SEND_PACKET_HEADER ) +
|
|
|
|
sizeof( global::headers::PIPE_PACKET_HEADER );
|
2023-08-18 09:18:00 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
if ( Size + total_header_size > MAX_CLIENT_SEND_PACKET_SIZE )
|
2023-08-22 19:32:25 +02:00
|
|
|
{
|
2023-09-08 20:41:11 +02:00
|
|
|
LOG_ERROR( "Packet is too large to send" );
|
|
|
|
mutex.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
PVOID send_buffer = malloc( total_header_size + Size );
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
if ( send_buffer == nullptr )
|
|
|
|
{
|
|
|
|
mutex.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2023-08-23 14:14:20 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
RtlZeroMemory( send_buffer, total_header_size + Size );
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-09-08 21:06:13 +02:00
|
|
|
global::headers::PIPE_PACKET_HEADER header;
|
|
|
|
header.message_type = MESSAGE_TYPE_CLIENT_SEND;
|
|
|
|
header.steam64_id = TEST_STEAM_64_ID;
|
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
memcpy( send_buffer, &header, sizeof( global::headers::PIPE_PACKET_HEADER ) );
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
global::headers::CLIENT_SEND_PACKET_HEADER header_extension;
|
|
|
|
header_extension.request_id = RequestId;
|
|
|
|
header_extension.packet_size = Size + total_header_size;
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
memcpy( PVOID( ( UINT64 )send_buffer + sizeof( global::headers::PIPE_PACKET_HEADER ) ),
|
|
|
|
&header_extension, sizeof( global::headers::CLIENT_SEND_PACKET_HEADER ) );
|
2023-08-22 19:32:25 +02:00
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
memcpy(PVOID((UINT64)send_buffer + total_header_size), Buffer, Size);
|
2023-08-22 19:32:25 +02:00
|
|
|
|
2023-09-10 12:20:35 +02:00
|
|
|
LOG_INFO( "Writing to pipe" );
|
|
|
|
|
2023-09-08 20:41:11 +02:00
|
|
|
this->pipe->WriteToPipe( send_buffer, header_extension.packet_size );
|
2023-08-22 19:32:25 +02:00
|
|
|
|
|
|
|
mutex.unlock();
|
2023-09-08 20:41:11 +02:00
|
|
|
free( send_buffer );
|
2023-08-18 16:34:15 +02:00
|
|
|
}
|