mirror-ac/user/client.cpp

91 lines
3.2 KiB
C++
Raw Normal View History

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-09-07 19:49:36 +02:00
void global::Client::UpdateSystemInformation(global::headers::SYSTEM_INFORMATION* SystemInformation)
{
memcpy( &this->system_information, SystemInformation, sizeof( global::headers::SYSTEM_INFORMATION ) );
}
2023-08-22 19:32:25 +02:00
/*
* Request an item from the server
*/
2023-08-24 15:12:49 +02:00
void global::Client::ServerReceive()
2023-08-22 19:32:25 +02:00
{
2023-08-24 15:12:49 +02:00
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();
global::headers::PIPE_PACKET_HEADER header;
header.message_type = SERVER_SEND_PACKET_ID;
2023-09-07 09:21:00 +02:00
header.steam64_id = TEST_STEAM_64_ID;
2023-09-07 19:49:36 +02:00
memcpy( &header.system_information, &this->system_information, sizeof( global::headers::SYSTEM_INFORMATION ) );
2023-08-22 19:32:25 +02:00
memcpy( this->send_buffer, &header, sizeof( global::headers::PIPE_PACKET_HEADER ) );
2023-08-18 07:33:13 +02:00
2023-08-22 19:32:25 +02:00
LONG total_size_of_headers = sizeof( global::headers::PIPE_PACKET_HEADER ) + sizeof( global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER );
2023-08-18 09:18:00 +02:00
2023-08-22 19:32:25 +02:00
if ( Size > ( SEND_BUFFER_SIZE - total_size_of_headers ) )
{
INT total_packets = std::ceil( Size / ( SEND_BUFFER_SIZE - total_size_of_headers ) );
2023-08-23 14:40:44 +02:00
LONG remaining_bytes = Size + total_packets * total_size_of_headers;
2023-08-18 16:34:15 +02:00
2023-08-23 14:40:44 +02:00
for ( INT count = 0; count < total_packets + 1; count++ )
2023-08-22 19:32:25 +02:00
{
global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER header_extension;
header_extension.request_id = RequestId;
2023-08-23 17:16:13 +02:00
header_extension.total_incoming_packet_count = total_packets + 1;
header_extension.total_incoming_packet_size = Size + total_packets * total_size_of_headers;
2023-08-22 19:32:25 +02:00
header_extension.current_packet_number = count;
2023-08-23 14:40:44 +02:00
header_extension.packet_size = count == total_packets ? remaining_bytes : SEND_BUFFER_SIZE;
2023-08-18 16:34:15 +02:00
2023-08-23 14:14:20 +02:00
LOG_INFO( "current packet number: %lx, packet size: %lx", header_extension.current_packet_number, header_extension.packet_size );
2023-08-22 19:32:25 +02:00
memcpy( PVOID( ( UINT64 )this->send_buffer + sizeof( global::headers::PIPE_PACKET_HEADER ) ),
&header_extension, sizeof(global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER));
2023-08-18 16:34:15 +02:00
2023-08-22 19:32:25 +02:00
memcpy(
PVOID( ( UINT64 )this->send_buffer + total_size_of_headers ), Buffer,
( UINT64 )header_extension.packet_size - total_size_of_headers
);
2023-08-18 16:34:15 +02:00
2023-08-22 19:32:25 +02:00
this->pipe->WriteToPipe( this->send_buffer, header_extension.packet_size );
2023-08-18 16:34:15 +02:00
2023-08-23 14:40:44 +02:00
LOG_INFO( "remainiong bytes: %lx", remaining_bytes );
2023-08-22 19:32:25 +02:00
remaining_bytes = remaining_bytes - header_extension.packet_size;
}
}
else
2023-08-18 16:34:15 +02:00
{
2023-08-22 19:32:25 +02:00
global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER header_extension;
header_extension.request_id = RequestId;
header_extension.total_incoming_packet_count = 1;
2023-08-23 17:16:13 +02:00
header_extension.total_incoming_packet_size = Size + total_size_of_headers;
2023-08-22 19:32:25 +02:00
header_extension.current_packet_number = 1;
2023-08-23 17:16:13 +02:00
header_extension.packet_size = Size + total_size_of_headers;
2023-08-22 19:32:25 +02:00
memcpy( PVOID( ( UINT64 )this->send_buffer + sizeof( global::headers::PIPE_PACKET_HEADER ) ),
&header_extension, sizeof( global::headers::PIPE_PACKET_SEND_EXTENSION_HEADER ) );
this->pipe->WriteToPipe( this->send_buffer, header_extension.packet_size );
2023-08-18 16:34:15 +02:00
}
2023-08-22 19:32:25 +02:00
RtlZeroMemory( this->send_buffer, SEND_BUFFER_SIZE );
mutex.unlock();
2023-08-18 16:34:15 +02:00
}