Remove unnecessary includes and fix steamauth exploit

This commit is contained in:
momo5502 2016-07-22 12:12:11 +02:00
parent 23571e899c
commit b2a9e7af81
30 changed files with 957 additions and 953 deletions

2
deps/fmt vendored

@ -1 +1 @@
Subproject commit 0d5ef5c2a66026409b0cfbafa1d2f46cdc5aa4d0 Subproject commit d5893c9a133382e1862c929c1d50ccaef2a6d2fc

2
deps/mongoose vendored

@ -1 +1 @@
Subproject commit 68dd8d277d7b5bb26daf04f08bef3030ad2d7725 Subproject commit b987df197436b8581a7a5a9e00c1d341f81fdb30

2
deps/protobuf vendored

@ -1 +1 @@
Subproject commit 042993b3dd8c52f979870c91ea7fcbcf0dcf94a0 Subproject commit 2ba058c66c10781d57a332987be23e3fed0f9e1c

View File

@ -101,9 +101,9 @@ namespace Components
static uint8_t loadLibAStr[] = { 0xB3, 0x90, 0x9E, 0x9B, 0xB3, 0x96, 0x9D, 0x8D, 0x9E, 0x8D, 0x86, 0xBE }; // LoadLibraryA static uint8_t loadLibAStr[] = { 0xB3, 0x90, 0x9E, 0x9B, 0xB3, 0x96, 0x9D, 0x8D, 0x9E, 0x8D, 0x86, 0xBE }; // LoadLibraryA
static uint8_t loadLibWStr[] = { 0xB3, 0x90, 0x9E, 0x9B, 0xB3, 0x96, 0x9D, 0x8D, 0x9E, 0x8D, 0x86, 0xA8 }; // LoadLibraryW static uint8_t loadLibWStr[] = { 0xB3, 0x90, 0x9E, 0x9B, 0xB3, 0x96, 0x9D, 0x8D, 0x9E, 0x8D, 0x86, 0xA8 }; // LoadLibraryW
HMODULE kernel32 = GetModuleHandleA(Utils::String::XORString(std::string(reinterpret_cast<char*>(kernel32Str), sizeof kernel32Str), -1).data()); HMODULE kernel32 = GetModuleHandleA(Utils::String::XOR(std::string(reinterpret_cast<char*>(kernel32Str), sizeof kernel32Str), -1).data());
FARPROC loadLibA = GetProcAddress(kernel32, Utils::String::XORString(std::string(reinterpret_cast<char*>(loadLibAStr), sizeof loadLibAStr), -1).data()); FARPROC loadLibA = GetProcAddress(kernel32, Utils::String::XOR(std::string(reinterpret_cast<char*>(loadLibAStr), sizeof loadLibAStr), -1).data());
FARPROC loadLibW = GetProcAddress(kernel32, Utils::String::XORString(std::string(reinterpret_cast<char*>(loadLibWStr), sizeof loadLibWStr), -1).data()); FARPROC loadLibW = GetProcAddress(kernel32, Utils::String::XOR(std::string(reinterpret_cast<char*>(loadLibWStr), sizeof loadLibWStr), -1).data());
AntiCheat::LoadLibHook[0].Initialize(loadLibA, loadLibStub, HOOK_JUMP); AntiCheat::LoadLibHook[0].Initialize(loadLibA, loadLibStub, HOOK_JUMP);
AntiCheat::LoadLibHook[1].Initialize(loadLibW, loadLibStub, HOOK_JUMP); AntiCheat::LoadLibHook[1].Initialize(loadLibW, loadLibStub, HOOK_JUMP);

View File

