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-12-25 16:54:35 +01:00
|
|
|
global::Client::Client(std::shared_ptr<global::ThreadPool> ThreadPool, LPTSTR PipeName)
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-12-25 16:54:35 +01:00
|
|
|
this->thread_pool = ThreadPool;
|
2023-12-27 04:35:46 +01:00
|
|
|
#if NO_SERVER
|
|
|
|
LOG_INFO("No_Server build used. Not opening named pipe.");
|
|
|
|
#else
|
2023-12-25 16:54:35 +01:00
|
|
|
this->pipe = std::make_shared<global::Pipe>(PipeName);
|
2023-12-27 04:35:46 +01:00
|
|
|
#endif
|
2023-08-22 19:32:25 +02:00
|
|
|
}
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
2023-12-25 16:54:35 +01:00
|
|
|
* Request an item from the server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
global::Client::ServerReceive(PVOID Buffer, SIZE_T Size)
|
2023-08-22 19:32:25 +02:00
|
|
|
{
|
2023-12-25 16:54:35 +01:00
|
|
|
this->pipe->ReadPipe(Buffer, Size);
|
2023-08-18 07:33:13 +02:00
|
|
|
}
|
|
|
|
|
2023-08-22 19:32:25 +02:00
|
|
|
/*
|
2023-12-25 16:54:35 +01:00
|
|
|
* Send an item to the server
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
global::Client::ServerSend(PVOID Buffer, SIZE_T Size, INT RequestId)
|
2023-08-18 07:33:13 +02:00
|
|
|
{
|
2023-12-27 04:35:46 +01:00
|
|
|
#if NO_SERVER
|
|
|
|
return;
|
|
|
|
#else
|
2023-12-25 16:54:35 +01:00
|
|
|
mutex.lock();
|
2023-08-18 07:33:13 +02:00
|
|
|
|
2023-12-25 16:54:35 +01: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-12-25 16:54:35 +01:00
|
|
|
if (Size + total_header_size > MAX_CLIENT_SEND_PACKET_SIZE)
|
|
|
|
{
|
|
|
|
LOG_ERROR("Packet is too large to send");
|
|
|
|
mutex.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
PVOID send_buffer = malloc(total_header_size + Size);
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
if (send_buffer == nullptr)
|
|
|
|
{
|
|
|
|
mutex.unlock();
|
|
|
|
return;
|
|
|
|
}
|
2023-08-23 14:14:20 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
RtlZeroMemory(send_buffer, total_header_size + Size);
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-12-27 04:35:46 +01:00
|
|
|
global::headers::PIPE_PACKET_HEADER header = {0};
|
|
|
|
header.message_type = MESSAGE_TYPE_CLIENT_SEND;
|
|
|
|
header.steam64_id = TEST_STEAM_64_ID;
|
2023-09-08 21:06:13 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
memcpy(send_buffer, &header, sizeof(global::headers::PIPE_PACKET_HEADER));
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
global::headers::CLIENT_SEND_PACKET_HEADER header_extension = {0};
|
|
|
|
header_extension.request_id = RequestId;
|
|
|
|
header_extension.packet_size = Size + total_header_size;
|
2023-08-18 16:34:15 +02:00
|
|
|
|
2023-12-25 16:54:35 +01: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-12-25 16:54:35 +01:00
|
|
|
memcpy(PVOID((UINT64)send_buffer + total_header_size), Buffer, Size);
|
2023-08-22 19:32:25 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
LOG_INFO("Writing to pipe");
|
2023-09-10 12:20:35 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
this->pipe->WriteToPipe(send_buffer, header_extension.packet_size);
|
2023-08-22 19:32:25 +02:00
|
|
|
|
2023-12-25 16:54:35 +01:00
|
|
|
mutex.unlock();
|
|
|
|
free(send_buffer);
|
2023-12-27 04:35:46 +01:00
|
|
|
#endif
|
|
|
|
|
2023-08-18 16:34:15 +02:00
|
|
|
}
|