2022-01-30 17:54:27 +01:00
|
|
|
#pragma once
|
2019-11-24 14:35:38 +01:00
|
|
|
|
2024-03-16 11:00:59 +01:00
|
|
|
#include <memory>
|
2019-11-24 14:35:38 +01:00
|
|
|
#include <string>
|
2022-02-04 15:47:35 +01:00
|
|
|
#include <vector>
|
2019-11-24 14:35:38 +01:00
|
|
|
|
|
|
|
#include "CThread.h"
|
|
|
|
|
|
|
|
class TcpReceiver : public CThread {
|
|
|
|
public:
|
|
|
|
enum eLoadResults {
|
2024-03-16 11:00:59 +01:00
|
|
|
SUCCESS = 0,
|
|
|
|
UNSUPPORTED_FORMAT = -1,
|
|
|
|
PLUGIN_PARSE_FAILED = -2,
|
|
|
|
PLUGIN_LOAD_LINK_FAILED = -3,
|
|
|
|
FILE_SAVE_BUFFER_ERROR = -4,
|
|
|
|
FILE_UNCOMPRESS_ERROR = -5,
|
|
|
|
NOT_ENOUGH_MEMORY = -6,
|
|
|
|
RECV_ERROR = -7,
|
|
|
|
LAUNCH_FAILED = -8,
|
2019-11-24 14:35:38 +01:00
|
|
|
};
|
|
|
|
|
2021-09-24 21:04:06 +02:00
|
|
|
explicit TcpReceiver(int32_t port);
|
2020-06-03 19:45:51 +02:00
|
|
|
|
2022-01-30 17:54:27 +01:00
|
|
|
virtual ~TcpReceiver();
|
2019-11-24 14:35:38 +01:00
|
|
|
|
|
|
|
private:
|
2021-09-24 21:04:06 +02:00
|
|
|
void executeThread() override;
|
2020-06-03 19:45:51 +02:00
|
|
|
|
2022-10-06 18:47:24 +02:00
|
|
|
bool createSocket();
|
|
|
|
void cleanupSocket();
|
|
|
|
|
2024-03-16 11:00:59 +01:00
|
|
|
static eLoadResults loadToMemory(int32_t clientSocket, uint32_t ipAddress);
|
|
|
|
|
|
|
|
static TcpReceiver::eLoadResults tryLoadWUHB(void *data, uint32_t fileSize, std::string &loadedPathOut);
|
|
|
|
static TcpReceiver::eLoadResults tryLoadRPX(uint8_t *data, uint32_t fileSize, std::string &loadedPathOut);
|
|
|
|
static TcpReceiver::eLoadResults tryLoadWPS(uint8_t *data, uint32_t fileSize);
|
|
|
|
static TcpReceiver::eLoadResults loadBinary(void *data, uint32_t fileSize);
|
|
|
|
static TcpReceiver::eLoadResults uncompressIfNeeded(const uint8_t *haxx, uint32_t fileSize, uint32_t fileSizeUnc, std::unique_ptr<uint8_t> &&in_data, std::unique_ptr<uint8_t> &out_data, uint32_t &fileSizeOut);
|
2019-11-24 14:35:38 +01:00
|
|
|
|
|
|
|
bool exitRequested;
|
|
|
|
int32_t serverPort;
|
|
|
|
int32_t serverSocket;
|
|
|
|
};
|