@ -145,7 +145,7 @@ namespace Components
void Auth::StoreKey() void Auth::StoreKey()
{ {
if (!Dedicated::IsDedicated() && !ZoneBuilder::IsEnabled()) if (!Dedicated::IsEnabled() && !ZoneBuilder::IsEnabled())
{ {
Proto::Auth::Certificate cert; Proto::Auth::Certificate cert;
cert.set_token(Auth::GuidToken.ToString()); cert.set_token(Auth::GuidToken.ToString());
@ -158,7 +158,7 @@ namespace Components
void Auth::LoadKey(bool force) void Auth::LoadKey(bool force)
{ {
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) return; if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
if (!force && Auth::GuidKey.IsValid()) return; if (!force && Auth::GuidKey.IsValid()) return;
Proto::Auth::Certificate cert; Proto::Auth::Certificate cert;
@ -292,7 +292,7 @@ namespace Components
Auth::LoadKey(true); Auth::LoadKey(true);
// Only clients receive the auth request // Only clients receive the auth request
if (!Dedicated::IsDedicated()) if (!Dedicated::IsEnabled())
{ {
Network::Handle("xuidAuthReq", [] (Network::Address address, std::string data) Network::Handle("xuidAuthReq", [] (Network::Address address, std::string data)
{ {

View File

@ -34,7 +34,7 @@ namespace Components
void Command::Add(const char* name, Command::Callback* callback) void Command::Add(const char* name, Command::Callback* callback)
{ {
std::string command = Utils::String::StrToLower(name); std::string command = Utils::String::ToLower(name);
if (Command::FunctionMap.find(command) == Command::FunctionMap.end()) if (Command::FunctionMap.find(command) == Command::FunctionMap.end())
{ {
@ -46,7 +46,7 @@ namespace Components
void Command::AddSV(const char* name, Command::Callback* callback) void Command::AddSV(const char* name, Command::Callback* callback)
{ {
std::string command = Utils::String::StrToLower(name); std::string command = Utils::String::ToLower(name);
if (Command::FunctionMapSV.find(command) == Command::FunctionMapSV.end()) if (Command::FunctionMapSV.find(command) == Command::FunctionMapSV.end())
{ {
@ -98,7 +98,7 @@ namespace Components
{ {
Command::Params params(false, *Game::cmd_id); Command::Params params(false, *Game::cmd_id);
std::string command = Utils::String::StrToLower(params[0]); std::string command = Utils::String::ToLower(params[0]);
if (Command::FunctionMap.find(command) != Command::FunctionMap.end()) if (Command::FunctionMap.find(command) != Command::FunctionMap.end())
{ {
@ -110,7 +110,7 @@ namespace Components
{ {
Command::Params params(true, *Game::cmd_id_sv); Command::Params params(true, *Game::cmd_id_sv);
std::string command = Utils::String::StrToLower(params[0]); std::string command = Utils::String::ToLower(params[0]);
if (Command::FunctionMapSV.find(command) != Command::FunctionMapSV.end()) if (Command::FunctionMapSV.find(command) != Command::FunctionMapSV.end())
{ {

View File

@ -523,7 +523,7 @@ namespace Components
Console::LastRefresh = Game::Sys_Milliseconds(); Console::LastRefresh = Game::Sys_Milliseconds();
}); });
} }
else if (Dedicated::IsDedicated()/* || ZoneBuilder::IsEnabled()*/) else if (Dedicated::IsEnabled()/* || ZoneBuilder::IsEnabled()*/)
{ {
Utils::Hook::Nop(0x60BB58, 11); Utils::Hook::Nop(0x60BB58, 11);

View File

@ -7,7 +7,7 @@ namespace Components
bool Dedicated::SendChat; bool Dedicated::SendChat;
bool Dedicated::IsDedicated() bool Dedicated::IsEnabled()
{ {
return Flags::HasFlag("dedicated"); return Flags::HasFlag("dedicated");
} }
@ -118,7 +118,7 @@ namespace Components
void Dedicated::MapRotate() void Dedicated::MapRotate()
{ {
if (!Dedicated::IsDedicated() && Dvar::Var("sv_dontrotate").Get<bool>()) if (!Dedicated::IsEnabled() && Dvar::Var("sv_dontrotate").Get<bool>())
{ {
Dvar::Var("sv_dontrotate").SetRaw(0); Dvar::Var("sv_dontrotate").SetRaw(0);
return; return;
@ -226,7 +226,7 @@ namespace Components
Utils::Hook::Set(0x4152E8, Dedicated::MapRotate); Utils::Hook::Set(0x4152E8, Dedicated::MapRotate);
Dvar::Register<bool>("sv_dontrotate", false, Game::dvar_flag::DVAR_FLAG_CHEAT, ""); Dvar::Register<bool>("sv_dontrotate", false, Game::dvar_flag::DVAR_FLAG_CHEAT, "");
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) // Run zonebuilder as dedi :P
{ {
Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node"); Dvar::Register<bool>("sv_lanOnly", false, Game::dvar_flag::DVAR_FLAG_NONE, "Don't act as node");

View File

@ -1,37 +1,37 @@
namespace Components namespace Components
{ {
class Dedicated : public Component class Dedicated : public Component
{ {
public: public:
typedef void(Callback)(); typedef void(Callback)();
Dedicated(); Dedicated();
~Dedicated(); ~Dedicated();
const char* GetName() { return "Dedicated"; }; const char* GetName() { return "Dedicated"; };
static bool IsDedicated(); static bool IsEnabled();
static void Heartbeat(); static void Heartbeat();
static void OnFrame(Callback* callback); static void OnFrame(Callback* callback);
static void Once(Callback* callback); static void Once(Callback* callback);
private: private:
static wink::signal<wink::slot<Callback>> FrameSignal; static wink::signal<wink::slot<Callback>> FrameSignal;
static wink::signal<wink::slot<Callback>> FrameOnceSignal; static wink::signal<wink::slot<Callback>> FrameOnceSignal;
static bool SendChat; static bool SendChat;
static void MapRotate(); static void MapRotate();
static void FrameStub(); static void FrameStub();
static void InitDedicatedServer(); static void InitDedicatedServer();
static void PostInitialization(); static void PostInitialization();
static void PostInitializationStub(); static void PostInitializationStub();
static const char* EvaluateSay(char* text); static const char* EvaluateSay(char* text);
static void PreSayStub(); static void PreSayStub();
static void PostSayStub(); static void PostSayStub();
}; };
} }

View File

@ -285,7 +285,7 @@ namespace Components
Download::Download() Download::Download()
{ {
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
mg_mgr_init(&Download::Mgr, NULL); mg_mgr_init(&Download::Mgr, NULL);
@ -319,7 +319,7 @@ namespace Components
Download::~Download() Download::~Download()
{ {
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
mg_mgr_free(&Download::Mgr); mg_mgr_free(&Download::Mgr);
} }

View File

@ -8,7 +8,7 @@ namespace Components
{ {
for (auto entry : Flags::EnabledFlags) for (auto entry : Flags::EnabledFlags)
{ {
if (Utils::String::StrToLower(entry) == Utils::String::StrToLower(flag)) if (Utils::String::ToLower(entry) == Utils::String::ToLower(flag))
{ {
return true; return true;
} }

View File

@ -1,254 +1,254 @@
#include "STDInclude.hpp" #include "STDInclude.hpp"
namespace Components namespace Components
{ {
Pipe* IPCPipe::ServerPipe = 0; Pipe* IPCPipe::ServerPipe = 0;
Pipe* IPCPipe::ClientPipe = 0; Pipe* IPCPipe::ClientPipe = 0;
#pragma region Pipe #pragma region Pipe
Pipe::Pipe() : mType(IPCTYPE_NONE), ReconnectAttempt(0), hPipe(INVALID_HANDLE_VALUE), ConnectCallback(0), mThreadAttached(false) Pipe::Pipe() : mType(IPCTYPE_NONE), ReconnectAttempt(0), hPipe(INVALID_HANDLE_VALUE), ConnectCallback(0), mThreadAttached(false)
{ {
this->Destroy(); this->Destroy();
} }
Pipe::~Pipe() Pipe::~Pipe()
{ {
this->Destroy(); this->Destroy();
} }
bool Pipe::Connect(std::string name) bool Pipe::Connect(std::string name)
{ {
this->Destroy(); this->Destroy();
this->mType = IPCTYPE_CLIENT; this->mType = IPCTYPE_CLIENT;
this->SetName(name); this->SetName(name);
this->hPipe = CreateFileA(this->PipeFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL); this->hPipe = CreateFileA(this->PipeFile, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if (INVALID_HANDLE_VALUE == this->hPipe) if (INVALID_HANDLE_VALUE == this->hPipe)
{ {
Logger::Print("Failed to connect to the pipe\n"); Logger::Print("Failed to connect to the pipe\n");
if (this->ReconnectAttempt < IPC_MAX_RECONNECTS) if (this->ReconnectAttempt < IPC_MAX_RECONNECTS)
{ {
Logger::Print("Attempting to reconnect to the pipe.\n"); Logger::Print("Attempting to reconnect to the pipe.\n");
++this->ReconnectAttempt; ++this->ReconnectAttempt;
std::this_thread::sleep_for(500ms); std::this_thread::sleep_for(500ms);
return this->Connect(name); return this->Connect(name);
} }
else else
{ {
this->Destroy(); this->Destroy();
return false; return false;
} }
} }
this->ReconnectAttempt = 0; this->ReconnectAttempt = 0;
Logger::Print("Successfully connected to the pipe\n"); Logger::Print("Successfully connected to the pipe\n");
return true; return true;
} }
bool Pipe::Create(std::string name) bool Pipe::Create(std::string name)
{ {
this->Destroy(); this->Destroy();
this->mType = IPCTYPE_SERVER; this->mType = IPCTYPE_SERVER;
this->SetName(name); this->SetName(name);
this->hPipe = CreateNamedPipeA(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL); this->hPipe = CreateNamedPipeA(this->PipeFile, PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, sizeof(this->mPacket), sizeof(this->mPacket), NMPWAIT_USE_DEFAULT_WAIT, NULL);
if (INVALID_HANDLE_VALUE != this->hPipe) if (INVALID_HANDLE_VALUE != this->hPipe)
{ {
// Only create the thread, when not performing unit tests! // Only create the thread, when not performing unit tests!
if (!Loader::PerformingUnitTests()) if (!Loader::PerformingUnitTests())
{ {
this->mThreadAttached = true; this->mThreadAttached = true;
this->mThread = std::thread(Pipe::ReceiveThread, this); this->mThread = std::thread(Pipe::ReceiveThread, this);
} }
Logger::Print("Pipe successfully created\n"); Logger::Print("Pipe successfully created\n");
return true; return true;
} }
Logger::Print("Failed to create the pipe\n"); Logger::Print("Failed to create the pipe\n");
this->Destroy(); this->Destroy();
return false; return false;
} }
void Pipe::OnConnect(Pipe::Callback callback) void Pipe::OnConnect(Pipe::Callback callback)
{ {
this->ConnectCallback = callback; this->ConnectCallback = callback;
} }
void Pipe::SetCallback(std::string command, Pipe::PacketCallback callback) void Pipe::SetCallback(std::string command, Pipe::PacketCallback callback)
{ {
this->PacketCallbacks[command] = callback; this->PacketCallbacks[command] = callback;
} }
bool Pipe::Write(std::string command, std::string data) bool Pipe::Write(std::string command, std::string data)
{ {
if (this->mType != IPCTYPE_CLIENT || this->hPipe == INVALID_HANDLE_VALUE) return false; if (this->mType != IPCTYPE_CLIENT || this->hPipe == INVALID_HANDLE_VALUE) return false;
Pipe::Packet packet; Pipe::Packet packet;
strcpy_s(packet.Command, command.data()); strcpy_s(packet.Command, command.data());
strcpy_s(packet.Buffer, data.data()); strcpy_s(packet.Buffer, data.data());
DWORD cbBytes; DWORD cbBytes;
return (WriteFile(this->hPipe, &packet, sizeof(packet), &cbBytes, NULL) || GetLastError() == ERROR_IO_PENDING); return (WriteFile(this->hPipe, &packet, sizeof(packet), &cbBytes, NULL) || GetLastError() == ERROR_IO_PENDING);
} }
void Pipe::Destroy() void Pipe::Destroy()
{ {
//this->Type = IPCTYPE_NONE; //this->Type = IPCTYPE_NONE;
//*this->PipeFile = 0; //*this->PipeFile = 0;
//*this->PipeName = 0; //*this->PipeName = 0;
if (this->hPipe && INVALID_HANDLE_VALUE != this->hPipe) if (this->hPipe && INVALID_HANDLE_VALUE != this->hPipe)
{ {
if (this->mType == IPCTYPE_SERVER) DisconnectNamedPipe(this->hPipe); if (this->mType == IPCTYPE_SERVER) DisconnectNamedPipe(this->hPipe);
CloseHandle(this->hPipe); CloseHandle(this->hPipe);
Logger::Print("Disconnected from the pipe.\n"); Logger::Print("Disconnected from the pipe.\n");
} }
this->mThreadAttached = false; this->mThreadAttached = false;
if (this->mThread.joinable()) if (this->mThread.joinable())
{ {
Logger::Print("Terminating pipe thread...\n"); Logger::Print("Terminating pipe thread...\n");
this->mThread.join(); this->mThread.join();
Logger::Print("Pipe thread terminated.\n"); Logger::Print("Pipe thread terminated.\n");
} }
} }
void Pipe::SetName(std::string name) void Pipe::SetName(std::string name)
{ {
memset(this->PipeName, 0, sizeof(this->PipeName)); memset(this->PipeName, 0, sizeof(this->PipeName));
memset(this->PipeFile, 0, sizeof(this->PipeFile)); memset(this->PipeFile, 0, sizeof(this->PipeFile));
strncpy_s(this->PipeName, name.data(), sizeof(this->PipeName)); strncpy_s(this->PipeName, name.data(), sizeof(this->PipeName));
sprintf_s(this->PipeFile, sizeof(this->PipeFile), "\\\\.\\Pipe\\%s", this->PipeName); sprintf_s(this->PipeFile, sizeof(this->PipeFile), "\\\\.\\Pipe\\%s", this->PipeName);
} }
void Pipe::ReceiveThread(Pipe* pipe) void Pipe::ReceiveThread(Pipe* pipe)
{ {
if (!pipe || pipe->mType != IPCTYPE_SERVER || pipe->hPipe == INVALID_HANDLE_VALUE || !pipe->hPipe) return; if (!pipe || pipe->mType != IPCTYPE_SERVER || pipe->hPipe == INVALID_HANDLE_VALUE || !pipe->hPipe) return;
if (ConnectNamedPipe(pipe->hPipe, NULL) == FALSE) if (ConnectNamedPipe(pipe->hPipe, NULL) == FALSE)
{ {
Logger::Print("Failed to initialize pipe reading.\n"); Logger::Print("Failed to initialize pipe reading.\n");
return; return;
} }
Logger::Print("Client connected to the pipe\n"); Logger::Print("Client connected to the pipe\n");
if (pipe->ConnectCallback) pipe->ConnectCallback(); if (pipe->ConnectCallback) pipe->ConnectCallback();
DWORD cbBytes; DWORD cbBytes;
while (pipe->mThreadAttached && pipe->hPipe && pipe->hPipe != INVALID_HANDLE_VALUE) while (pipe->mThreadAttached && pipe->hPipe && pipe->hPipe != INVALID_HANDLE_VALUE)
{ {
BOOL bResult = ReadFile(pipe->hPipe, &pipe->mPacket, sizeof(pipe->mPacket), &cbBytes, NULL); BOOL bResult = ReadFile(pipe->hPipe, &pipe->mPacket, sizeof(pipe->mPacket), &cbBytes, NULL);
if (bResult && cbBytes) if (bResult && cbBytes)
{ {
if (pipe->PacketCallbacks.find(pipe->mPacket.Command) != pipe->PacketCallbacks.end()) if (pipe->PacketCallbacks.find(pipe->mPacket.Command) != pipe->PacketCallbacks.end())
{ {
pipe->PacketCallbacks[pipe->mPacket.Command](pipe->mPacket.Buffer); pipe->PacketCallbacks[pipe->mPacket.Command](pipe->mPacket.Buffer);
} }
} }
else if (pipe->mThreadAttached && pipe->hPipe != INVALID_HANDLE_VALUE) else if (pipe->mThreadAttached && pipe->hPipe != INVALID_HANDLE_VALUE)
{ {
Logger::Print("Failed to read from client through pipe\n"); Logger::Print("Failed to read from client through pipe\n");
DisconnectNamedPipe(pipe->hPipe); DisconnectNamedPipe(pipe->hPipe);
ConnectNamedPipe(pipe->hPipe, NULL); ConnectNamedPipe(pipe->hPipe, NULL);
if (pipe->ConnectCallback) pipe->ConnectCallback(); if (pipe->ConnectCallback) pipe->ConnectCallback();
} }
ZeroMemory(&pipe->mPacket, sizeof(pipe->mPacket)); ZeroMemory(&pipe->mPacket, sizeof(pipe->mPacket));
} }
} }
#pragma endregion #pragma endregion
// Callback to connect first instance's client pipe to the second instance's server pipe // Callback to connect first instance's client pipe to the second instance's server pipe
void IPCPipe::ConnectClient() void IPCPipe::ConnectClient()
{ {
if (Singleton::IsFirstInstance() && IPCPipe::ClientPipe) if (Singleton::IsFirstInstance() && IPCPipe::ClientPipe)
{ {
IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_CLIENT); IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_CLIENT);
} }
} }
// Writes to the process on the other end of the pipe // Writes to the process on the other end of the pipe
bool IPCPipe::Write(std::string command, std::string data) bool IPCPipe::Write(std::string command, std::string data)
{ {
if (IPCPipe::ClientPipe) if (IPCPipe::ClientPipe)
{ {
return IPCPipe::ClientPipe->Write(command, data); return IPCPipe::ClientPipe->Write(command, data);
} }
return false; return false;
} }
// Installs a callback for receiving commands from the process on the other end of the pipe // Installs a callback for receiving commands from the process on the other end of the pipe
void IPCPipe::On(std::string command, Pipe::PacketCallback callback) void IPCPipe::On(std::string command, Pipe::PacketCallback callback)
{ {
if (IPCPipe::ServerPipe) if (IPCPipe::ServerPipe)
{ {
IPCPipe::ServerPipe->SetCallback(command, callback); IPCPipe::ServerPipe->SetCallback(command, callback);
} }
} }
IPCPipe::IPCPipe() IPCPipe::IPCPipe()
{ {
if (Dedicated::IsDedicated()) return; if (Dedicated::IsEnabled()) return;
// Server pipe // Server pipe
IPCPipe::ServerPipe = new Pipe(); IPCPipe::ServerPipe = new Pipe();
IPCPipe::ServerPipe->OnConnect(IPCPipe::ConnectClient); IPCPipe::ServerPipe->OnConnect(IPCPipe::ConnectClient);
IPCPipe::ServerPipe->Create((Singleton::IsFirstInstance() ? IPC_PIPE_NAME_SERVER : IPC_PIPE_NAME_CLIENT)); IPCPipe::ServerPipe->Create((Singleton::IsFirstInstance() ? IPC_PIPE_NAME_SERVER : IPC_PIPE_NAME_CLIENT));
// Client pipe // Client pipe
IPCPipe::ClientPipe = new Pipe(); IPCPipe::ClientPipe = new Pipe();
// Connect second instance's client pipe to first instance's server pipe // Connect second instance's client pipe to first instance's server pipe
if (!Singleton::IsFirstInstance()) if (!Singleton::IsFirstInstance())
{ {
IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_SERVER); IPCPipe::ClientPipe->Connect(IPC_PIPE_NAME_SERVER);
} }
IPCPipe::On("ping", [] (std::string data) IPCPipe::On("ping", [] (std::string data)
{ {
Logger::Print("Received ping form pipe, sending pong!\n"); Logger::Print("Received ping form pipe, sending pong!\n");
IPCPipe::Write("pong", data); IPCPipe::Write("pong", data);
}); });
IPCPipe::On("pong", [] (std::string data) IPCPipe::On("pong", [] (std::string data)
{ {
Logger::Print("Received pong form pipe!\n"); Logger::Print("Received pong form pipe!\n");
}); });
// Test pipe functionality by sending pings // Test pipe functionality by sending pings
Command::Add("ipcping", [] (Command::Params params) Command::Add("ipcping", [] (Command::Params params)
{ {
Logger::Print("Sending ping to pipe!\n"); Logger::Print("Sending ping to pipe!\n");
IPCPipe::Write("ping", ""); IPCPipe::Write("ping", "");
}); });
} }
IPCPipe::~IPCPipe() IPCPipe::~IPCPipe()
{ {
if (IPCPipe::ServerPipe) delete IPCPipe::ServerPipe; if (IPCPipe::ServerPipe) delete IPCPipe::ServerPipe;
if (IPCPipe::ClientPipe) delete IPCPipe::ClientPipe; if (IPCPipe::ClientPipe) delete IPCPipe::ClientPipe;
IPCPipe::ServerPipe = 0; IPCPipe::ServerPipe = 0;
IPCPipe::ClientPipe = 0; IPCPipe::ClientPipe = 0;
} }
} }

View File

@ -8,7 +8,7 @@ namespace Components
bool Logger::IsConsoleReady() bool Logger::IsConsoleReady()
{ {
return (IsWindow(*reinterpret_cast<HWND*>(0x64A3288)) != FALSE || (Dedicated::IsDedicated() && !Flags::HasFlag("console"))); return (IsWindow(*reinterpret_cast<HWND*>(0x64A3288)) != FALSE || (Dedicated::IsEnabled() && !Flags::HasFlag("console")));
} }
void Logger::Print(const char* message, ...) void Logger::Print(const char* message, ...)

View File

@ -609,7 +609,7 @@ namespace Components
Menus::Menus() Menus::Menus()
{ {
if (Dedicated::IsDedicated()) return; if (Dedicated::IsEnabled()) return;
// Ensure everything is zero'ed // Ensure everything is zero'ed
Menus::FreeEverything(); Menus::FreeEverything();

View File

@ -6,14 +6,14 @@ namespace Components
void MusicalTalent::Replace(std::string sound, const char* file) void MusicalTalent::Replace(std::string sound, const char* file)
{ {
MusicalTalent::SoundAliasList[Utils::String::StrToLower(sound)] = file; MusicalTalent::SoundAliasList[Utils::String::ToLower(sound)] = file;
} }
Game::XAssetHeader MusicalTalent::ModifyAliases(Game::XAssetType type, std::string filename) Game::XAssetHeader MusicalTalent::ModifyAliases(Game::XAssetType type, std::string filename)
{ {
Game::XAssetHeader header = { 0 }; Game::XAssetHeader header = { 0 };
if (MusicalTalent::SoundAliasList.find(Utils::String::StrToLower(filename)) != MusicalTalent::SoundAliasList.end()) if (MusicalTalent::SoundAliasList.find(Utils::String::ToLower(filename)) != MusicalTalent::SoundAliasList.end())
{ {
Game::snd_alias_list_t* aliases = Game::DB_FindXAssetHeader(type, filename.data()).aliasList; Game::snd_alias_list_t* aliases = Game::DB_FindXAssetHeader(type, filename.data()).aliasList;
@ -21,7 +21,7 @@ namespace Components
{ {
if (aliases->aliases->stream->type == 2) if (aliases->aliases->stream->type == 2)
{ {
aliases->aliases->stream->file = MusicalTalent::SoundAliasList[Utils::String::StrToLower(filename)]; aliases->aliases->stream->file = MusicalTalent::SoundAliasList[Utils::String::ToLower(filename)];
} }
header.aliasList = aliases; header.aliasList = aliases;
@ -33,6 +33,8 @@ namespace Components
MusicalTalent::MusicalTalent() MusicalTalent::MusicalTalent()
{ {
if (ZoneBuilder::IsEnabled()) return;
AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_SOUND, MusicalTalent::ModifyAliases); AssetHandler::OnFind(Game::XAssetType::ASSET_TYPE_SOUND, MusicalTalent::ModifyAliases);
MusicalTalent::Replace("music_mainmenu_mp", "hz_t_menumusic.mp3"); MusicalTalent::Replace("music_mainmenu_mp", "hz_t_menumusic.mp3");

View File

@ -125,7 +125,7 @@ namespace Components
void Network::Handle(std::string packet, Network::Callback* callback) void Network::Handle(std::string packet, Network::Callback* callback)
{ {
Network::PacketHandlers[Utils::String::StrToLower(packet)] = callback; Network::PacketHandlers[Utils::String::ToLower(packet)] = callback;
} }
void Network::OnStart(Network::CallbackRaw* callback) void Network::OnStart(Network::CallbackRaw* callback)
@ -228,12 +228,12 @@ namespace Components
packetCommand = packetCommand.substr(0, pos); packetCommand = packetCommand.substr(0, pos);
} }
packetCommand = Utils::String::StrToLower(packetCommand); packetCommand = Utils::String::ToLower(packetCommand);
// Check if custom handler exists // Check if custom handler exists
for (auto i = Network::PacketHandlers.begin(); i != Network::PacketHandlers.end(); ++i) for (auto i = Network::PacketHandlers.begin(); i != Network::PacketHandlers.end(); ++i)
{ {
if (Utils::String::StrToLower(i->first) == packetCommand) if (Utils::String::ToLower(i->first) == packetCommand)
{ {
Network::SelectedPacket = i->first; Network::SelectedPacket = i->first;
return 0; return 0;

View File

@ -37,7 +37,7 @@ namespace Components
} }
void Node::StoreNodes(bool force) void Node::StoreNodes(bool force)
{ {
if (Dedicated::IsDedicated() && Dvar::Var("sv_lanOnly").Get<bool>()) return; if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
static int lastStorage = 0; static int lastStorage = 0;
@ -141,7 +141,7 @@ namespace Components
if (address.IsSelf()) return; if (address.IsSelf()) return;
Proto::Node::List list; Proto::Node::List list;
list.set_is_dedi(Dedicated::IsDedicated()); list.set_is_dedi(Dedicated::IsEnabled());
list.set_protocol(PROTOCOL); list.set_protocol(PROTOCOL);
list.set_version(NODE_VERSION); list.set_version(NODE_VERSION);
@ -222,7 +222,7 @@ namespace Components
entry->lastTime = Game::Sys_Milliseconds(); entry->lastTime = Game::Sys_Milliseconds();
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
entry->challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt()); entry->challenge = fmt::sprintf("%X", Utils::Cryptography::Rand::GenerateInt());
@ -245,7 +245,7 @@ namespace Components
void Node::FrameHandler() void Node::FrameHandler()
{ {
if (Dedicated::IsDedicated() && Dvar::Var("sv_lanOnly").Get<bool>()) return; if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").Get<bool>()) return;
// Frame limit // Frame limit
static int lastFrame = 0; static int lastFrame = 0;
@ -302,7 +302,7 @@ namespace Components
node.lastTime = Game::Sys_Milliseconds(); node.lastTime = Game::Sys_Milliseconds();
node.lastListQuery = Game::Sys_Milliseconds(); node.lastListQuery = Game::Sys_Milliseconds();
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
Network::SendCommand(node.address, "nodeListRequest"); Network::SendCommand(node.address, "nodeListRequest");
} }
@ -361,7 +361,7 @@ namespace Components
}); });
// Send deadline when shutting down // Send deadline when shutting down
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
QuickPatch::OnShutdown([] () QuickPatch::OnShutdown([] ()
{ {
@ -692,7 +692,7 @@ namespace Components
entry->state = Node::STATE_VALID; entry->state = Node::STATE_VALID;
entry->lastTime = Game::Sys_Milliseconds(); entry->lastTime = Game::Sys_Milliseconds();
if (!Dedicated::IsDedicated() && entry->isDedi && ServerList::IsOnlineList() && entry->protocol == PROTOCOL) if (!Dedicated::IsEnabled() && entry->isDedi && ServerList::IsOnlineList() && entry->protocol == PROTOCOL)
{ {
ServerList::InsertRequest(entry->address, true); ServerList::InsertRequest(entry->address, true);
} }
@ -739,7 +739,7 @@ namespace Components
// So we either have to register as node, or register a remote session // So we either have to register as node, or register a remote session
Network::Handle("nodeListError", [] (Network::Address address, std::string data) Network::Handle("nodeListError", [] (Network::Address address, std::string data)
{ {
if (Dedicated::IsDedicated()) if (Dedicated::IsEnabled())
{ {
Node::NodeEntry* entry = Node::FindNode(address); Node::NodeEntry* entry = Node::FindNode(address);
if (entry) if (entry)

View File

@ -115,7 +115,7 @@ namespace Components
Party::Party() Party::Party()
{ {
static Game::dvar_t* partyEnable = Dvar::Register<bool>("party_enable", Dedicated::IsDedicated(), Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system").Get<Game::dvar_t*>(); static Game::dvar_t* partyEnable = Dvar::Register<bool>("party_enable", Dedicated::IsEnabled(), Game::dvar_flag::DVAR_FLAG_NONE, "Enable party system").Get<Game::dvar_t*>();
Dvar::Register<bool>("xblive_privatematch", true, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "").Get<Game::dvar_t*>(); Dvar::Register<bool>("xblive_privatematch", true, Game::dvar_flag::DVAR_FLAG_WRITEPROTECTED, "").Get<Game::dvar_t*>();
// various changes to SV_DirectConnect-y stuff to allow non-party joinees // various changes to SV_DirectConnect-y stuff to allow non-party joinees

View File

@ -11,7 +11,7 @@ namespace Components
if (Utils::Hook::Get<bool>(0x1AD3680)) return; if (Utils::Hook::Get<bool>(0x1AD3680)) return;
// Don't load playlists when dedi and no party // Don't load playlists when dedi and no party
if (Dedicated::IsDedicated() && !Dvar::Var("party_enable").Get<bool>()) if (Dedicated::IsEnabled() && !Dvar::Var("party_enable").Get<bool>())
{ {
Utils::Hook::Set<bool>(0x1AD3680, true); // Set received to true Utils::Hook::Set<bool>(0x1AD3680, true); // Set received to true
Dvar::Var("xblive_privateserver").Set(true); Dvar::Var("xblive_privateserver").Set(true);

View File

@ -23,7 +23,7 @@ namespace Components
void QuickPatch::OnFrame(QuickPatch::Callback* callback) void QuickPatch::OnFrame(QuickPatch::Callback* callback)
{ {
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())
{ {
Dedicated::OnFrame(callback); Dedicated::OnFrame(callback);
} }
@ -35,7 +35,7 @@ namespace Components
void QuickPatch::Once(QuickPatch::Callback* callback) void QuickPatch::Once(QuickPatch::Callback* callback)
{ {
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled())
{ {
Dedicated::Once(callback); Dedicated::Once(callback);
} }
@ -157,7 +157,7 @@ namespace Components
{ {
Utils::Hook::Set<char*>(0x4289E8, "IW4x (r" REVISION_STR REVISION_SUFFIX "): ZoneBuilder"); Utils::Hook::Set<char*>(0x4289E8, "IW4x (r" REVISION_STR REVISION_SUFFIX "): ZoneBuilder");
} }
else if (Dedicated::IsDedicated()) else if (Dedicated::IsEnabled())
{ {
Utils::Hook::Set<char*>(0x4289E8, "IW4x (r" REVISION_STR REVISION_SUFFIX "): Dedicated"); Utils::Hook::Set<char*>(0x4289E8, "IW4x (r" REVISION_STR REVISION_SUFFIX "): Dedicated");
} }
@ -322,8 +322,9 @@ namespace Components
//Utils::Hook::Set<BYTE>(0x68323A, 0xEB); //Utils::Hook::Set<BYTE>(0x68323A, 0xEB);
// Exploit fixes // Exploit fixes
Utils::Hook(0x414D92, QuickPatch::MsgReadBitsCompressCheckSV, HOOK_CALL).Install()->Quick(); Utils::Hook::Set<BYTE>(0x412370, 0xC3); // SV_SteamAuthClient
Utils::Hook(0x4A9F56, QuickPatch::MsgReadBitsCompressCheckCL, HOOK_CALL).Install()->Quick(); Utils::Hook(0x414D92, QuickPatch::MsgReadBitsCompressCheckSV, HOOK_CALL).Install()->Quick(); // SV_ExecuteClientCommands
Utils::Hook(0x4A9F56, QuickPatch::MsgReadBitsCompressCheckCL, HOOK_CALL).Install()->Quick(); // CL_ParseServerMessage
Command::Add("unlockstats", [] (Command::Params params) Command::Add("unlockstats", [] (Command::Params params)
{ {

View File

@ -46,7 +46,7 @@ namespace Components
}); });
// TODO: Maybe execute that for clients as well, when we use triangular natting. // TODO: Maybe execute that for clients as well, when we use triangular natting.
if (!Dedicated::IsDedicated()) return; if (!Dedicated::IsEnabled()) return;
// Load public key // Load public key
static uint8_t publicKey[] = static uint8_t publicKey[] =

View File

@ -1,29 +1,29 @@
#include "STDInclude.hpp" #include "STDInclude.hpp"
namespace Components namespace Components
{ {
bool Singleton::FirstInstance = true; bool Singleton::FirstInstance = true;
bool Singleton::IsFirstInstance() bool Singleton::IsFirstInstance()
{ {
return Singleton::FirstInstance; return Singleton::FirstInstance;
} }
Singleton::Singleton() Singleton::Singleton()
{ {
if (Flags::HasFlag("version")) if (Flags::HasFlag("version"))
{ {
printf("IW4x r" REVISION_STR "-" MILESTONE " (built " __DATE__ " " __TIME__ ")\n"); printf("IW4x r" REVISION_STR "-" MILESTONE " (built " __DATE__ " " __TIME__ ")\n");
ExitProcess(0); ExitProcess(0);
} }
if (Dedicated::IsDedicated() || ZoneBuilder::IsEnabled()) return; if (Dedicated::IsEnabled() || ZoneBuilder::IsEnabled()) return;
Singleton::FirstInstance = (CreateMutexA(NULL, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS); Singleton::FirstInstance = (CreateMutexA(NULL, FALSE, "iw4x_mutex") && GetLastError() != ERROR_ALREADY_EXISTS);
if (!Singleton::FirstInstance && !ConnectProtocol::Used() && MessageBoxA(0, "Do you want to start another instance?", "Game already running", MB_ICONEXCLAMATION | MB_YESNO) == IDNO) if (!Singleton::FirstInstance && !ConnectProtocol::Used() && MessageBoxA(0, "Do you want to start another instance?", "Game already running", MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
{ {
ExitProcess(0); ExitProcess(0);
} }
} }
} }

View File

@ -366,7 +366,7 @@ namespace Components
UIFeeder::Add(10.0f, Theatre::GetDemoCount, Theatre::GetDemoText, Theatre::SelectDemo); UIFeeder::Add(10.0f, Theatre::GetDemoCount, Theatre::GetDemoText, Theatre::SelectDemo);
// set the configstrings stuff to load the default (empty) string table; this should allow demo recording on all gametypes/maps // set the configstrings stuff to load the default (empty) string table; this should allow demo recording on all gametypes/maps
if(!Dedicated::IsDedicated()) Utils::Hook::Set<char*>(0x47440B, "mp/defaultStringTable.csv"); if(!Dedicated::IsEnabled()) Utils::Hook::Set<char*>(0x47440B, "mp/defaultStringTable.csv");
// Change font size // Change font size
Utils::Hook::Set<BYTE>(0x5AC854, 2); Utils::Hook::Set<BYTE>(0x5AC854, 2);

View File

@ -95,7 +95,7 @@ namespace Components
// Text // Text
float leftText = width / 2 - bWidth / 2 - cornerSize + iOffsetLeft * 2 + imgDim; float leftText = width / 2 - bWidth / 2 - cornerSize + iOffsetLeft * 2 + imgDim;
float rightText = width / 2 + bWidth / 2 - cornerSize - iOffsetLeft; float rightText = width / 2 + bWidth / 2 - cornerSize - iOffsetLeft;
Game::R_AddCmdDrawText(Utils::String::StrToUpper(toast->Title).data(), 0x7FFFFFFF, font, static_cast<float>(leftText + (rightText - leftText) / 2 - titleSize / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 7), fontSize, fontSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Title Game::R_AddCmdDrawText(Utils::String::ToUpper(toast->Title).data(), 0x7FFFFFFF, font, static_cast<float>(leftText + (rightText - leftText) / 2 - titleSize / 2 + cornerSize), static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 7), fontSize, fontSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Title
Game::R_AddCmdDrawText(toast->Desc.data(), 0x7FFFFFFF, descfont, leftText + (rightText - leftText) / 2 - descrSize / 2 + cornerSize, static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 33), descSize, descSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Description Game::R_AddCmdDrawText(toast->Desc.data(), 0x7FFFFFFF, descfont, leftText + (rightText - leftText) / 2 - descrSize / 2 + cornerSize, static_cast<float>(height - bHeight / 2 + cornerSize * 2 + 33), descSize, descSize, 0, wColor, Game::ITEM_TEXTSTYLE_SHADOWED); // Description
} }

View File

@ -441,7 +441,7 @@ namespace Components
bool ZoneBuilder::IsEnabled() bool ZoneBuilder::IsEnabled()
{ {
return (Flags::HasFlag("zonebuilder") && !Dedicated::IsDedicated()); return (Flags::HasFlag("zonebuilder") && !Dedicated::IsEnabled());
} }
void ZoneBuilder::BeginAssetTrace(std::string zone) void ZoneBuilder::BeginAssetTrace(std::string zone)

View File

@ -12,32 +12,32 @@
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <stdio.h> //#include <stdio.h>
#include <string.h> //#include <string.h>
#include <wincrypt.h> //#include <wincrypt.h>
#include <time.h> //#include <time.h>
#include <timeapi.h> #include <timeapi.h>
#include <shellapi.h> #include <shellapi.h>
#include <shlwapi.h> //#include <shlwapi.h>
#include <WinSock2.h> //#include <WinSock2.h>
#include <Wininet.h> #include <Wininet.h>
#include <Urlmon.h> //#include <Urlmon.h>
#include <d3d9.h> #include <d3d9.h>
#include <map> //#include <map>
#include <mutex> //#include <mutex>
#include <string> //#include <string>
#include <vector> //#include <vector>
#include <sstream> #include <sstream>
#include <fstream> #include <fstream>
#include <utility> //#include <utility>
#include <algorithm> //#include <algorithm>
#include <functional> //#include <functional>
#include <cctype> #include <cctype>
#include <locale> //#include <locale>
#include <regex> #include <regex>
#include <thread> #include <thread>
#include <chrono> //#include <chrono>
#include <future> #include <future>
#include <queue> #include <queue>

View File

@ -1,102 +1,102 @@
#include "STDInclude.hpp" #include "STDInclude.hpp"
namespace Steam namespace Steam
{ {
int User::GetHSteamUser() int User::GetHSteamUser()
{ {
return NULL; return NULL;
} }
bool User::LoggedOn() bool User::LoggedOn()
{ {
return true; return true;
} }
SteamID User::GetSteamID() SteamID User::GetSteamID()
{ {
static unsigned int subId = 0; static unsigned int subId = 0;
SteamID id; SteamID id;
if (!subId) if (!subId)
{ {
if (Components::Dedicated::IsDedicated() || Components::ZoneBuilder::IsEnabled()) // Dedi guid if (Components::Dedicated::IsEnabled() || Components::ZoneBuilder::IsEnabled()) // Dedi guid
{ {
subId = ~0xDED1CA7E; subId = ~0xDED1CA7E;
} }
else if (Components::Singleton::IsFirstInstance()) // ECDSA guid else if (Components::Singleton::IsFirstInstance()) // ECDSA guid
{ {
subId = Components::Auth::GetKeyHash(); subId = Components::Auth::GetKeyHash();
} }
else // Random guid else // Random guid
{ {
subId = (Game::Sys_Milliseconds() + timeGetTime()); subId = (Game::Sys_Milliseconds() + timeGetTime());
} }
subId &= ~0x80000000; // Ensure it's positive subId &= ~0x80000000; // Ensure it's positive
} }
id.Bits = 0x110000100000000 | subId; id.Bits = 0x110000100000000 | subId;
return id; return id;
} }
int User::InitiateGameConnection(void *pAuthBlob, int cbMaxAuthBlob, SteamID steamIDGameServer, unsigned int unIPServer, unsigned short usPortServer, bool bSecure) int User::InitiateGameConnection(void *pAuthBlob, int cbMaxAuthBlob, SteamID steamIDGameServer, unsigned int unIPServer, unsigned short usPortServer, bool bSecure)
{ {
Components::Logger::Print("%s\n", __FUNCTION__); Components::Logger::Print("%s\n", __FUNCTION__);
return 0; return 0;
} }
void User::TerminateGameConnection(unsigned int unIPServer, unsigned short usPortServer) void User::TerminateGameConnection(unsigned int unIPServer, unsigned short usPortServer)
{ {
} }
void User::TrackAppUsageEvent(SteamID gameID, int eAppUsageEvent, const char *pchExtraInfo) void User::TrackAppUsageEvent(SteamID gameID, int eAppUsageEvent, const char *pchExtraInfo)
{ {
} }
bool User::GetUserDataFolder(char *pchBuffer, int cubBuffer) bool User::GetUserDataFolder(char *pchBuffer, int cubBuffer)
{ {
return false; return false;
} }
void User::StartVoiceRecording() void User::StartVoiceRecording()
{ {
} }
void User::StopVoiceRecording() void User::StopVoiceRecording()
{ {
} }
int User::GetCompressedVoice(void *pDestBuffer, unsigned int cbDestBufferSize, unsigned int *nBytesWritten) int User::GetCompressedVoice(void *pDestBuffer, unsigned int cbDestBufferSize, unsigned int *nBytesWritten)
{ {
return 0; return 0;
} }
int User::DecompressVoice(void *pCompressed, unsigned int cbCompressed, void *pDestBuffer, unsigned int cbDestBufferSize, unsigned int *nBytesWritten) int User::DecompressVoice(void *pCompressed, unsigned int cbCompressed, void *pDestBuffer, unsigned int cbDestBufferSize, unsigned int *nBytesWritten)
{ {
return 0; return 0;
} }
unsigned int User::GetAuthSessionTicket(void *pTicket, int cbMaxTicket, unsigned int *pcbTicket) unsigned int User::GetAuthSessionTicket(void *pTicket, int cbMaxTicket, unsigned int *pcbTicket)
{ {
return 0; return 0;
} }
int User::BeginAuthSession(const void *pAuthTicket, int cbAuthTicket, SteamID steamID) int User::BeginAuthSession(const void *pAuthTicket, int cbAuthTicket, SteamID steamID)
{ {
return 0; return 0;
} }
void User::EndAuthSession(SteamID steamID) void User::EndAuthSession(SteamID steamID)
{ {
} }
void User::CancelAuthTicket(unsigned int hAuthTicket) void User::CancelAuthTicket(unsigned int hAuthTicket)
{ {
} }
unsigned int User::UserHasLicenseForApp(SteamID steamID, unsigned int appID) unsigned int User::UserHasLicenseForApp(SteamID steamID, unsigned int appID)
{ {
return 0; return 0;
} }
} }

View File

@ -4,13 +4,13 @@ namespace Utils
{ {
namespace String namespace String
{ {
std::string StrToLower(std::string input) std::string ToLower(std::string input)
{ {
std::transform(input.begin(), input.end(), input.begin(), ::tolower); std::transform(input.begin(), input.end(), input.begin(), ::tolower);
return input; return input;
} }
std::string StrToUpper(std::string input) std::string ToUpper(std::string input)
{ {
std::transform(input.begin(), input.end(), input.begin(), ::toupper); std::transform(input.begin(), input.end(), input.begin(), ::toupper);
return input; return input;
@ -38,7 +38,7 @@ namespace Utils
return result; return result;
} }
std::string XORString(std::string str, char value) std::string XOR(std::string str, char value)
{ {
for (unsigned int i = 0; i < str.size(); ++i) for (unsigned int i = 0; i < str.size(); ++i)
{ {

View File

@ -19,8 +19,8 @@ namespace Utils
return buffer; return buffer;
} }
std::string StrToLower(std::string input); std::string ToLower(std::string input);
std::string StrToUpper(std::string input); std::string ToUpper(std::string input);
bool EndsWith(std::string haystack, std::string needle); bool EndsWith(std::string haystack, std::string needle);
std::vector<std::string> Explode(const std::string& str, char delim); std::vector<std::string> Explode(const std::string& str, char delim);
void Replace(std::string &string, std::string find, std::string replace); void Replace(std::string &string, std::string find, std::string replace);
@ -33,6 +33,6 @@ namespace Utils
std::string DumpHex(std::string data, std::string separator = " "); std::string DumpHex(std::string data, std::string separator = " ");
std::string XORString(std::string str, char value); std::string XOR(std::string str, char value);
} }
} }

View File

@ -1,462 +1,463 @@
#include "STDInclude.hpp" #include "STDInclude.hpp"
#include <shlwapi.h>
namespace Utils
{ namespace Utils
WebIO::WebIO() : WebIO("WebIO") {} {
WebIO::WebIO() : WebIO("WebIO") {}
WebIO::WebIO(std::string useragent, std::string url) : WebIO(useragent)
{ WebIO::WebIO(std::string useragent, std::string url) : WebIO(useragent)
WebIO::SetURL(url); {
} WebIO::SetURL(url);
}
WebIO::WebIO(std::string useragent) : m_timeout(5000) // 5 seconds timeout by default
{ WebIO::WebIO(std::string useragent) : m_timeout(5000) // 5 seconds timeout by default
WebIO::OpenSession(useragent); {
} WebIO::OpenSession(useragent);
}
WebIO::~WebIO()
{ WebIO::~WebIO()
WebIO::m_username.clear(); {
WebIO::m_password.clear(); WebIO::m_username.clear();
WebIO::m_password.clear();
WebIO::CloseConnection();
WebIO::CloseSession(); WebIO::CloseConnection();
} WebIO::CloseSession();
}
void WebIO::OpenSession(std::string useragent)
{ void WebIO::OpenSession(std::string useragent)
WebIO::m_hSession = InternetOpenA(useragent.data(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); {
} WebIO::m_hSession = InternetOpenA(useragent.data(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
}
void WebIO::CloseSession()
{ void WebIO::CloseSession()
InternetCloseHandle(WebIO::m_hSession); {
} InternetCloseHandle(WebIO::m_hSession);
}
void WebIO::SetCredentials(std::string username, std::string password)
{ void WebIO::SetCredentials(std::string username, std::string password)
WebIO::m_username.clear(); {
WebIO::m_password.clear(); WebIO::m_username.clear();
WebIO::m_password.clear();
WebIO::m_username.append(username.begin(), username.end());
WebIO::m_password.append(password.begin(), password.end()); WebIO::m_username.append(username.begin(), username.end());
} WebIO::m_password.append(password.begin(), password.end());
}
void WebIO::SetURL(std::string url)
{ void WebIO::SetURL(std::string url)
WebIO::m_sUrl.server.clear(); {
WebIO::m_sUrl.protocol.clear(); WebIO::m_sUrl.server.clear();
WebIO::m_sUrl.document.clear(); WebIO::m_sUrl.protocol.clear();
WebIO::m_sUrl.document.clear();
// Insert protocol if none
if (url.find("://") == std::string::npos) // Insert protocol if none
{ if (url.find("://") == std::string::npos)
url = "http://" + url; {
} url = "http://" + url;
}
PARSEDURLA pURL;
pURL.cbSize = sizeof(pURL); PARSEDURLA pURL;
ParseURLA(url.data(), &pURL); pURL.cbSize = sizeof(pURL);
ParseURLA(url.data(), &pURL);
// Parse protocol
if (pURL.cchProtocol && pURL.cchProtocol != 0xCCCCCCCC && pURL.pszProtocol) // Parse protocol
{ if (pURL.cchProtocol && pURL.cchProtocol != 0xCCCCCCCC && pURL.pszProtocol)
for (UINT i = 0; i < pURL.cchProtocol; ++i) {
{ for (UINT i = 0; i < pURL.cchProtocol; ++i)
char lChar = static_cast<char>(tolower(pURL.pszProtocol[i])); {
WebIO::m_sUrl.protocol.append(&lChar, 1); char lChar = static_cast<char>(tolower(pURL.pszProtocol[i]));
} WebIO::m_sUrl.protocol.append(&lChar, 1);
} }
else }
{ else
WebIO::m_sUrl.protocol.append("http"); {
} WebIO::m_sUrl.protocol.append("http");
}
// Parse suffix
std::string server; // Parse suffix
std::string server;
if (pURL.cchSuffix && pURL.cchSuffix != 0xCCCCCCCC && pURL.pszSuffix)
{ if (pURL.cchSuffix && pURL.cchSuffix != 0xCCCCCCCC && pURL.pszSuffix)
server.append(pURL.pszSuffix, pURL.cchSuffix); {
} server.append(pURL.pszSuffix, pURL.cchSuffix);
else }
{ else
// TODO: Add some error handling here {
return; // TODO: Add some error handling here
} return;
}
// Remove '//' from the url
if (!server.find("//")) // Remove '//' from the url
{ if (!server.find("//"))
server = server.substr(2); {
} server = server.substr(2);
}
size_t pos = server.find("/");
if (pos == std::string::npos) size_t pos = server.find("/");
{ if (pos == std::string::npos)
WebIO::m_sUrl.server = server; {
WebIO::m_sUrl.document = "/"; WebIO::m_sUrl.server = server;
} WebIO::m_sUrl.document = "/";
else }
{ else
WebIO::m_sUrl.server = server.substr(0, pos); {
WebIO::m_sUrl.document = server.substr(pos); WebIO::m_sUrl.server = server.substr(0, pos);
} WebIO::m_sUrl.document = server.substr(pos);
}
WebIO::m_sUrl.raw.clear();
WebIO::m_sUrl.raw.append(WebIO::m_sUrl.protocol); WebIO::m_sUrl.raw.clear();
WebIO::m_sUrl.raw.append("://"); WebIO::m_sUrl.raw.append(WebIO::m_sUrl.protocol);
WebIO::m_sUrl.raw.append(WebIO::m_sUrl.server); WebIO::m_sUrl.raw.append("://");
WebIO::m_sUrl.raw.append(WebIO::m_sUrl.document); WebIO::m_sUrl.raw.append(WebIO::m_sUrl.server);
WebIO::m_sUrl.raw.append(WebIO::m_sUrl.document);
WebIO::m_isFTP = (WebIO::m_sUrl.protocol == "ftp");
} WebIO::m_isFTP = (WebIO::m_sUrl.protocol == "ftp");
}
std::string WebIO::BuildPostBody(WebIO::Params params)
{ std::string WebIO::BuildPostBody(WebIO::Params params)
std::string body; {
std::string body;
for (auto param = params.begin(); param != params.end(); ++param)
{ for (auto param = params.begin(); param != params.end(); ++param)
std::string key = param->first; {
std::string value = param->second; std::string key = param->first;
std::string value = param->second;
if (!body.empty()) body.append("&");
if (!body.empty()) body.append("&");
body.append(key);
body.append("="); body.append(key);
body.append(value); body.append("=");
} body.append(value);
}
body.append("\0");
body.append("\0");
return body;
} return body;
}
std::string WebIO::Post(std::string url, std::string body)
{ std::string WebIO::Post(std::string url, std::string body)
WebIO::SetURL(url); {
return WebIO::Post(body); WebIO::SetURL(url);
} return WebIO::Post(body);
}
std::string WebIO::Post(std::string url, WebIO::Params params)
{ std::string WebIO::Post(std::string url, WebIO::Params params)
WebIO::SetURL(url); {
return WebIO::Post(params); WebIO::SetURL(url);
} return WebIO::Post(params);
}
std::string WebIO::Post(WebIO::Params params)
{ std::string WebIO::Post(WebIO::Params params)
return WebIO::Post(WebIO::BuildPostBody(params)); {
} return WebIO::Post(WebIO::BuildPostBody(params));
}
std::string WebIO::Post(std::string body)
{ std::string WebIO::Post(std::string body)
return WebIO::Execute("POST", body); {
} return WebIO::Execute("POST", body);
}
std::string WebIO::Get(std::string url)
{ std::string WebIO::Get(std::string url)
WebIO::SetURL(url); {
return WebIO::Get(); WebIO::SetURL(url);
} return WebIO::Get();
}
std::string WebIO::Get()
{ std::string WebIO::Get()
return WebIO::Execute("GET", ""); {
} return WebIO::Execute("GET", "");
}
bool WebIO::OpenConnection()
{ bool WebIO::OpenConnection()
WORD wPort = INTERNET_DEFAULT_HTTP_PORT; {
DWORD dwService = INTERNET_SERVICE_HTTP; WORD wPort = INTERNET_DEFAULT_HTTP_PORT;
DWORD dwFlag = 0; DWORD dwService = INTERNET_SERVICE_HTTP;
DWORD dwFlag = 0;
if (WebIO::m_isFTP)
{ if (WebIO::m_isFTP)
wPort = INTERNET_DEFAULT_FTP_PORT; {
dwService = INTERNET_SERVICE_FTP; wPort = INTERNET_DEFAULT_FTP_PORT;
dwFlag = INTERNET_FLAG_PASSIVE; dwService = INTERNET_SERVICE_FTP;
} dwFlag = INTERNET_FLAG_PASSIVE;
else if (WebIO::IsSecuredConnection()) }
{ else if (WebIO::IsSecuredConnection())
wPort = INTERNET_DEFAULT_HTTPS_PORT; {
} wPort = INTERNET_DEFAULT_HTTPS_PORT;
}
const char* username = (WebIO::m_username.size() ? WebIO::m_username.data() : NULL);
const char* password = (WebIO::m_password.size() ? WebIO::m_password.data() : NULL); const char* username = (WebIO::m_username.size() ? WebIO::m_username.data() : NULL);
WebIO::m_hConnect = InternetConnectA(WebIO::m_hSession, WebIO::m_sUrl.server.data(), wPort, username, password, dwService, dwFlag, 0); const char* password = (WebIO::m_password.size() ? WebIO::m_password.data() : NULL);
WebIO::m_hConnect = InternetConnectA(WebIO::m_hSession, WebIO::m_sUrl.server.data(), wPort, username, password, dwService, dwFlag, 0);
return (WebIO::m_hConnect && WebIO::m_hConnect != INVALID_HANDLE_VALUE);
} return (WebIO::m_hConnect && WebIO::m_hConnect != INVALID_HANDLE_VALUE);
}
void WebIO::CloseConnection()
{ void WebIO::CloseConnection()
if (WebIO::m_hFile && WebIO::m_hFile != INVALID_HANDLE_VALUE) InternetCloseHandle(WebIO::m_hFile); {
if (WebIO::m_hConnect && WebIO::m_hConnect != INVALID_HANDLE_VALUE) InternetCloseHandle(WebIO::m_hConnect); if (WebIO::m_hFile && WebIO::m_hFile != INVALID_HANDLE_VALUE) InternetCloseHandle(WebIO::m_hFile);
} if (WebIO::m_hConnect && WebIO::m_hConnect != INVALID_HANDLE_VALUE) InternetCloseHandle(WebIO::m_hConnect);
}
WebIO* WebIO::SetTimeout(DWORD mseconds)
{ WebIO* WebIO::SetTimeout(DWORD mseconds)
this->m_timeout = mseconds; {
return this; this->m_timeout = mseconds;
} return this;
}
std::string WebIO::Execute(const char* command, std::string body)
{ std::string WebIO::Execute(const char* command, std::string body)
if (!WebIO::OpenConnection()) return ""; {
if (!WebIO::OpenConnection()) return "";
const char *acceptTypes[] = { "application/x-www-form-urlencoded", nullptr };
const char *acceptTypes[] = { "application/x-www-form-urlencoded", nullptr };
DWORD dwFlag = INTERNET_FLAG_RELOAD | (WebIO::IsSecuredConnection() ? INTERNET_FLAG_SECURE : 0);
DWORD dwFlag = INTERNET_FLAG_RELOAD | (WebIO::IsSecuredConnection() ? INTERNET_FLAG_SECURE : 0);
// This doesn't seem to actually do anything, half of those options don't even seem to be implemented.
// Good job microsoft... ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa385328%28v=vs.85%29.aspx ) // This doesn't seem to actually do anything, half of those options don't even seem to be implemented.
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_CONNECT_TIMEOUT, &m_timeout, sizeof(m_timeout)); // Good job microsoft... ( https://msdn.microsoft.com/en-us/library/windows/desktop/aa385328%28v=vs.85%29.aspx )
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_RECEIVE_TIMEOUT, &m_timeout, sizeof(m_timeout)); //InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_CONNECT_TIMEOUT, &m_timeout, sizeof(m_timeout));
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_SEND_TIMEOUT, &m_timeout, sizeof(m_timeout)); //InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_RECEIVE_TIMEOUT, &m_timeout, sizeof(m_timeout));
//InternetSetOption(WebIO::m_hConnect, INTERNET_OPTION_SEND_TIMEOUT, &m_timeout, sizeof(m_timeout));
WebIO::m_hFile = HttpOpenRequestA(WebIO::m_hConnect, command, WebIO::m_sUrl.document.data(), NULL, NULL, acceptTypes, dwFlag, 0);
WebIO::m_hFile = HttpOpenRequestA(WebIO::m_hConnect, command, WebIO::m_sUrl.document.data(), NULL, NULL, acceptTypes, dwFlag, 0);
if (!WebIO::m_hFile || WebIO::m_hFile == INVALID_HANDLE_VALUE)
{ if (!WebIO::m_hFile || WebIO::m_hFile == INVALID_HANDLE_VALUE)
WebIO::CloseConnection(); {
return ""; WebIO::CloseConnection();
} return "";
}
const char* headers = "Content-type: application/x-www-form-urlencoded";
HttpSendRequestA(WebIO::m_hFile, headers, strlen(headers), const_cast<char*>(body.data()), body.size() + 1); const char* headers = "Content-type: application/x-www-form-urlencoded";
HttpSendRequestA(WebIO::m_hFile, headers, strlen(headers), const_cast<char*>(body.data()), body.size() + 1);
std::string returnBuffer;
std::string returnBuffer;
DWORD size = 0;
char buffer[0x2001] = { 0 }; DWORD size = 0;
char buffer[0x2001] = { 0 };
while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
{ while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
returnBuffer.append(buffer, size); {
if (!size) break; returnBuffer.append(buffer, size);
} if (!size) break;
}
WebIO::CloseConnection();
WebIO::CloseConnection();
return returnBuffer;
} return returnBuffer;
}
bool WebIO::IsSecuredConnection()
{ bool WebIO::IsSecuredConnection()
return (WebIO::m_sUrl.protocol == "https"); {
} return (WebIO::m_sUrl.protocol == "https");
}
bool WebIO::Connect()
{ bool WebIO::Connect()
return WebIO::OpenConnection(); {
} return WebIO::OpenConnection();
}
void WebIO::Disconnect()
{ void WebIO::Disconnect()
WebIO::CloseConnection(); {
} WebIO::CloseConnection();
}
bool WebIO::SetDirectory(std::string directory)
{ bool WebIO::SetDirectory(std::string directory)
return (FtpSetCurrentDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE); {
} return (FtpSetCurrentDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
}
bool WebIO::SetRelativeDirectory(std::string directory)
{ bool WebIO::SetRelativeDirectory(std::string directory)
std::string currentDir; {
std::string currentDir;
if (WebIO::GetDirectory(currentDir))
{ if (WebIO::GetDirectory(currentDir))
WebIO::FormatPath(directory, true); {
WebIO::FormatPath(currentDir, true); WebIO::FormatPath(directory, true);
WebIO::FormatPath(currentDir, true);
char path[MAX_PATH] = { 0 };
PathCombineA(path, currentDir.data(), directory.data()); char path[MAX_PATH] = { 0 };
PathCombineA(path, currentDir.data(), directory.data());
std::string newPath(path);
WebIO::FormatPath(newPath, false); std::string newPath(path);
WebIO::FormatPath(newPath, false);
return WebIO::SetDirectory(newPath);
} return WebIO::SetDirectory(newPath);
}
return false;
} return false;
}
bool WebIO::GetDirectory(std::string &directory)
{ bool WebIO::GetDirectory(std::string &directory)
directory.clear(); {
directory.clear();
DWORD size = MAX_PATH;
char currentDir[MAX_PATH] = { 0 }; DWORD size = MAX_PATH;
char currentDir[MAX_PATH] = { 0 };
if (FtpGetCurrentDirectoryA(WebIO::m_hConnect, currentDir, &size) == TRUE)
{ if (FtpGetCurrentDirectoryA(WebIO::m_hConnect, currentDir, &size) == TRUE)
directory.append(currentDir, size); {
return true; directory.append(currentDir, size);
} return true;
}
return false;
} return false;
}
void WebIO::FormatPath(std::string &path, bool win)
{ void WebIO::FormatPath(std::string &path, bool win)
size_t nPos; {
std::string find = "\\"; size_t nPos;
std::string replace = "/"; std::string find = "\\";
std::string replace = "/";
if (win)
{ if (win)
find = "/"; {
replace = "\\"; find = "/";
} replace = "\\";
}
while ((nPos = path.find(find)) != std::wstring::npos)
{ while ((nPos = path.find(find)) != std::wstring::npos)
path = path.replace(nPos, find.length(), replace); {
} path = path.replace(nPos, find.length(), replace);
} }
}
bool WebIO::CreateDirectory(std::string directory)
{ bool WebIO::CreateDirectory(std::string directory)
return (FtpCreateDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE); {
} return (FtpCreateDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
}
// Recursively delete a directory
bool WebIO::DeleteDirectory(std::string directory) // Recursively delete a directory
{ bool WebIO::DeleteDirectory(std::string directory)
std::string tempDir; {
WebIO::GetDirectory(tempDir); std::string tempDir;
WebIO::GetDirectory(tempDir);
WebIO::SetRelativeDirectory(directory);
WebIO::SetRelativeDirectory(directory);
std::vector<std::string> list;
std::vector<std::string> list;
WebIO::ListFiles(".", list);
for (auto file : list) WebIO::DeleteFile(file); WebIO::ListFiles(".", list);
for (auto file : list) WebIO::DeleteFile(file);
WebIO::ListDirectories(".", list);
for (auto dir : list) WebIO::DeleteDirectory(dir); WebIO::ListDirectories(".", list);
for (auto dir : list) WebIO::DeleteDirectory(dir);
WebIO::SetDirectory(tempDir);
WebIO::SetDirectory(tempDir);
return (FtpRemoveDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
} return (FtpRemoveDirectoryA(WebIO::m_hConnect, directory.data()) == TRUE);
}
bool WebIO::RenameDirectory(std::string directory, std::string newDir)
{ bool WebIO::RenameDirectory(std::string directory, std::string newDir)
return (FtpRenameFileA(WebIO::m_hConnect, directory.data(), newDir.data()) == TRUE); // According to the internetz, this should work {
} return (FtpRenameFileA(WebIO::m_hConnect, directory.data(), newDir.data()) == TRUE); // According to the internetz, this should work
}
bool WebIO::ListElements(std::string directory, std::vector<std::string> &list, bool files)
{ bool WebIO::ListElements(std::string directory, std::vector<std::string> &list, bool files)
list.clear(); {
list.clear();
WIN32_FIND_DATAA findFileData;
bool result = false; WIN32_FIND_DATAA findFileData;
DWORD dwAttribute = (files ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_DIRECTORY); bool result = false;
DWORD dwAttribute = (files ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_DIRECTORY);
// Any filename.
std::string tempDir; // Any filename.
WebIO::GetDirectory(tempDir); std::string tempDir;
WebIO::SetRelativeDirectory(directory); WebIO::GetDirectory(tempDir);
WebIO::SetRelativeDirectory(directory);
WebIO::m_hFile = FtpFindFirstFileA(WebIO::m_hConnect, "*", &findFileData, INTERNET_FLAG_RELOAD, NULL);
WebIO::m_hFile = FtpFindFirstFileA(WebIO::m_hConnect, "*", &findFileData, INTERNET_FLAG_RELOAD, NULL);
if (WebIO::m_hFile != INVALID_HANDLE_VALUE)
{ if (WebIO::m_hFile != INVALID_HANDLE_VALUE)
do {
{ do
//if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) continue; {
//if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) continue; //if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) continue;
//if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) continue;
if (findFileData.dwFileAttributes == dwAttribute) // No bitwise flag check, as it might return archives/offline/hidden or other files/dirs
{ if (findFileData.dwFileAttributes == dwAttribute) // No bitwise flag check, as it might return archives/offline/hidden or other files/dirs
//printf("%s: %X\n", findFileData.cFileName, findFileData.dwFileAttributes); {
list.push_back(findFileData.cFileName); //printf("%s: %X\n", findFileData.cFileName, findFileData.dwFileAttributes);
result = true; list.push_back(findFileData.cFileName);
} result = true;
} while (InternetFindNextFileA(WebIO::m_hFile, &findFileData)); }
} while (InternetFindNextFileA(WebIO::m_hFile, &findFileData));
InternetCloseHandle(WebIO::m_hFile);
} InternetCloseHandle(WebIO::m_hFile);
}
WebIO::SetDirectory(tempDir);
WebIO::SetDirectory(tempDir);
return result;
} return result;
}
bool WebIO::ListDirectories(std::string directory, std::vector<std::string> &list)
{ bool WebIO::ListDirectories(std::string directory, std::vector<std::string> &list)
return WebIO::ListElements(directory, list, false); {
} return WebIO::ListElements(directory, list, false);
}
bool WebIO::ListFiles(std::string directory, std::vector<std::string> &list)
{ bool WebIO::ListFiles(std::string directory, std::vector<std::string> &list)
return WebIO::ListElements(directory, list, true); {
} return WebIO::ListElements(directory, list, true);
}
bool WebIO::UploadFile(std::string file, std::string localfile)
{ bool WebIO::UploadFile(std::string file, std::string localfile)
return (FtpPutFileA(WebIO::m_hConnect, localfile.data(), file.data(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE); {
} return (FtpPutFileA(WebIO::m_hConnect, localfile.data(), file.data(), FTP_TRANSFER_TYPE_BINARY, NULL) == TRUE);
}
bool WebIO::DeleteFile(std::string file)
{ bool WebIO::DeleteFile(std::string file)
return (FtpDeleteFileA(WebIO::m_hConnect, file.data()) == TRUE); {
} return (FtpDeleteFileA(WebIO::m_hConnect, file.data()) == TRUE);
}
bool WebIO::RenameFile(std::string file, std::string newFile)
{ bool WebIO::RenameFile(std::string file, std::string newFile)
return (FtpRenameFileA(WebIO::m_hConnect, file.data(), newFile.data()) == TRUE); {
} return (FtpRenameFileA(WebIO::m_hConnect, file.data(), newFile.data()) == TRUE);
}
bool WebIO::DownloadFile(std::string file, std::string localfile)
{ bool WebIO::DownloadFile(std::string file, std::string localfile)
return (FtpGetFileA(WebIO::m_hConnect, file.data(), localfile.data(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE); {
} return (FtpGetFileA(WebIO::m_hConnect, file.data(), localfile.data(), FALSE, NULL, FTP_TRANSFER_TYPE_BINARY, 0) == TRUE);
}
bool WebIO::UploadFileData(std::string file, std::string data)
{ bool WebIO::UploadFileData(std::string file, std::string data)
bool result = false; {
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0); bool result = false;
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_WRITE, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
if (WebIO::m_hFile)
{ if (WebIO::m_hFile)
DWORD size = 0; {
if (InternetWriteFile(WebIO::m_hFile, data.data(), data.size(), &size) == TRUE) DWORD size = 0;
{ if (InternetWriteFile(WebIO::m_hFile, data.data(), data.size(), &size) == TRUE)
result = (size == data.size()); {
} result = (size == data.size());
}
InternetCloseHandle(WebIO::m_hFile);
} InternetCloseHandle(WebIO::m_hFile);
}
return result;
} return result;
}
bool WebIO::DownloadFileData(std::string file, std::string &data)
{ bool WebIO::DownloadFileData(std::string file, std::string &data)
data.clear(); {
data.clear();
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_READ, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
WebIO::m_hFile = FtpOpenFileA(WebIO::m_hConnect, file.data(), GENERIC_READ, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD, 0);
if (WebIO::m_hFile)
{ if (WebIO::m_hFile)
DWORD size = 0; {
char buffer[0x2001] = { 0 }; DWORD size = 0;
char buffer[0x2001] = { 0 };
while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
{ while (InternetReadFile(WebIO::m_hFile, buffer, 0x2000, &size))
data.append(buffer, size); {
if (!size) break; data.append(buffer, size);
} if (!size) break;
}
InternetCloseHandle(WebIO::m_hFile);
return true; InternetCloseHandle(WebIO::m_hFile);
} return true;
}
return false;
} return false;
} }
}