mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-22 08:31:07 +00:00
Reformat to clang-format
This commit is contained in:
+3
-2
@@ -8,10 +8,11 @@
|
|||||||
|
|
||||||
class HTTP {
|
class HTTP {
|
||||||
public:
|
public:
|
||||||
static bool Download(const std::string &IP, const std::string &Path);
|
static bool Download(const std::string& IP, const std::string& Path);
|
||||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
static std::string Get(const std::string &IP);
|
static std::string Get(const std::string& IP);
|
||||||
static bool ProgressBar(size_t c, size_t t);
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static bool isDownload;
|
static bool isDownload;
|
||||||
};
|
};
|
||||||
@@ -6,4 +6,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using Json = nlohmann::json;
|
using Json = nlohmann::json;
|
||||||
|
|
||||||
|
|||||||
+31
-28
@@ -5,11 +5,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Memory/IPC.h"
|
#include "Memory/IPC.h"
|
||||||
#include <filesystem>
|
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
|
#include <filesystem>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
struct VersionParser {
|
struct VersionParser {
|
||||||
@@ -21,10 +20,11 @@ struct VersionParser {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Launcher {
|
class Launcher {
|
||||||
public: //constructors
|
public: // constructors
|
||||||
Launcher(int argc, char* argv[]);
|
Launcher(int argc, char* argv[]);
|
||||||
~Launcher();
|
~Launcher();
|
||||||
public: //available functions
|
|
||||||
|
public: // available functions
|
||||||
static void StaticAbort(Launcher* Instance = nullptr);
|
static void StaticAbort(Launcher* Instance = nullptr);
|
||||||
std::string Login(const std::string& fields);
|
std::string Login(const std::string& fields);
|
||||||
void SendIPC(const std::string& Data, bool core = true);
|
void SendIPC(const std::string& Data, bool core = true);
|
||||||
@@ -35,7 +35,8 @@ public: //available functions
|
|||||||
void LaunchGame();
|
void LaunchGame();
|
||||||
void CheckKey();
|
void CheckKey();
|
||||||
void SetupMOD();
|
void SetupMOD();
|
||||||
public: //Getters and Setters
|
|
||||||
|
public: // Getters and Setters
|
||||||
void setDiscordMessage(const std::string& message);
|
void setDiscordMessage(const std::string& message);
|
||||||
static void setExit(bool exit) noexcept;
|
static void setExit(bool exit) noexcept;
|
||||||
const std::string& getFullVersion();
|
const std::string& getFullVersion();
|
||||||
@@ -46,7 +47,7 @@ public: //Getters and Setters
|
|||||||
const std::string& getVersion();
|
const std::string& getVersion();
|
||||||
static bool getExit() noexcept;
|
static bool getExit() noexcept;
|
||||||
|
|
||||||
private: //functions
|
private: // functions
|
||||||
void HandleIPC(const std::string& Data);
|
void HandleIPC(const std::string& Data);
|
||||||
std::string GetLocalAppdata();
|
std::string GetLocalAppdata();
|
||||||
void UpdatePresence();
|
void UpdatePresence();
|
||||||
@@ -59,32 +60,34 @@ private: //functions
|
|||||||
void Relaunch();
|
void Relaunch();
|
||||||
void ListenIPC();
|
void ListenIPC();
|
||||||
void Abort();
|
void Abort();
|
||||||
private: //variables
|
|
||||||
uint32_t GamePID{0};
|
private: // variables
|
||||||
|
uint32_t GamePID { 0 };
|
||||||
bool EnableUI = true;
|
bool EnableUI = true;
|
||||||
int64_t DiscordTime{};
|
int64_t DiscordTime {};
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
fs::path CurrentPath{};
|
fs::path CurrentPath {};
|
||||||
std::string BeamRoot{};
|
std::string BeamRoot {};
|
||||||
std::string UserRole{};
|
std::string UserRole {};
|
||||||
std::string PublicKey{};
|
std::string PublicKey {};
|
||||||
std::thread IPCSystem{};
|
std::thread IPCSystem {};
|
||||||
std::thread DiscordRPC{};
|
std::thread DiscordRPC {};
|
||||||
std::string MPUserPath{};
|
std::string MPUserPath {};
|
||||||
std::string BeamVersion{};
|
std::string BeamVersion {};
|
||||||
std::string BeamUserPath{};
|
std::string BeamUserPath {};
|
||||||
std::string DiscordMessage{};
|
std::string DiscordMessage {};
|
||||||
std::string Version{"2.0"};
|
std::string Version { "2.0" };
|
||||||
Server ServerHandler{this};
|
Server ServerHandler { this };
|
||||||
std::string TargetBuild{"default"};
|
std::string TargetBuild { "default" };
|
||||||
static inline std::atomic<bool> Shutdown{false}, Exit{false};
|
static inline std::atomic<bool> Shutdown { false }, Exit { false };
|
||||||
std::string FullVersion{Version + ".99"};
|
std::string FullVersion { Version + ".99" };
|
||||||
VersionParser SupportedVersion{"0.25.4.0"};
|
VersionParser SupportedVersion { "0.25.4.0" };
|
||||||
std::unique_ptr<IPC> IPCToGame{};
|
std::unique_ptr<IPC> IPCToGame {};
|
||||||
std::unique_ptr<IPC> IPCFromGame{};
|
std::unique_ptr<IPC> IPCFromGame {};
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShutdownException : public std::runtime_error {
|
class ShutdownException : public std::runtime_error {
|
||||||
public:
|
public:
|
||||||
explicit ShutdownException(const std::string& message): runtime_error(message){};
|
explicit ShutdownException(const std::string& message)
|
||||||
|
: runtime_error(message) {};
|
||||||
};
|
};
|
||||||
|
|||||||
+13
-11
@@ -4,10 +4,10 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <thread>
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
struct sockaddr_in;
|
struct sockaddr_in;
|
||||||
class Launcher;
|
class Launcher;
|
||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
Server() = delete;
|
Server() = delete;
|
||||||
explicit Server(Launcher* Instance);
|
explicit Server(Launcher* Instance);
|
||||||
~Server();
|
~Server();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void ServerSend(std::string Data, bool Rel);
|
void ServerSend(std::string Data, bool Rel);
|
||||||
void Connect(const std::string& Data);
|
void Connect(const std::string& Data);
|
||||||
@@ -27,11 +28,12 @@ public:
|
|||||||
bool Terminated();
|
bool Terminated();
|
||||||
int getPing() const;
|
int getPing() const;
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
std::chrono::time_point<std::chrono::high_resolution_clock> PingStart, PingEnd;
|
||||||
std::string MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name);
|
std::string MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name);
|
||||||
void AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name);
|
void AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name);
|
||||||
std::atomic<bool> Terminate{false}, ModLoaded{false};
|
std::atomic<bool> Terminate { false }, ModLoaded { false };
|
||||||
char* TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size);
|
char* TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size);
|
||||||
std::string GetAddress(const std::string& Data);
|
std::string GetAddress(const std::string& Data);
|
||||||
void InvalidResource(const std::string& File);
|
void InvalidResource(const std::string& File);
|
||||||
@@ -54,21 +56,21 @@ private:
|
|||||||
uint64_t TCPSocket = -1;
|
uint64_t TCPSocket = -1;
|
||||||
uint64_t UDPSocket = -1;
|
uint64_t UDPSocket = -1;
|
||||||
void WaitForConfirm();
|
void WaitForConfirm();
|
||||||
std::string UStatus{};
|
std::string UStatus {};
|
||||||
std::string MStatus{};
|
std::string MStatus {};
|
||||||
std::string ModList{};
|
std::string ModList {};
|
||||||
void TCPClientMain();
|
void TCPClientMain();
|
||||||
void SyncResources();
|
void SyncResources();
|
||||||
std::string TCPRcv();
|
std::string TCPRcv();
|
||||||
uint64_t InitDSock();
|
uint64_t InitDSock();
|
||||||
std::string Auth();
|
std::string Auth();
|
||||||
std::string IP{};
|
std::string IP {};
|
||||||
void UDPClient();
|
void UDPClient();
|
||||||
void PingLoop();
|
void PingLoop();
|
||||||
int ClientID{0};
|
int ClientID { 0 };
|
||||||
void UDPMain();
|
void UDPMain();
|
||||||
void UDPRcv();
|
void UDPRcv();
|
||||||
void Abort();
|
void Abort();
|
||||||
int Port{0};
|
int Port { 0 };
|
||||||
int Ping{0};
|
int Ping { 0 };
|
||||||
};
|
};
|
||||||
|
|||||||
+15
-10
@@ -1,17 +1,19 @@
|
|||||||
//
|
///
|
||||||
// Created by Anonymous275 on 24/07/22.
|
/// Created by Anonymous275 on 7/26/22
|
||||||
//
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
|
///
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <semaphore>
|
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
#include <semaphore>
|
||||||
|
|
||||||
template <class T, size_t Size>
|
template <class T, size_t Size>
|
||||||
class atomic_queue {
|
class atomic_queue {
|
||||||
public:
|
public:
|
||||||
bool try_pop(T& val) {
|
bool try_pop(T& val) {
|
||||||
lock_guard guard(semaphore);
|
lock_guard guard(semaphore);
|
||||||
if(queue.empty())return false;
|
if (queue.empty())
|
||||||
|
return false;
|
||||||
val = queue.front();
|
val = queue.front();
|
||||||
queue.pop();
|
queue.pop();
|
||||||
full.release();
|
full.release();
|
||||||
@@ -33,24 +35,27 @@ public:
|
|||||||
lock_guard guard(semaphore);
|
lock_guard guard(semaphore);
|
||||||
return queue.empty();
|
return queue.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void check_full() {
|
void check_full() {
|
||||||
if(size() >= Size) {
|
if (size() >= Size) {
|
||||||
full.acquire();
|
full.acquire();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct lock_guard {
|
struct lock_guard {
|
||||||
explicit lock_guard(std::binary_semaphore& lock) : lock(lock){
|
explicit lock_guard(std::binary_semaphore& lock)
|
||||||
|
: lock(lock) {
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
}
|
}
|
||||||
~lock_guard() {
|
~lock_guard() {
|
||||||
lock.release();
|
lock.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::binary_semaphore& lock;
|
std::binary_semaphore& lock;
|
||||||
};
|
};
|
||||||
std::binary_semaphore semaphore{1}, full{0};
|
std::binary_semaphore semaphore { 1 }, full { 0 };
|
||||||
std::queue<T> queue{};
|
std::queue<T> queue {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+13
-11
@@ -3,35 +3,37 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#include <tomlplusplus/toml.hpp>
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include <tomlplusplus/toml.hpp>
|
||||||
|
|
||||||
void Launcher::LoadConfig() {
|
void Launcher::LoadConfig() {
|
||||||
if(fs::exists("Launcher.toml")) {
|
if (fs::exists("Launcher.toml")) {
|
||||||
toml::parse_result config = toml::parse_file("Launcher.toml");
|
toml::parse_result config = toml::parse_file("Launcher.toml");
|
||||||
auto ui = config["UI"];
|
auto ui = config["UI"];
|
||||||
auto build = config["Build"];
|
auto build = config["Build"];
|
||||||
if(ui.is_boolean()) {
|
if (ui.is_boolean()) {
|
||||||
EnableUI = ui.as_boolean()->get();
|
EnableUI = ui.as_boolean()->get();
|
||||||
} else LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
} else
|
||||||
|
LOG(ERROR) << "Failed to get 'UI' boolean from config";
|
||||||
|
|
||||||
//Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
|
// Default -1 / Release 1 / EA 2 / Dev 3 / Custom 3
|
||||||
if(build.is_string()) {
|
if (build.is_string()) {
|
||||||
TargetBuild = build.as_string()->get();
|
TargetBuild = build.as_string()->get();
|
||||||
for(char& c : TargetBuild)c = char(tolower(c));
|
for (char& c : TargetBuild)
|
||||||
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
c = char(tolower(c));
|
||||||
|
} else
|
||||||
|
LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
std::ofstream tml("Launcher.toml");
|
std::ofstream tml("Launcher.toml");
|
||||||
if(tml.is_open()){
|
if (tml.is_open()) {
|
||||||
tml <<
|
tml <<
|
||||||
R"(UI = true
|
R"(UI = true
|
||||||
Build = "Default"
|
Build = "Default"
|
||||||
)";
|
)";
|
||||||
tml.close();
|
tml.close();
|
||||||
}else{
|
} else {
|
||||||
LOG(FATAL) << "Failed to write config on disk!";
|
LOG(FATAL) << "Failed to write config on disk!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -3,14 +3,13 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
#include <discord_rpc.h>
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <discord_rpc.h>
|
||||||
|
|
||||||
|
void handleReady(const DiscordUser* u) { }
|
||||||
void handleReady(const DiscordUser* u) {}
|
void handleDisconnected(int errcode, const char* message) { }
|
||||||
void handleDisconnected(int errcode, const char* message) {}
|
|
||||||
void handleError(int errcode, const char* message) {
|
void handleError(int errcode, const char* message) {
|
||||||
LOG(ERROR) << "Discord error: " << message;
|
LOG(ERROR) << "Discord error: " << message;
|
||||||
}
|
}
|
||||||
@@ -40,7 +39,7 @@ void Launcher::RichPresence() {
|
|||||||
handlers.disconnected = handleDisconnected;
|
handlers.disconnected = handleDisconnected;
|
||||||
Discord_Initialize("629743237988352010", &handlers, 1, nullptr);
|
Discord_Initialize("629743237988352010", &handlers, 1, nullptr);
|
||||||
UpdatePresence();
|
UpdatePresence();
|
||||||
while(!Shutdown.load()) {
|
while (!Shutdown.load()) {
|
||||||
Discord_RunCallbacks();
|
Discord_RunCallbacks();
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
|
|||||||
+77
-70
@@ -3,88 +3,95 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#include "Memory/Memory.h"
|
|
||||||
#include "Memory/BeamNG.h"
|
|
||||||
#include "Launcher.h"
|
|
||||||
#include "HttpAPI.h"
|
#include "HttpAPI.h"
|
||||||
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Memory/BeamNG.h"
|
||||||
|
#include "Memory/Memory.h"
|
||||||
|
|
||||||
void Launcher::HandleIPC(const std::string& Data) {
|
void Launcher::HandleIPC(const std::string& Data) {
|
||||||
char Code = Data.at(0), SubCode = 0;
|
char Code = Data.at(0), SubCode = 0;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
if (Data.length() > 1)
|
||||||
|
SubCode = Data.at(1);
|
||||||
switch (Code) {
|
switch (Code) {
|
||||||
case 'A':
|
case 'A':
|
||||||
ServerHandler.StartUDP();
|
ServerHandler.StartUDP();
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
|
ServerHandler.Close();
|
||||||
|
SendIPC(Code + HTTP::Post("https://backend.beammp.com/servers", ""));
|
||||||
|
LOG(INFO) << "Sent Server List";
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
ServerHandler.Close();
|
||||||
|
ServerHandler.Connect(Data);
|
||||||
|
while (ServerHandler.getModList().empty() && !ServerHandler.Terminated()) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
|
}
|
||||||
|
if (ServerHandler.getModList() == "-")
|
||||||
|
SendIPC("L");
|
||||||
|
else
|
||||||
|
SendIPC("L" + ServerHandler.getModList());
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
SendIPC("Ul" + ServerHandler.getUIStatus());
|
||||||
|
if (ServerHandler.getPing() > 800) {
|
||||||
|
SendIPC("Up-2");
|
||||||
|
} else
|
||||||
|
SendIPC("Up" + std::to_string(ServerHandler.getPing()));
|
||||||
|
break;
|
||||||
|
case 'M':
|
||||||
|
SendIPC(ServerHandler.getMap());
|
||||||
|
break;
|
||||||
|
case 'Q':
|
||||||
|
if (SubCode == 'S') {
|
||||||
ServerHandler.Close();
|
ServerHandler.Close();
|
||||||
SendIPC(Code + HTTP::Post("https://backend.beammp.com/servers",""));
|
}
|
||||||
LOG(INFO) << "Sent Server List";
|
if (SubCode == 'G')
|
||||||
break;
|
exit(2);
|
||||||
case 'C':
|
break;
|
||||||
ServerHandler.Close();
|
case 'R': // will send mod name
|
||||||
ServerHandler.Connect(Data);
|
ServerHandler.setModLoaded();
|
||||||
while(ServerHandler.getModList().empty() && !ServerHandler.Terminated()){
|
break;
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
case 'Z':
|
||||||
}
|
SendIPC("Z" + Version);
|
||||||
if(ServerHandler.getModList() == "-")SendIPC("L");
|
break;
|
||||||
else SendIPC("L"+ServerHandler.getModList());
|
case 'N':
|
||||||
break;
|
if (SubCode == 'c') {
|
||||||
case 'U':
|
SendIPC("N{\"Auth\":" + std::to_string(LoginAuth) + "}");
|
||||||
SendIPC("Ul" + ServerHandler.getUIStatus());
|
} else {
|
||||||
if(ServerHandler.getPing() > 800) {
|
SendIPC("N" + Login(Data.substr(Data.find(':') + 1)));
|
||||||
SendIPC("Up-2");
|
}
|
||||||
}else SendIPC("Up" + std::to_string(ServerHandler.getPing()));
|
break;
|
||||||
break;
|
default:
|
||||||
case 'M':
|
break;
|
||||||
SendIPC(ServerHandler.getMap());
|
|
||||||
break;
|
|
||||||
case 'Q':
|
|
||||||
if(SubCode == 'S') {
|
|
||||||
ServerHandler.Close();
|
|
||||||
}
|
|
||||||
if(SubCode == 'G')exit(2);
|
|
||||||
break;
|
|
||||||
case 'R': //will send mod name
|
|
||||||
ServerHandler.setModLoaded();
|
|
||||||
break;
|
|
||||||
case 'Z':
|
|
||||||
SendIPC("Z" + Version);
|
|
||||||
break;
|
|
||||||
case 'N':
|
|
||||||
if(SubCode == 'c') {
|
|
||||||
SendIPC("N{\"Auth\":"+std::to_string(LoginAuth)+"}");
|
|
||||||
} else {
|
|
||||||
SendIPC("N" + Login(Data.substr(Data.find(':') + 1)));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::ServerParser(const std::string& Data) {
|
void Server::ServerParser(const std::string& Data) {
|
||||||
if(Data.empty())return;
|
if (Data.empty())
|
||||||
char Code = Data.at(0),SubCode = 0;
|
return;
|
||||||
if(Data.length() > 1)SubCode = Data.at(1);
|
char Code = Data.at(0), SubCode = 0;
|
||||||
|
if (Data.length() > 1)
|
||||||
|
SubCode = Data.at(1);
|
||||||
switch (Code) {
|
switch (Code) {
|
||||||
case 'p':
|
case 'p':
|
||||||
PingEnd = std::chrono::high_resolution_clock::now();
|
PingEnd = std::chrono::high_resolution_clock::now();
|
||||||
if(PingStart > PingEnd)Ping = 0;
|
if (PingStart > PingEnd)
|
||||||
else Ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd-PingStart).count());
|
Ping = 0;
|
||||||
return;
|
else
|
||||||
case 'M':
|
Ping = int(std::chrono::duration_cast<std::chrono::milliseconds>(PingEnd - PingStart).count());
|
||||||
MStatus = Data;
|
return;
|
||||||
UStatus = "done";
|
case 'M':
|
||||||
return;
|
MStatus = Data;
|
||||||
case 'K':
|
UStatus = "done";
|
||||||
Terminate = true;
|
return;
|
||||||
UStatus = Data.substr(1);
|
case 'K':
|
||||||
return;
|
Terminate = true;
|
||||||
default:
|
UStatus = Data.substr(1);
|
||||||
break;
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
LauncherInstance->SendIPC(Data, false);
|
LauncherInstance->SendIPC(Data, false);
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-44
@@ -4,23 +4,25 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include "Memory/Memory.h"
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
|
||||||
#include <csignal>
|
|
||||||
#include "HttpAPI.h"
|
#include "HttpAPI.h"
|
||||||
#include <windows.h>
|
#include "Logger.h"
|
||||||
#include <shellapi.h>
|
#include "Memory/Memory.h"
|
||||||
#include <ShlObj.h>
|
#include <ShlObj.h>
|
||||||
#include <comutil.h>
|
#include <comutil.h>
|
||||||
|
#include <csignal>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <shellapi.h>
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
|
LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
|
||||||
LOG(ERROR) << "CAUGHT EXCEPTION! Code 0x" << std::hex << std::uppercase << p->ExceptionRecord->ExceptionCode;
|
LOG(ERROR) << "CAUGHT EXCEPTION! Code 0x" << std::hex << std::uppercase << p->ExceptionRecord->ExceptionCode;
|
||||||
return EXCEPTION_EXECUTE_HANDLER;
|
return EXCEPTION_EXECUTE_HANDLER;
|
||||||
}
|
}
|
||||||
|
|
||||||
Launcher::Launcher(int argc, char* argv[]) : CurrentPath(std::filesystem::path(argv[0])), DiscordMessage("Just launched") {
|
Launcher::Launcher(int argc, char* argv[])
|
||||||
|
: CurrentPath(std::filesystem::path(argv[0]))
|
||||||
|
, DiscordMessage("Just launched") {
|
||||||
Launcher::StaticAbort(this);
|
Launcher::StaticAbort(this);
|
||||||
DiscordTime = std::time(nullptr);
|
DiscordTime = std::time(nullptr);
|
||||||
Log::Init();
|
Log::Init();
|
||||||
@@ -33,16 +35,16 @@ Launcher::Launcher(int argc, char* argv[]) : CurrentPath(std::filesystem::path(a
|
|||||||
void Launcher::Abort() {
|
void Launcher::Abort() {
|
||||||
Shutdown.store(true);
|
Shutdown.store(true);
|
||||||
ServerHandler.Close();
|
ServerHandler.Close();
|
||||||
if(DiscordRPC.joinable()) {
|
if (DiscordRPC.joinable()) {
|
||||||
DiscordRPC.join();
|
DiscordRPC.join();
|
||||||
}
|
}
|
||||||
if(IPCSystem.joinable()) {
|
if (IPCSystem.joinable()) {
|
||||||
IPCSystem.join();
|
IPCSystem.join();
|
||||||
}
|
}
|
||||||
if(!MPUserPath.empty()) {
|
if (!MPUserPath.empty()) {
|
||||||
ResetMods();
|
ResetMods();
|
||||||
}
|
}
|
||||||
if(GamePID != 0) {
|
if (GamePID != 0) {
|
||||||
auto Handle = OpenProcess(PROCESS_TERMINATE, false, DWORD(GamePID));
|
auto Handle = OpenProcess(PROCESS_TERMINATE, false, DWORD(GamePID));
|
||||||
TerminateProcess(Handle, 0);
|
TerminateProcess(Handle, 0);
|
||||||
CloseHandle(Handle);
|
CloseHandle(Handle);
|
||||||
@@ -50,25 +52,25 @@ void Launcher::Abort() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Launcher::~Launcher() {
|
Launcher::~Launcher() {
|
||||||
if(!Shutdown.load()) {
|
if (!Shutdown.load()) {
|
||||||
Abort();
|
Abort();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShutdownHandler(int sig) {
|
void ShutdownHandler(int sig) {
|
||||||
Launcher::StaticAbort();
|
Launcher::StaticAbort();
|
||||||
while(HTTP::isDownload) {
|
while (HTTP::isDownload) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Got termination signal (" << sig << ")";
|
LOG(INFO) << "Got termination signal (" << sig << ")";
|
||||||
while(!Launcher::getExit()) {
|
while (!Launcher::getExit()) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::StaticAbort(Launcher* Instance) {
|
void Launcher::StaticAbort(Launcher* Instance) {
|
||||||
static Launcher* Address;
|
static Launcher* Address;
|
||||||
if(Instance) {
|
if (Instance) {
|
||||||
Address = Instance;
|
Address = Instance;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -86,21 +88,21 @@ void Launcher::WindowsInit() {
|
|||||||
|
|
||||||
void Launcher::LaunchGame() {
|
void Launcher::LaunchGame() {
|
||||||
VersionParser GameVersion(BeamVersion);
|
VersionParser GameVersion(BeamVersion);
|
||||||
if(GameVersion.data[1] > SupportedVersion.data[1]) {
|
if (GameVersion.data[1] > SupportedVersion.data[1]) {
|
||||||
LOG(FATAL) << "BeamNG V" << BeamVersion << " not yet supported, please wait until we update BeamMP!";
|
LOG(FATAL) << "BeamNG V" << BeamVersion << " not yet supported, please wait until we update BeamMP!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
} else if(GameVersion.data[1] < SupportedVersion.data[1]) {
|
} else if (GameVersion.data[1] < SupportedVersion.data[1]) {
|
||||||
LOG(FATAL) << "BeamNG V" << BeamVersion << " not supported, please update and launch the new update!";
|
LOG(FATAL) << "BeamNG V" << BeamVersion << " not supported, please update and launch the new update!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
} else if(GameVersion > SupportedVersion) {
|
} else if (GameVersion > SupportedVersion) {
|
||||||
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly newer than recommended, this might cause issues!";
|
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly newer than recommended, this might cause issues!";
|
||||||
} else if(GameVersion < SupportedVersion) {
|
} else if (GameVersion < SupportedVersion) {
|
||||||
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly older than recommended, this might cause issues!";
|
LOG(WARNING) << "BeamNG V" << BeamVersion << " is slightly older than recommended, this might cause issues!";
|
||||||
}
|
}
|
||||||
if(Memory::GetBeamNGPID({}) == 0) {
|
if (Memory::GetBeamNGPID({}) == 0) {
|
||||||
LOG(INFO) << "Launching BeamNG from steam";
|
LOG(INFO) << "Launching BeamNG from steam";
|
||||||
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
ShellExecuteA(nullptr, nullptr, "steam://rungameid/284160", nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
//ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
// ShowWindow(GetConsoleWindow(), HIDE_WINDOW);
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Waiting for a game process, please start BeamNG manually in case of steam issues";
|
LOG(INFO) << "Waiting for a game process, please start BeamNG manually in case of steam issues";
|
||||||
}
|
}
|
||||||
@@ -109,16 +111,17 @@ void Launcher::WaitForGame() {
|
|||||||
std::set<uint32_t> BlackList;
|
std::set<uint32_t> BlackList;
|
||||||
do {
|
do {
|
||||||
auto PID = Memory::GetBeamNGPID(BlackList);
|
auto PID = Memory::GetBeamNGPID(BlackList);
|
||||||
if(PID != 0 && IPC::mem_used(PID)) {
|
if (PID != 0 && IPC::mem_used(PID)) {
|
||||||
BlackList.emplace(PID);
|
BlackList.emplace(PID);
|
||||||
} else {
|
} else {
|
||||||
GamePID = PID;
|
GamePID = PID;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
} while(GamePID == 0 && !Shutdown.load());
|
} while (GamePID == 0 && !Shutdown.load());
|
||||||
if(Shutdown.load())return;
|
if (Shutdown.load())
|
||||||
|
return;
|
||||||
|
|
||||||
if(GamePID == 0) {
|
if (GamePID == 0) {
|
||||||
LOG(FATAL) << "Game process not found! aborting";
|
LOG(FATAL) << "Game process not found! aborting";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
}
|
}
|
||||||
@@ -126,12 +129,12 @@ void Launcher::WaitForGame() {
|
|||||||
LOG(INFO) << "Game found! PID " << GamePID;
|
LOG(INFO) << "Game found! PID " << GamePID;
|
||||||
|
|
||||||
IPCToGame = std::make_unique<IPC>(GamePID, 0x1900000);
|
IPCToGame = std::make_unique<IPC>(GamePID, 0x1900000);
|
||||||
IPCFromGame = std::make_unique<IPC>(GamePID+1, 0x1900000);
|
IPCFromGame = std::make_unique<IPC>(GamePID + 1, 0x1900000);
|
||||||
|
|
||||||
IPCSystem = std::thread(&Launcher::ListenIPC, this);
|
IPCSystem = std::thread(&Launcher::ListenIPC, this);
|
||||||
Memory::Inject(GamePID);
|
Memory::Inject(GamePID);
|
||||||
setDiscordMessage("In menus");
|
setDiscordMessage("In menus");
|
||||||
while(!Shutdown.load() && Memory::GetBeamNGPID(BlackList) != 0) {
|
while (!Shutdown.load() && Memory::GetBeamNGPID(BlackList) != 0) {
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Game process was lost";
|
LOG(INFO) << "Game process was lost";
|
||||||
@@ -139,11 +142,11 @@ void Launcher::WaitForGame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::ListenIPC() {
|
void Launcher::ListenIPC() {
|
||||||
while(!Shutdown.load()) {
|
while (!Shutdown.load()) {
|
||||||
IPCFromGame->receive();
|
IPCFromGame->receive();
|
||||||
if(!IPCFromGame->receive_timed_out()) {
|
if (!IPCFromGame->receive_timed_out()) {
|
||||||
auto& MSG = IPCFromGame->msg();
|
auto& MSG = IPCFromGame->msg();
|
||||||
if(MSG[0] == 'C') {
|
if (MSG[0] == 'C') {
|
||||||
HandleIPC(IPCFromGame->msg().substr(1));
|
HandleIPC(IPCFromGame->msg().substr(1));
|
||||||
} else {
|
} else {
|
||||||
ServerHandler.ServerSend(IPCFromGame->msg().substr(1), false);
|
ServerHandler.ServerSend(IPCFromGame->msg().substr(1), false);
|
||||||
@@ -153,12 +156,14 @@ void Launcher::ListenIPC() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::SendIPC(const std::string& Data, bool core) {
|
void Launcher::SendIPC(const std::string& Data, bool core) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
if(core)IPCToGame->send("C" + Data);
|
if (core)
|
||||||
else IPCToGame->send("G" + Data);
|
IPCToGame->send("C" + Data);
|
||||||
if(IPCToGame->send_timed_out()) {
|
else
|
||||||
|
IPCToGame->send("G" + Data);
|
||||||
|
if (IPCToGame->send_timed_out()) {
|
||||||
LOG(WARNING) << "Timed out while sending \"" << Data << "\"";
|
LOG(WARNING) << "Timed out while sending \"" << Data << "\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -166,8 +171,8 @@ void Launcher::SendIPC(const std::string& Data, bool core) {
|
|||||||
std::string QueryValue(HKEY& hKey, const char* Name) {
|
std::string QueryValue(HKEY& hKey, const char* Name) {
|
||||||
DWORD keySize;
|
DWORD keySize;
|
||||||
BYTE buffer[16384];
|
BYTE buffer[16384];
|
||||||
if(RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
|
if (RegQueryValueExA(hKey, Name, nullptr, nullptr, buffer, &keySize) == ERROR_SUCCESS) {
|
||||||
return {(char*)buffer, keySize-1};
|
return { (char*)buffer, keySize - 1 };
|
||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
@@ -185,7 +190,7 @@ std::string Launcher::GetLocalAppdata() {
|
|||||||
std::string Path((char*)bstrPath);
|
std::string Path((char*)bstrPath);
|
||||||
CoTaskMemFree(folderPath);
|
CoTaskMemFree(folderPath);
|
||||||
|
|
||||||
if(!Path.empty()) {
|
if (!Path.empty()) {
|
||||||
Path += "\\BeamNG.drive\\";
|
Path += "\\BeamNG.drive\\";
|
||||||
VersionParser GameVer(BeamVersion);
|
VersionParser GameVer(BeamVersion);
|
||||||
Path += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
|
Path += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
|
||||||
@@ -196,21 +201,22 @@ std::string Launcher::GetLocalAppdata() {
|
|||||||
void Launcher::QueryRegistry() {
|
void Launcher::QueryRegistry() {
|
||||||
HKEY BeamNG;
|
HKEY BeamNG;
|
||||||
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0, KEY_READ, &BeamNG);
|
LONG RegRes = RegOpenKeyExA(HKEY_CURRENT_USER, R"(Software\BeamNG\BeamNG.drive)", 0, KEY_READ, &BeamNG);
|
||||||
if(RegRes == ERROR_SUCCESS) {
|
if (RegRes == ERROR_SUCCESS) {
|
||||||
BeamRoot = QueryValue(BeamNG, "rootpath");
|
BeamRoot = QueryValue(BeamNG, "rootpath");
|
||||||
BeamVersion = QueryValue(BeamNG, "version");
|
BeamVersion = QueryValue(BeamNG, "version");
|
||||||
BeamUserPath = QueryValue(BeamNG, "userpath_override");
|
BeamUserPath = QueryValue(BeamNG, "userpath_override");
|
||||||
RegCloseKey(BeamNG);
|
RegCloseKey(BeamNG);
|
||||||
if(BeamUserPath.empty() && !BeamVersion.empty()) {
|
if (BeamUserPath.empty() && !BeamVersion.empty()) {
|
||||||
BeamUserPath = GetLocalAppdata();
|
BeamUserPath = GetLocalAppdata();
|
||||||
} else if(!BeamUserPath.empty() && !BeamVersion.empty()) {
|
} else if (!BeamUserPath.empty() && !BeamVersion.empty()) {
|
||||||
VersionParser GameVer(BeamVersion);
|
VersionParser GameVer(BeamVersion);
|
||||||
BeamUserPath += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
|
BeamUserPath += GameVer.split[0] + '.' + GameVer.split[1] + '\\';
|
||||||
}
|
}
|
||||||
if(!BeamUserPath.empty()) {
|
if (!BeamUserPath.empty()) {
|
||||||
MPUserPath = BeamUserPath + "mods\\multiplayer";
|
MPUserPath = BeamUserPath + "mods\\multiplayer";
|
||||||
}
|
}
|
||||||
if(!BeamRoot.empty() && !BeamVersion.empty() && !BeamUserPath.empty())return;
|
if (!BeamRoot.empty() && !BeamVersion.empty() && !BeamUserPath.empty())
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
LOG(FATAL) << "Please launch the game at least once, failed to read registry key Software\\BeamNG\\BeamNG.drive";
|
LOG(FATAL) << "Please launch the game at least once, failed to read registry key Software\\BeamNG\\BeamNG.drive";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
@@ -219,13 +225,13 @@ void Launcher::QueryRegistry() {
|
|||||||
void Launcher::AdminRelaunch() {
|
void Launcher::AdminRelaunch() {
|
||||||
system("cls");
|
system("cls");
|
||||||
ShellExecuteA(nullptr, "runas", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
ShellExecuteA(nullptr, "runas", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
throw ShutdownException("Relaunching");
|
throw ShutdownException("Relaunching");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::Relaunch() {
|
void Launcher::Relaunch() {
|
||||||
ShellExecuteA(nullptr, "open", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
ShellExecuteA(nullptr, "open", CurrentPath.string().c_str(), nullptr, nullptr, SW_SHOWNORMAL);
|
||||||
ShowWindow(GetConsoleWindow(),0);
|
ShowWindow(GetConsoleWindow(), 0);
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||||
throw ShutdownException("Relaunching");
|
throw ShutdownException("Relaunching");
|
||||||
}
|
}
|
||||||
@@ -258,6 +264,6 @@ const std::string& Launcher::getMPUserPath() {
|
|||||||
return MPUserPath;
|
return MPUserPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Launcher::getPublicKey() {
|
const std::string& Launcher::getPublicKey() {
|
||||||
return PublicKey;
|
return PublicKey;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -12,10 +12,10 @@ void Log::Init() {
|
|||||||
std::string DFormat("%datetime{[%d/%M/%y %H:%m:%s]} %fbase:%line [%level] %msg");
|
std::string DFormat("%datetime{[%d/%M/%y %H:%m:%s]} %fbase:%line [%level] %msg");
|
||||||
Conf.setGlobally(ConfigurationType::Format, "%datetime{[%d/%M/%y %H:%m:%s]} [%level] %msg");
|
Conf.setGlobally(ConfigurationType::Format, "%datetime{[%d/%M/%y %H:%m:%s]} [%level] %msg");
|
||||||
Conf.setGlobally(ConfigurationType::LogFlushThreshold, "2");
|
Conf.setGlobally(ConfigurationType::LogFlushThreshold, "2");
|
||||||
Conf.set(Level::Verbose,ConfigurationType::Format, DFormat);
|
Conf.set(Level::Verbose, ConfigurationType::Format, DFormat);
|
||||||
Conf.set(Level::Debug,ConfigurationType::Format, DFormat);
|
Conf.set(Level::Debug, ConfigurationType::Format, DFormat);
|
||||||
Conf.set(Level::Trace,ConfigurationType::Format, DFormat);
|
Conf.set(Level::Trace, ConfigurationType::Format, DFormat);
|
||||||
Conf.set(Level::Fatal,ConfigurationType::Format, DFormat);
|
Conf.set(Level::Fatal, ConfigurationType::Format, DFormat);
|
||||||
Conf.setGlobally(ConfigurationType::Filename, "Launcher.log");
|
Conf.setGlobally(ConfigurationType::Filename, "Launcher.log");
|
||||||
Conf.setGlobally(ConfigurationType::MaxLogFileSize, "7340032");
|
Conf.setGlobally(ConfigurationType::MaxLogFileSize, "7340032");
|
||||||
Loggers::reconfigureAllLoggers(Conf);
|
Loggers::reconfigureAllLoggers(Conf);
|
||||||
|
|||||||
+11
-10
@@ -3,10 +3,9 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#include "atomic_queue.h"
|
|
||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
|
#include "atomic_queue.h"
|
||||||
|
|
||||||
std::unique_ptr<atomic_queue<std::string, 1000>> Queue;
|
std::unique_ptr<atomic_queue<std::string, 1000>> Queue;
|
||||||
|
|
||||||
@@ -21,7 +20,8 @@ void BeamNG::EntryPoint() {
|
|||||||
Queue = std::make_unique<atomic_queue<std::string, 1000>>();
|
Queue = std::make_unique<atomic_queue<std::string, 1000>>();
|
||||||
uint32_t PID = Memory::GetPID();
|
uint32_t PID = Memory::GetPID();
|
||||||
auto status = MH_Initialize();
|
auto status = MH_Initialize();
|
||||||
if(status != MH_OK)Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
if (status != MH_OK)
|
||||||
|
Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
|
||||||
Memory::Print("PID : " + std::to_string(PID));
|
Memory::Print("PID : " + std::to_string(PID));
|
||||||
GELua::FindAddresses();
|
GELua::FindAddresses();
|
||||||
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
|
||||||
@@ -29,15 +29,15 @@ void BeamNG::EntryPoint() {
|
|||||||
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(GELua::lua_open_jit, lua_open_jit_D);
|
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(GELua::lua_open_jit, lua_open_jit_D);
|
||||||
OpenJITDetour->Enable();
|
OpenJITDetour->Enable();
|
||||||
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
|
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
|
||||||
IPCToLauncher = std::make_unique<IPC>(PID+1, 0x1900000);
|
IPCToLauncher = std::make_unique<IPC>(PID + 1, 0x1900000);
|
||||||
IPCListener();
|
IPCListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
int Core(lua_State* L) {
|
int Core(lua_State* L) {
|
||||||
if(lua_gettop(L) == 1) {
|
if (lua_gettop(L) == 1) {
|
||||||
size_t Size;
|
size_t Size;
|
||||||
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
||||||
//Memory::Print("Core -> " + std::string(Data) + " - " + std::to_string(Size));
|
// Memory::Print("Core -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||||
std::string msg(Data, Size);
|
std::string msg(Data, Size);
|
||||||
BeamNG::SendIPC("C" + msg);
|
BeamNG::SendIPC("C" + msg);
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ int Core(lua_State* L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Game(lua_State* L) {
|
int Game(lua_State* L) {
|
||||||
if(lua_gettop(L) == 1) {
|
if (lua_gettop(L) == 1) {
|
||||||
size_t Size;
|
size_t Size;
|
||||||
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
const char* Data = GELua::lua_tolstring(L, 1, &Size);
|
||||||
//Memory::Print("Game -> " + std::string(Data) + " - " + std::to_string(Size));
|
// Memory::Print("Game -> " + std::string(Data) + " - " + std::to_string(Size));
|
||||||
std::string msg(Data, Size);
|
std::string msg(Data, Size);
|
||||||
BeamNG::SendIPC("G" + msg);
|
BeamNG::SendIPC("G" + msg);
|
||||||
}
|
}
|
||||||
@@ -80,13 +80,14 @@ void BeamNG::SendIPC(const std::string& Data) {
|
|||||||
|
|
||||||
void BeamNG::IPCListener() {
|
void BeamNG::IPCListener() {
|
||||||
int TimeOuts = 0;
|
int TimeOuts = 0;
|
||||||
while(TimeOuts < 20) {
|
while (TimeOuts < 20) {
|
||||||
IPCFromLauncher->receive();
|
IPCFromLauncher->receive();
|
||||||
if (!IPCFromLauncher->receive_timed_out()) {
|
if (!IPCFromLauncher->receive_timed_out()) {
|
||||||
TimeOuts = 0;
|
TimeOuts = 0;
|
||||||
Queue->push(IPCFromLauncher->msg());
|
Queue->push(IPCFromLauncher->msg());
|
||||||
IPCFromLauncher->confirm_receive();
|
IPCFromLauncher->confirm_receive();
|
||||||
} else TimeOuts++;
|
} else
|
||||||
|
TimeOuts++;
|
||||||
}
|
}
|
||||||
Memory::Print("IPC System shutting down");
|
Memory::Print("IPC System shutting down");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#include "Memory/Definitions.h"
|
#include "Memory/Definitions.h"
|
||||||
#include "lua/lj_strscan.h"
|
|
||||||
#include "lua/lj_arch.h"
|
#include "lua/lj_arch.h"
|
||||||
#include "lua/lj_obj.h"
|
#include "lua/lj_bc.h"
|
||||||
#include "lua/lj_def.h"
|
#include "lua/lj_def.h"
|
||||||
#include "lua/lj_gc.h"
|
#include "lua/lj_gc.h"
|
||||||
#include "lua/lj_bc.h"
|
#include "lua/lj_obj.h"
|
||||||
|
#include "lua/lj_strscan.h"
|
||||||
|
|
||||||
LUA_API int lua_gettop(lua_State *L) {
|
LUA_API int lua_gettop(lua_State* L) {
|
||||||
return (int)(L->top - L->base);
|
return (int)(L->top - L->base);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Memory/Patterns.h"
|
|
||||||
#include "Memory/Memory.h"
|
|
||||||
#include "Memory/GELua.h"
|
#include "Memory/GELua.h"
|
||||||
|
#include "Memory/Memory.h"
|
||||||
|
#include "Memory/Patterns.h"
|
||||||
|
|
||||||
const char* GameModule = "BeamNG.drive.x64.exe";
|
const char* GameModule = "BeamNG.drive.x64.exe";
|
||||||
const char* DllModule = "libbeamng.x64.dll";
|
const char* DllModule = "libbeamng.x64.dll";
|
||||||
@@ -13,7 +13,7 @@ const char* DllModule = "libbeamng.x64.dll";
|
|||||||
std::string GetHex(uint64_t num) {
|
std::string GetHex(uint64_t num) {
|
||||||
char buffer[30];
|
char buffer[30];
|
||||||
sprintf(buffer, "%llx", num);
|
sprintf(buffer, "%llx", num);
|
||||||
return std::string{buffer};
|
return std::string { buffer };
|
||||||
}
|
}
|
||||||
|
|
||||||
void GELua::FindAddresses() {
|
void GELua::FindAddresses() {
|
||||||
|
|||||||
+10
-11
@@ -4,24 +4,25 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
|
||||||
#include "Memory/IPC.h"
|
#include "Memory/IPC.h"
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
IPC::IPC(uint32_t ID, size_t Size) noexcept : Size_(Size) {
|
IPC::IPC(uint32_t ID, size_t Size) noexcept
|
||||||
std::string Sem{"MP_S" + std::to_string(ID)},
|
: Size_(Size) {
|
||||||
SemConf{"MP_SC" + std::to_string(ID)},
|
std::string Sem { "MP_S" + std::to_string(ID) },
|
||||||
Mem{"MP_IO" + std::to_string(ID)};
|
SemConf { "MP_SC" + std::to_string(ID) },
|
||||||
|
Mem { "MP_IO" + std::to_string(ID) };
|
||||||
|
|
||||||
SemHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, Sem.c_str());
|
SemHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, Sem.c_str());
|
||||||
if(SemHandle_ == nullptr) {
|
if (SemHandle_ == nullptr) {
|
||||||
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, Sem.c_str());
|
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, Sem.c_str());
|
||||||
}
|
}
|
||||||
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemConf.c_str());
|
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemConf.c_str());
|
||||||
if(SemConfHandle_ == nullptr) {
|
if (SemConfHandle_ == nullptr) {
|
||||||
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemConf.c_str());
|
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemConf.c_str());
|
||||||
}
|
}
|
||||||
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
||||||
if(MemoryHandle_ == nullptr) {
|
if (MemoryHandle_ == nullptr) {
|
||||||
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), Mem.c_str());
|
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), Mem.c_str());
|
||||||
}
|
}
|
||||||
Data_ = (char*)MapViewOfFile(MemoryHandle_, FILE_MAP_ALL_ACCESS, 0, 0, Size);
|
Data_ = (char*)MapViewOfFile(MemoryHandle_, FILE_MAP_ALL_ACCESS, 0, 0, Size);
|
||||||
@@ -82,11 +83,9 @@ IPC::~IPC() noexcept {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool IPC::mem_used(uint32_t MemID) noexcept {
|
bool IPC::mem_used(uint32_t MemID) noexcept {
|
||||||
std::string Mem{"MP_IO" + std::to_string(MemID)};
|
std::string Mem { "MP_IO" + std::to_string(MemID) };
|
||||||
HANDLE MEM = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
HANDLE MEM = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
|
||||||
bool used = MEM != nullptr;
|
bool used = MEM != nullptr;
|
||||||
UnmapViewOfFile(MEM);
|
UnmapViewOfFile(MEM);
|
||||||
return used;
|
return used;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+20
-20
@@ -7,9 +7,9 @@
|
|||||||
#undef UNICODE
|
#undef UNICODE
|
||||||
#include "Memory/Memory.h"
|
#include "Memory/Memory.h"
|
||||||
#include "Memory/BeamNG.h"
|
#include "Memory/BeamNG.h"
|
||||||
|
#include <psapi.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tlhelp32.h>
|
#include <tlhelp32.h>
|
||||||
#include <psapi.h>
|
|
||||||
|
|
||||||
uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||||
SetLastError(0);
|
SetLastError(0);
|
||||||
@@ -17,21 +17,22 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
|||||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||||
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||||
|
|
||||||
if(Process32First(Snapshot, &pe32)) {
|
if (Process32First(Snapshot, &pe32)) {
|
||||||
do{
|
do {
|
||||||
if(std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
if (std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
||||||
&& BL.find(pe32.th32ProcessID) == BL.end()
|
&& BL.find(pe32.th32ProcessID) == BL.end()
|
||||||
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while(Process32Next(Snapshot, &pe32));
|
} while (Process32Next(Snapshot, &pe32));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Snapshot != INVALID_HANDLE_VALUE) {
|
if (Snapshot != INVALID_HANDLE_VALUE) {
|
||||||
CloseHandle(Snapshot);
|
CloseHandle(Snapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GetLastError() != 0)return 0;
|
if (GetLastError() != 0)
|
||||||
|
return 0;
|
||||||
return pe32.th32ProcessID;
|
return pe32.th32ProcessID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,24 +45,23 @@ uint32_t Memory::GetPID() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
|
uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
|
||||||
MODULEINFO mInfo{nullptr};
|
MODULEINFO mInfo { nullptr };
|
||||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(module), &mInfo, sizeof(MODULEINFO));
|
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(module), &mInfo, sizeof(MODULEINFO));
|
||||||
auto base = uint64_t(mInfo.lpBaseOfDll);
|
auto base = uint64_t(mInfo.lpBaseOfDll);
|
||||||
auto size = uint32_t(mInfo.SizeOfImage);
|
auto size = uint32_t(mInfo.SizeOfImage);
|
||||||
auto len = strlen(Pattern[1]);
|
auto len = strlen(Pattern[1]);
|
||||||
for(auto i = 0; i < size - len; i++) {
|
for (auto i = 0; i < size - len; i++) {
|
||||||
bool found = true;
|
bool found = true;
|
||||||
for(auto j = 0; j < len && found; j++) {
|
for (auto j = 0; j < len && found; j++) {
|
||||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base+i+j);
|
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
|
||||||
}
|
}
|
||||||
if(found) {
|
if (found) {
|
||||||
return base+i;
|
return base + i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void* operator new(size_t size) {
|
void* operator new(size_t size) {
|
||||||
return GlobalAlloc(GPTR, size);
|
return GlobalAlloc(GPTR, size);
|
||||||
}
|
}
|
||||||
@@ -98,11 +98,11 @@ void Memory::Inject(uint32_t PID) {
|
|||||||
|
|
||||||
auto relocationTable = (PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
auto relocationTable = (PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
||||||
PDWORD_PTR patchedAddress;
|
PDWORD_PTR patchedAddress;
|
||||||
while (relocationTable->SizeOfBlock > 0){
|
while (relocationTable->SizeOfBlock > 0) {
|
||||||
DWORD relocationEntriesCount = (relocationTable->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
DWORD relocationEntriesCount = (relocationTable->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
||||||
auto relocationRVA = (PBASE_RELOCATION_ENTRY)(relocationTable + 1);
|
auto relocationRVA = (PBASE_RELOCATION_ENTRY)(relocationTable + 1);
|
||||||
for (uint32_t i = 0; i < relocationEntriesCount; i++){
|
for (uint32_t i = 0; i < relocationEntriesCount; i++) {
|
||||||
if (relocationRVA[i].Offset){
|
if (relocationRVA[i].Offset) {
|
||||||
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) + relocationTable->VirtualAddress + relocationRVA[i].Offset);
|
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) + relocationTable->VirtualAddress + relocationRVA[i].Offset);
|
||||||
*patchedAddress += deltaImageBase;
|
*patchedAddress += deltaImageBase;
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,7 @@ void Memory::Inject(uint32_t PID) {
|
|||||||
relocationTable = PIMAGE_BASE_RELOCATION(DWORD_PTR(relocationTable) + relocationTable->SizeOfBlock);
|
relocationTable = PIMAGE_BASE_RELOCATION(DWORD_PTR(relocationTable) + relocationTable->SizeOfBlock);
|
||||||
}
|
}
|
||||||
WriteProcessMemory(targetProcess, targetImage, localImage, ntHeader->OptionalHeader.SizeOfImage, nullptr);
|
WriteProcessMemory(targetProcess, targetImage, localImage, ntHeader->OptionalHeader.SizeOfImage, nullptr);
|
||||||
CreateRemoteThread(targetProcess,nullptr,0,(LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase),nullptr,0,nullptr);
|
CreateRemoteThread(targetProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase), nullptr, 0, nullptr);
|
||||||
CloseHandle(targetProcess);
|
CloseHandle(targetProcess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-14
@@ -7,46 +7,46 @@
|
|||||||
#include <zlib.h>
|
#include <zlib.h>
|
||||||
|
|
||||||
#define Biggest 30000
|
#define Biggest 30000
|
||||||
std::string Zlib::Comp(std::string Data){
|
std::string Zlib::Comp(std::string Data) {
|
||||||
char*C = new char[Biggest];
|
char* C = new char[Biggest];
|
||||||
memset(C, 0, Biggest);
|
memset(C, 0, Biggest);
|
||||||
z_stream defstream;
|
z_stream defstream;
|
||||||
defstream.zalloc = Z_NULL;
|
defstream.zalloc = Z_NULL;
|
||||||
defstream.zfree = Z_NULL;
|
defstream.zfree = Z_NULL;
|
||||||
defstream.opaque = Z_NULL;
|
defstream.opaque = Z_NULL;
|
||||||
defstream.avail_in = (uInt)Data.length();
|
defstream.avail_in = (uInt)Data.length();
|
||||||
defstream.next_in = (Bytef *)&Data[0];
|
defstream.next_in = (Bytef*)&Data[0];
|
||||||
defstream.avail_out = Biggest;
|
defstream.avail_out = Biggest;
|
||||||
defstream.next_out = reinterpret_cast<Bytef *>(C);
|
defstream.next_out = reinterpret_cast<Bytef*>(C);
|
||||||
deflateInit(&defstream, Z_BEST_COMPRESSION);
|
deflateInit(&defstream, Z_BEST_COMPRESSION);
|
||||||
deflate(&defstream, Z_SYNC_FLUSH);
|
deflate(&defstream, Z_SYNC_FLUSH);
|
||||||
deflate(&defstream, Z_FINISH);
|
deflate(&defstream, Z_FINISH);
|
||||||
deflateEnd(&defstream);
|
deflateEnd(&defstream);
|
||||||
uint32_t TO = defstream.total_out;
|
uint32_t TO = defstream.total_out;
|
||||||
std::string Ret(TO,0);
|
std::string Ret(TO, 0);
|
||||||
memcpy_s(&Ret[0],TO,C,TO);
|
memcpy_s(&Ret[0], TO, C, TO);
|
||||||
delete [] C;
|
delete[] C;
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Zlib::DeComp(std::string Compressed){
|
std::string Zlib::DeComp(std::string Compressed) {
|
||||||
char*C = new char[Biggest];
|
char* C = new char[Biggest];
|
||||||
memset(C, 0, Biggest);
|
memset(C, 0, Biggest);
|
||||||
z_stream infstream;
|
z_stream infstream;
|
||||||
infstream.zalloc = Z_NULL;
|
infstream.zalloc = Z_NULL;
|
||||||
infstream.zfree = Z_NULL;
|
infstream.zfree = Z_NULL;
|
||||||
infstream.opaque = Z_NULL;
|
infstream.opaque = Z_NULL;
|
||||||
infstream.avail_in = Biggest;
|
infstream.avail_in = Biggest;
|
||||||
infstream.next_in = (Bytef *)(&Compressed[0]);
|
infstream.next_in = (Bytef*)(&Compressed[0]);
|
||||||
infstream.avail_out = Biggest;
|
infstream.avail_out = Biggest;
|
||||||
infstream.next_out = (Bytef *)(C);
|
infstream.next_out = (Bytef*)(C);
|
||||||
inflateInit(&infstream);
|
inflateInit(&infstream);
|
||||||
inflate(&infstream, Z_SYNC_FLUSH);
|
inflate(&infstream, Z_SYNC_FLUSH);
|
||||||
inflate(&infstream, Z_FINISH);
|
inflate(&infstream, Z_FINISH);
|
||||||
inflateEnd(&infstream);
|
inflateEnd(&infstream);
|
||||||
uint32_t TO = infstream.total_out;
|
uint32_t TO = infstream.total_out;
|
||||||
std::string Ret(TO,0);
|
std::string Ret(TO, 0);
|
||||||
memcpy_s(&Ret[0],TO,C,TO);
|
memcpy_s(&Ret[0], TO, C, TO);
|
||||||
delete [] C;
|
delete[] C;
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-28
@@ -3,22 +3,22 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
#include <cpp-httplib/httplib.h>
|
|
||||||
#include "Launcher.h"
|
|
||||||
#include "HttpAPI.h"
|
#include "HttpAPI.h"
|
||||||
#include <iostream>
|
#include "Launcher.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
#include <fstream>
|
|
||||||
#include <mutex>
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cpp-httplib/httplib.h>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
bool HTTP::isDownload = false;
|
bool HTTP::isDownload = false;
|
||||||
std::atomic<httplib::Client*> CliRef = nullptr;
|
std::atomic<httplib::Client*> CliRef = nullptr;
|
||||||
std::string HTTP::Get(const std::string &IP) {
|
std::string HTTP::Get(const std::string& IP) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
auto pos = IP.find('/',10);
|
auto pos = IP.find('/', 10);
|
||||||
|
|
||||||
httplib::Client cli(IP.substr(0, pos));
|
httplib::Client cli(IP.substr(0, pos));
|
||||||
CliRef.store(&cli);
|
CliRef.store(&cli);
|
||||||
@@ -26,13 +26,14 @@ std::string HTTP::Get(const std::string &IP) {
|
|||||||
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
auto res = cli.Get(IP.substr(pos).c_str(), ProgressBar);
|
||||||
std::string Ret;
|
std::string Ret;
|
||||||
|
|
||||||
if(res.error() == httplib::Error::Success){
|
if (res.error() == httplib::Error::Success) {
|
||||||
if(res->status == 200){
|
if (res->status == 200) {
|
||||||
Ret = res->body;
|
Ret = res->body;
|
||||||
}else LOG(ERROR) << res->reason;
|
} else
|
||||||
|
LOG(ERROR) << res->reason;
|
||||||
|
|
||||||
}else{
|
} else {
|
||||||
if(isDownload) {
|
if (isDownload) {
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
LOG(ERROR) << "HTTP Get failed on " << httplib::to_string(res.error());
|
LOG(ERROR) << "HTTP Get failed on " << httplib::to_string(res.error());
|
||||||
@@ -45,27 +46,27 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
auto pos = IP.find('/',10);
|
auto pos = IP.find('/', 10);
|
||||||
|
|
||||||
httplib::Client cli(IP.substr(0, pos));
|
httplib::Client cli(IP.substr(0, pos));
|
||||||
CliRef.store(&cli);
|
CliRef.store(&cli);
|
||||||
cli.set_connection_timeout(std::chrono::seconds(5));
|
cli.set_connection_timeout(std::chrono::seconds(5));
|
||||||
std::string Ret;
|
std::string Ret;
|
||||||
|
|
||||||
if(!Fields.empty()) {
|
if (!Fields.empty()) {
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
httplib::Result res = cli.Post(IP.substr(pos).c_str(), Fields, "application/json");
|
||||||
|
|
||||||
if(res.error() == httplib::Error::Success) {
|
if (res.error() == httplib::Error::Success) {
|
||||||
if(res->status != 200) {
|
if (res->status != 200) {
|
||||||
LOG(ERROR) << res->reason;
|
LOG(ERROR) << res->reason;
|
||||||
}
|
}
|
||||||
Ret = res->body;
|
Ret = res->body;
|
||||||
} else{
|
} else {
|
||||||
LOG(ERROR) << "HTTP Post failed on " << httplib::to_string(res.error());
|
LOG(ERROR) << "HTTP Post failed on " << httplib::to_string(res.error());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
httplib::Result res = cli.Post(IP.substr(pos).c_str());
|
||||||
if(res.error() == httplib::Error::Success) {
|
if (res.error() == httplib::Error::Success) {
|
||||||
if (res->status != 200) {
|
if (res->status != 200) {
|
||||||
LOG(ERROR) << res->reason;
|
LOG(ERROR) << res->reason;
|
||||||
}
|
}
|
||||||
@@ -75,12 +76,14 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
CliRef.store(nullptr);
|
CliRef.store(nullptr);
|
||||||
if(Ret.empty())return "-1";
|
if (Ret.empty())
|
||||||
else return Ret;
|
return "-1";
|
||||||
|
else
|
||||||
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::ProgressBar(size_t c, size_t t){
|
bool HTTP::ProgressBar(size_t c, size_t t) {
|
||||||
if(isDownload) {
|
if (isDownload) {
|
||||||
static double progress_bar_adv;
|
static double progress_bar_adv;
|
||||||
progress_bar_adv = round(double(c) / double(t) * 25);
|
progress_bar_adv = round(double(c) / double(t) * 25);
|
||||||
std::cout << "\r";
|
std::cout << "\r";
|
||||||
@@ -88,11 +91,13 @@ bool HTTP::ProgressBar(size_t c, size_t t){
|
|||||||
std::cout << round(double(c) / double(t) * 100);
|
std::cout << round(double(c) / double(t) * 100);
|
||||||
std::cout << "% ] [";
|
std::cout << "% ] [";
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i <= progress_bar_adv; i++)std::cout << "#";
|
for (i = 0; i <= progress_bar_adv; i++)
|
||||||
for (i = 0; i < 25 - progress_bar_adv; i++)std::cout << ".";
|
std::cout << "#";
|
||||||
|
for (i = 0; i < 25 - progress_bar_adv; i++)
|
||||||
|
std::cout << ".";
|
||||||
std::cout << "]";
|
std::cout << "]";
|
||||||
}
|
}
|
||||||
if(Launcher::Terminated()) {
|
if (Launcher::Terminated()) {
|
||||||
CliRef.load()->stop();
|
CliRef.load()->stop();
|
||||||
std::cout << '\n';
|
std::cout << '\n';
|
||||||
isDownload = false;
|
isDownload = false;
|
||||||
@@ -101,7 +106,7 @@ bool HTTP::ProgressBar(size_t c, size_t t){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::Download(const std::string &IP, const std::string &Path) {
|
bool HTTP::Download(const std::string& IP, const std::string& Path) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
@@ -109,10 +114,11 @@ bool HTTP::Download(const std::string &IP, const std::string &Path) {
|
|||||||
std::string Ret = Get(IP);
|
std::string Ret = Get(IP);
|
||||||
isDownload = false;
|
isDownload = false;
|
||||||
|
|
||||||
if(Ret.empty())return false;
|
if (Ret.empty())
|
||||||
|
return false;
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
std::ofstream File(Path, std::ios::binary);
|
std::ofstream File(Path, std::ios::binary);
|
||||||
if(File.is_open()) {
|
if (File.is_open()) {
|
||||||
File << Ret;
|
File << Ret;
|
||||||
File.close();
|
File.close();
|
||||||
LOG(INFO) << "Download complete!";
|
LOG(INFO) << "Download complete!";
|
||||||
|
|||||||
+23
-24
@@ -3,22 +3,22 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Launcher.h"
|
|
||||||
#include "HttpAPI.h"
|
#include "HttpAPI.h"
|
||||||
#include "Logger.h"
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
#include "Launcher.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
void UpdateKey(const std::string& newKey){
|
void UpdateKey(const std::string& newKey) {
|
||||||
if(!newKey.empty()){
|
if (!newKey.empty()) {
|
||||||
std::ofstream Key("key");
|
std::ofstream Key("key");
|
||||||
if(Key.is_open()){
|
if (Key.is_open()) {
|
||||||
Key << newKey;
|
Key << newKey;
|
||||||
Key.close();
|
Key.close();
|
||||||
} else {
|
} else {
|
||||||
LOG(FATAL) << "Cannot write to disk!";
|
LOG(FATAL) << "Cannot write to disk!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
}
|
}
|
||||||
}else if(fs::exists("key")){
|
} else if (fs::exists("key")) {
|
||||||
remove("key");
|
remove("key");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,15 +27,15 @@ void UpdateKey(const std::string& newKey){
|
|||||||
/// "Guest":"Name"
|
/// "Guest":"Name"
|
||||||
/// "pk":"private_key"
|
/// "pk":"private_key"
|
||||||
|
|
||||||
std::string GetFail(const std::string& R){
|
std::string GetFail(const std::string& R) {
|
||||||
std::string DRet = R"({"success":false,"message":)";
|
std::string DRet = R"({"success":false,"message":)";
|
||||||
DRet += "\""+R+"\"}";
|
DRet += "\"" + R + "\"}";
|
||||||
LOG(ERROR) << R;
|
LOG(ERROR) << R;
|
||||||
return DRet;
|
return DRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Launcher::Login(const std::string& fields) {
|
std::string Launcher::Login(const std::string& fields) {
|
||||||
if(fields == "LO"){
|
if (fields == "LO") {
|
||||||
LoginAuth = false;
|
LoginAuth = false;
|
||||||
UpdateKey("");
|
UpdateKey("");
|
||||||
return "";
|
return "";
|
||||||
@@ -44,7 +44,7 @@ std::string Launcher::Login(const std::string& fields) {
|
|||||||
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields);
|
||||||
Json d = Json::parse(Buffer, nullptr, false);
|
Json d = Json::parse(Buffer, nullptr, false);
|
||||||
|
|
||||||
if(Buffer == "-1"){
|
if (Buffer == "-1") {
|
||||||
return GetFail("Failed to communicate with the auth system!");
|
return GetFail("Failed to communicate with the auth system!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,18 +53,19 @@ std::string Launcher::Login(const std::string& fields) {
|
|||||||
return GetFail("Invalid answer from authentication servers, please try again later!");
|
return GetFail("Invalid answer from authentication servers, please try again later!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!d["success"].is_null() && d["success"].get<bool>()){
|
if (!d["success"].is_null() && d["success"].get<bool>()) {
|
||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
if(!d["private_key"].is_null()){
|
if (!d["private_key"].is_null()) {
|
||||||
UpdateKey(d["private_key"].get<std::string>());
|
UpdateKey(d["private_key"].get<std::string>());
|
||||||
}
|
}
|
||||||
if(!d["public_key"].is_null()){
|
if (!d["public_key"].is_null()) {
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
}
|
}
|
||||||
LOG(INFO) << "Authentication successful!";
|
LOG(INFO) << "Authentication successful!";
|
||||||
}else LOG(WARNING) << "Authentication failed!";
|
} else
|
||||||
|
LOG(WARNING) << "Authentication failed!";
|
||||||
|
|
||||||
if(!d["message"].is_null()) {
|
if (!d["message"].is_null()) {
|
||||||
d.erase("private_key");
|
d.erase("private_key");
|
||||||
d.erase("public_key");
|
d.erase("public_key");
|
||||||
return d.dump();
|
return d.dump();
|
||||||
@@ -73,9 +74,9 @@ std::string Launcher::Login(const std::string& fields) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::CheckKey() {
|
void Launcher::CheckKey() {
|
||||||
if(fs::exists("key") && fs::file_size("key") < 100){
|
if (fs::exists("key") && fs::file_size("key") < 100) {
|
||||||
std::ifstream Key("key");
|
std::ifstream Key("key");
|
||||||
if(Key.is_open()) {
|
if (Key.is_open()) {
|
||||||
auto Size = fs::file_size("key");
|
auto Size = fs::file_size("key");
|
||||||
std::string Buffer(Size, 0);
|
std::string Buffer(Size, 0);
|
||||||
Key.read(&Buffer[0], std::streamsize(Size));
|
Key.read(&Buffer[0], std::streamsize(Size));
|
||||||
@@ -89,22 +90,20 @@ void Launcher::CheckKey() {
|
|||||||
LOG(FATAL) << "Invalid answer from authentication servers, please try again later!";
|
LOG(FATAL) << "Invalid answer from authentication servers, please try again later!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
}
|
}
|
||||||
if(d["success"].get<bool>()){
|
if (d["success"].get<bool>()) {
|
||||||
LoginAuth = true;
|
LoginAuth = true;
|
||||||
UpdateKey(d["private_key"].get<std::string>());
|
UpdateKey(d["private_key"].get<std::string>());
|
||||||
PublicKey = d["public_key"].get<std::string>();
|
PublicKey = d["public_key"].get<std::string>();
|
||||||
UserRole = d["role"].get<std::string>();
|
UserRole = d["role"].get<std::string>();
|
||||||
LOG(INFO) << "Auto-Authentication was successful";
|
LOG(INFO) << "Auto-Authentication was successful";
|
||||||
}else{
|
} else {
|
||||||
LOG(WARNING) << "Auto-Authentication unsuccessful please re-login!";
|
LOG(WARNING) << "Auto-Authentication unsuccessful please re-login!";
|
||||||
UpdateKey("");
|
UpdateKey("");
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
LOG(WARNING) << "Could not open saved key!";
|
LOG(WARNING) << "Could not open saved key!";
|
||||||
UpdateKey("");
|
UpdateKey("");
|
||||||
}
|
}
|
||||||
}else UpdateKey("");
|
} else
|
||||||
|
UpdateKey("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+91
-76
@@ -3,42 +3,43 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#include <filesystem>
|
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
#include "Server.h"
|
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Server.h"
|
||||||
|
#include <atomic>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <future>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <future>
|
#include <ws2tcpip.h>
|
||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
std::vector<std::string> Split(const std::string& String, const std::string& delimiter){
|
std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
||||||
std::vector<std::string> Val;
|
std::vector<std::string> Val;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
std::string token,s = String;
|
std::string token, s = String;
|
||||||
while ((pos = s.find(delimiter)) != std::string::npos) {
|
while ((pos = s.find(delimiter)) != std::string::npos) {
|
||||||
token = s.substr(0, pos);
|
token = s.substr(0, pos);
|
||||||
if(!token.empty())Val.push_back(token);
|
if (!token.empty())
|
||||||
|
Val.push_back(token);
|
||||||
s.erase(0, pos + delimiter.length());
|
s.erase(0, pos + delimiter.length());
|
||||||
}
|
}
|
||||||
if(!s.empty())Val.push_back(s);
|
if (!s.empty())
|
||||||
|
Val.push_back(s);
|
||||||
return Val;
|
return Val;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckForDir(){
|
void CheckForDir() {
|
||||||
if(!fs::exists("Resources")){
|
if (!fs::exists("Resources")) {
|
||||||
_wmkdir(L"Resources");
|
_wmkdir(L"Resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::WaitForConfirm() {
|
void Server::WaitForConfirm() {
|
||||||
while(!Terminate && !ModLoaded){
|
while (!Terminate && !ModLoaded) {
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
}
|
}
|
||||||
ModLoaded = false;
|
ModLoaded = false;
|
||||||
@@ -54,39 +55,41 @@ std::string Server::Auth() {
|
|||||||
|
|
||||||
auto Res = TCPRcv();
|
auto Res = TCPRcv();
|
||||||
|
|
||||||
if(Res.empty() || Res[0] == 'E'){
|
if (Res.empty() || Res[0] == 'E') {
|
||||||
Abort();
|
Abort();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
TCPSend(LauncherInstance->getPublicKey());
|
TCPSend(LauncherInstance->getPublicKey());
|
||||||
if(Terminate)return "";
|
if (Terminate)
|
||||||
|
return "";
|
||||||
|
|
||||||
Res = TCPRcv();
|
Res = TCPRcv();
|
||||||
if(Res.empty() || Res[0] != 'P'){
|
if (Res.empty() || Res[0] != 'P') {
|
||||||
Abort();
|
Abort();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Res = Res.substr(1);
|
Res = Res.substr(1);
|
||||||
if(std::all_of(Res.begin(), Res.end(), isdigit)){
|
if (std::all_of(Res.begin(), Res.end(), isdigit)) {
|
||||||
ClientID = std::stoi(Res);
|
ClientID = std::stoi(Res);
|
||||||
}else{
|
} else {
|
||||||
Abort();
|
Abort();
|
||||||
UUl("Authentication failed!");
|
UUl("Authentication failed!");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
TCPSend("SR");
|
TCPSend("SR");
|
||||||
if(Terminate)return "";
|
if (Terminate)
|
||||||
|
return "";
|
||||||
|
|
||||||
Res = TCPRcv();
|
Res = TCPRcv();
|
||||||
|
|
||||||
if(Res[0] == 'E'){
|
if (Res[0] == 'E') {
|
||||||
Abort();
|
Abort();
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Res.empty() || Res == "-"){
|
if (Res.empty() || Res == "-") {
|
||||||
LOG(INFO) << "Didn't Receive any mods...";
|
LOG(INFO) << "Didn't Receive any mods...";
|
||||||
ModList = "-";
|
ModList = "-";
|
||||||
TCPSend("Done");
|
TCPSend("Done");
|
||||||
@@ -97,32 +100,35 @@ std::string Server::Auth() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::UpdateUl(bool D, const std::string& msg) {
|
void Server::UpdateUl(bool D, const std::string& msg) {
|
||||||
if(D)UStatus = "UlDownloading Resource " + msg;
|
if (D)
|
||||||
else UStatus = "UlLoading Resource " + msg;
|
UStatus = "UlDownloading Resource " + msg;
|
||||||
|
else
|
||||||
|
UStatus = "UlLoading Resource " + msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::AsyncUpdate(uint64_t& Rcv,uint64_t Size,const std::string& Name) {
|
void Server::AsyncUpdate(uint64_t& Rcv, uint64_t Size, const std::string& Name) {
|
||||||
do {
|
do {
|
||||||
double pr = double(Rcv) / double(Size) * 100;
|
double pr = double(Rcv) / double(Size) * 100;
|
||||||
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
std::string Per = std::to_string(trunc(pr * 10) / 10);
|
||||||
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
UpdateUl(true, Name + " (" + Per.substr(0, Per.find('.') + 2) + "%)");
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}while(!Terminate && Rcv < Size);
|
} while (!Terminate && Rcv < Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* Server::TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size) {
|
char* Server::TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size) {
|
||||||
if(Sock == -1){
|
if (Sock == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Invalid Socket");
|
UUl("Invalid Socket");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
char* File = new char[Size];
|
char* File = new char[Size];
|
||||||
uint64_t Rcv = 0;
|
uint64_t Rcv = 0;
|
||||||
do{
|
do {
|
||||||
int Len = int(Size-Rcv);
|
int Len = int(Size - Rcv);
|
||||||
if(Len > 1000000)Len = 1000000;
|
if (Len > 1000000)
|
||||||
|
Len = 1000000;
|
||||||
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
|
||||||
if(Temp < 1){
|
if (Temp < 1) {
|
||||||
UUl("Socket Closed Code 1");
|
UUl("Socket Closed Code 1");
|
||||||
KillSocket(Sock);
|
KillSocket(Sock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@@ -131,7 +137,7 @@ char* Server::TCPRcvRaw(uint64_t Sock, uint64_t& GRcv, uint64_t Size) {
|
|||||||
}
|
}
|
||||||
Rcv += Temp;
|
Rcv += Temp;
|
||||||
GRcv += Temp;
|
GRcv += Temp;
|
||||||
}while(Rcv < Size && !Terminate);
|
} while (Rcv < Size && !Terminate);
|
||||||
return File;
|
return File;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +150,7 @@ void Server::MultiKill(uint64_t Sock) {
|
|||||||
uint64_t Server::InitDSock() {
|
uint64_t Server::InitDSock() {
|
||||||
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
SOCKADDR_IN ServerAddr;
|
SOCKADDR_IN ServerAddr;
|
||||||
if(DSock < 1) {
|
if (DSock < 1) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -152,13 +158,13 @@ uint64_t Server::InitDSock() {
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
if(connect(DSock, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)) != 0){
|
if (connect(DSock, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr)) != 0) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
char Code[2] = {'D', char(ClientID)};
|
char Code[2] = { 'D', char(ClientID) };
|
||||||
if(send(DSock,Code,2,0) != 2){
|
if (send(DSock, Code, 2, 0) != 2) {
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -168,18 +174,18 @@ uint64_t Server::InitDSock() {
|
|||||||
|
|
||||||
std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name) {
|
std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::string& Name) {
|
||||||
|
|
||||||
uint64_t GRcv = 0, MSize = Size/2, DSize = Size - MSize;
|
uint64_t GRcv = 0, MSize = Size / 2, DSize = Size - MSize;
|
||||||
|
|
||||||
std::thread Au(&Server::AsyncUpdate, this, std::ref(GRcv), Size, Name);
|
std::thread Au(&Server::AsyncUpdate, this, std::ref(GRcv), Size, Name);
|
||||||
|
|
||||||
std::packaged_task<char*()> task([&] { return TCPRcvRaw(TCPSocket,GRcv,MSize); });
|
std::packaged_task<char*()> task([&] { return TCPRcvRaw(TCPSocket, GRcv, MSize); });
|
||||||
std::future<char*> f1 = task.get_future();
|
std::future<char*> f1 = task.get_future();
|
||||||
std::thread Dt(std::move(task));
|
std::thread Dt(std::move(task));
|
||||||
Dt.detach();
|
Dt.detach();
|
||||||
|
|
||||||
char* DData = TCPRcvRaw(DSock,GRcv,DSize);
|
char* DData = TCPRcvRaw(DSock, GRcv, DSize);
|
||||||
|
|
||||||
if(!DData){
|
if (!DData) {
|
||||||
MultiKill(DSock);
|
MultiKill(DSock);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -187,21 +193,21 @@ std::string Server::MultiDownload(uint64_t DSock, uint64_t Size, const std::stri
|
|||||||
f1.wait();
|
f1.wait();
|
||||||
char* MData = f1.get();
|
char* MData = f1.get();
|
||||||
|
|
||||||
if(!MData){
|
if (!MData) {
|
||||||
MultiKill(DSock);
|
MultiKill(DSock);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Au.joinable())Au.join();
|
if (Au.joinable())
|
||||||
|
Au.join();
|
||||||
|
|
||||||
|
/// omg yes very ugly my god but i was in a rush will revisit
|
||||||
|
std::string Ret(Size, 0);
|
||||||
|
memcpy_s(&Ret[0], MSize, MData, MSize);
|
||||||
|
delete[] MData;
|
||||||
|
|
||||||
///omg yes very ugly my god but i was in a rush will revisit
|
memcpy_s(&Ret[MSize], DSize, DData, DSize);
|
||||||
std::string Ret(Size,0);
|
delete[] DData;
|
||||||
memcpy_s(&Ret[0],MSize,MData,MSize);
|
|
||||||
delete[]MData;
|
|
||||||
|
|
||||||
memcpy_s(&Ret[MSize],DSize,DData,DSize);
|
|
||||||
delete[]DData;
|
|
||||||
|
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
@@ -214,7 +220,8 @@ void Server::InvalidResource(const std::string& File) {
|
|||||||
|
|
||||||
void Server::SyncResources() {
|
void Server::SyncResources() {
|
||||||
std::string Ret = Auth();
|
std::string Ret = Auth();
|
||||||
if(Ret.empty())return;
|
if (Ret.empty())
|
||||||
|
return;
|
||||||
LOG(INFO) << "Checking Resources...";
|
LOG(INFO) << "Checking Resources...";
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
|
|
||||||
@@ -224,45 +231,51 @@ void Server::SyncResources() {
|
|||||||
list.clear();
|
list.clear();
|
||||||
Ret.clear();
|
Ret.clear();
|
||||||
|
|
||||||
int Amount = 0,Pos = 0;
|
int Amount = 0, Pos = 0;
|
||||||
std::string a,t;
|
std::string a, t;
|
||||||
for(const std::string&name : FNames){
|
for (const std::string& name : FNames) {
|
||||||
if(!name.empty()){
|
if (!name.empty()) {
|
||||||
t += name.substr(name.find_last_of('/') + 1) + ";";
|
t += name.substr(name.find_last_of('/') + 1) + ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(t.empty())ModList = "-";
|
if (t.empty())
|
||||||
else ModList = t;
|
ModList = "-";
|
||||||
|
else
|
||||||
|
ModList = t;
|
||||||
t.clear();
|
t.clear();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
auto ZIP = FN->find(".zip");
|
auto ZIP = FN->find(".zip");
|
||||||
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
if (ZIP == std::string::npos || FN->length() - ZIP != 4) {
|
||||||
InvalidResource(*FN);
|
InvalidResource(*FN);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pos == std::string::npos)continue;
|
if (pos == std::string::npos)
|
||||||
|
continue;
|
||||||
Amount++;
|
Amount++;
|
||||||
}
|
}
|
||||||
if(!FNames.empty())LOG(INFO) << "Syncing...";
|
if (!FNames.empty())
|
||||||
|
LOG(INFO) << "Syncing...";
|
||||||
SOCKET DSock = InitDSock();
|
SOCKET DSock = InitDSock();
|
||||||
for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) {
|
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
|
||||||
auto pos = FN->find_last_of('/');
|
auto pos = FN->find_last_of('/');
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
a = "Resources" + FN->substr(pos);
|
a = "Resources" + FN->substr(pos);
|
||||||
} else continue;
|
} else
|
||||||
|
continue;
|
||||||
Pos++;
|
Pos++;
|
||||||
if (fs::exists(a)) {
|
if (fs::exists(a)) {
|
||||||
if (!std::all_of(FS->begin(), FS->end(), isdigit))continue;
|
if (!std::all_of(FS->begin(), FS->end(), isdigit))
|
||||||
if (fs::file_size(a) == std::stoull(*FS)){
|
continue;
|
||||||
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
if (fs::file_size(a) == std::stoull(*FS)) {
|
||||||
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/')));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if(!fs::exists(LauncherInstance->getMPUserPath())){
|
if (!fs::exists(LauncherInstance->getMPUserPath())) {
|
||||||
fs::create_directories(LauncherInstance->getMPUserPath());
|
fs::create_directories(LauncherInstance->getMPUserPath());
|
||||||
}
|
}
|
||||||
fs::copy_file(a, LauncherInstance->getMPUserPath() + a.substr(a.find_last_of('/')),
|
fs::copy_file(a, LauncherInstance->getMPUserPath() + a.substr(a.find_last_of('/')),
|
||||||
fs::copy_options::overwrite_existing);
|
fs::copy_options::overwrite_existing);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
LOG(ERROR) << "Failed copy to the mods folder! " << e.what();
|
LOG(ERROR) << "Failed copy to the mods folder! " << e.what();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@@ -270,7 +283,8 @@ void Server::SyncResources() {
|
|||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
continue;
|
continue;
|
||||||
}else remove(a.c_str());
|
} else
|
||||||
|
remove(a.c_str());
|
||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::string FName = a.substr(a.find_last_of('/'));
|
std::string FName = a.substr(a.find_last_of('/'));
|
||||||
@@ -278,7 +292,7 @@ void Server::SyncResources() {
|
|||||||
TCPSend("f" + *FN);
|
TCPSend("f" + *FN);
|
||||||
|
|
||||||
std::string Data = TCPRcv();
|
std::string Data = TCPRcv();
|
||||||
if (Data == "CO" || Terminate){
|
if (Data == "CO" || Terminate) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
UUl("Server cannot find " + FName);
|
UUl("Server cannot find " + FName);
|
||||||
break;
|
break;
|
||||||
@@ -286,10 +300,11 @@ void Server::SyncResources() {
|
|||||||
|
|
||||||
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName;
|
||||||
|
|
||||||
Data = MultiDownload(DSock,std::stoull(*FS), Name);
|
Data = MultiDownload(DSock, std::stoull(*FS), Name);
|
||||||
|
|
||||||
if(Terminate)break;
|
if (Terminate)
|
||||||
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
|
break;
|
||||||
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName);
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
|
||||||
if (LFS.is_open()) {
|
if (LFS.is_open()) {
|
||||||
@@ -297,20 +312,20 @@ void Server::SyncResources() {
|
|||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}while(fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
} while (fs::file_size(a) != std::stoull(*FS) && !Terminate);
|
||||||
if(!Terminate){
|
if (!Terminate) {
|
||||||
if(!fs::exists(LauncherInstance->getMPUserPath())){
|
if (!fs::exists(LauncherInstance->getMPUserPath())) {
|
||||||
fs::create_directories(LauncherInstance->getMPUserPath());
|
fs::create_directories(LauncherInstance->getMPUserPath());
|
||||||
}
|
}
|
||||||
fs::copy_file(a,LauncherInstance->getMPUserPath() + FName, fs::copy_options::overwrite_existing);
|
fs::copy_file(a, LauncherInstance->getMPUserPath() + FName, fs::copy_options::overwrite_existing);
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
}
|
}
|
||||||
KillSocket(DSock);
|
KillSocket(DSock);
|
||||||
if(!Terminate){
|
if (!Terminate) {
|
||||||
TCPSend("Done");
|
TCPSend("Done");
|
||||||
LOG(INFO) << "Done!";
|
LOG(INFO) << "Done!";
|
||||||
}else{
|
} else {
|
||||||
UStatus = "start";
|
UStatus = "start";
|
||||||
LOG(INFO) << "Connection Terminated!";
|
LOG(INFO) << "Connection Terminated!";
|
||||||
}
|
}
|
||||||
|
|||||||
+61
-43
@@ -5,17 +5,18 @@
|
|||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
#include "Compressor.h"
|
|
||||||
#include "Server.h"
|
#include "Server.h"
|
||||||
|
#include "Compressor.h"
|
||||||
#include "Launcher.h"
|
#include "Launcher.h"
|
||||||
|
#include "Logger.h"
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
#include <ws2tcpip.h>
|
#include <ws2tcpip.h>
|
||||||
#include "Logger.h"
|
|
||||||
|
|
||||||
Server::Server(Launcher *Instance) : LauncherInstance(Instance) {
|
Server::Server(Launcher* Instance)
|
||||||
|
: LauncherInstance(Instance) {
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
int iRes = WSAStartup(514, &wsaData); //2.2
|
int iRes = WSAStartup(514, &wsaData); // 2.2
|
||||||
if (iRes != 0) {
|
if (iRes != 0) {
|
||||||
LOG(ERROR) << "WSAStartup failed with error: " << iRes;
|
LOG(ERROR) << "WSAStartup failed with error: " << iRes;
|
||||||
}
|
}
|
||||||
@@ -42,7 +43,7 @@ void Server::TCPClientMain() {
|
|||||||
ServerAddr.sin_family = AF_INET;
|
ServerAddr.sin_family = AF_INET;
|
||||||
ServerAddr.sin_port = htons(Port);
|
ServerAddr.sin_port = htons(Port);
|
||||||
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
inet_pton(AF_INET, IP.c_str(), &ServerAddr.sin_addr);
|
||||||
status = connect(TCPSocket, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr));
|
status = connect(TCPSocket, (SOCKADDR*)&ServerAddr, sizeof(ServerAddr));
|
||||||
if (status != 0) {
|
if (status != 0) {
|
||||||
UStatus = "Connection Failed!";
|
UStatus = "Connection Failed!";
|
||||||
LOG(ERROR) << "Connect failed! Error code: " << GetSocketApiError();
|
LOG(ERROR) << "Connect failed! Error code: " << GetSocketApiError();
|
||||||
@@ -72,15 +73,17 @@ void Server::StartUDP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::UDPSend(std::string Data) {
|
void Server::UDPSend(std::string Data) {
|
||||||
if (ClientID == -1 || UDPSocket == -1)return;
|
if (ClientID == -1 || UDPSocket == -1)
|
||||||
|
return;
|
||||||
if (Data.length() > 400) {
|
if (Data.length() > 400) {
|
||||||
std::string CMP(Zlib::Comp(Data));
|
std::string CMP(Zlib::Comp(Data));
|
||||||
Data = "ABG:" + CMP;
|
Data = "ABG:" + CMP;
|
||||||
}
|
}
|
||||||
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
std::string Packet = char(ClientID + 1) + std::string(":") + Data;
|
||||||
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr *) UDPSockAddress.get(),
|
int sendOk = sendto(UDPSocket, Packet.c_str(), int(Packet.size()), 0, (sockaddr*)UDPSockAddress.get(),
|
||||||
sizeof(sockaddr_in));
|
sizeof(sockaddr_in));
|
||||||
if (sendOk == SOCKET_ERROR)LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
if (sendOk == SOCKET_ERROR)
|
||||||
|
LOG(ERROR) << "UDP Socket Error Code : " << GetSocketApiError();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::UDPParser(std::string Packet) {
|
void Server::UDPParser(std::string Packet) {
|
||||||
@@ -91,13 +94,15 @@ void Server::UDPParser(std::string Packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::UDPRcv() {
|
void Server::UDPRcv() {
|
||||||
sockaddr_in FromServer{};
|
sockaddr_in FromServer {};
|
||||||
int clientLength = sizeof(FromServer);
|
int clientLength = sizeof(FromServer);
|
||||||
ZeroMemory(&FromServer, clientLength);
|
ZeroMemory(&FromServer, clientLength);
|
||||||
std::string Ret(10240, 0);
|
std::string Ret(10240, 0);
|
||||||
if (UDPSocket == -1)return;
|
if (UDPSocket == -1)
|
||||||
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr *) &FromServer, &clientLength);
|
return;
|
||||||
if (Rcv == SOCKET_ERROR)return;
|
int32_t Rcv = recvfrom(UDPSocket, &Ret[0], 10240, 0, (sockaddr*)&FromServer, &clientLength);
|
||||||
|
if (Rcv == SOCKET_ERROR)
|
||||||
|
return;
|
||||||
UDPParser(Ret.substr(0, Rcv));
|
UDPParser(Ret.substr(0, Rcv));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +114,8 @@ void Server::UDPClient() {
|
|||||||
LauncherInstance->SendIPC("P" + std::to_string(ClientID), false);
|
LauncherInstance->SendIPC("P" + std::to_string(ClientID), false);
|
||||||
TCPSend("H");
|
TCPSend("H");
|
||||||
UDPSend("p");
|
UDPSend("p");
|
||||||
while (!Terminate)UDPRcv();
|
while (!Terminate)
|
||||||
|
UDPRcv();
|
||||||
KillSocket(UDPSocket);
|
KillSocket(UDPSocket);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,16 +126,19 @@ void Server::UDPMain() {
|
|||||||
LOG(INFO) << "Connection terminated";
|
LOG(INFO) << "Connection terminated";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::Connect(const std::string &Data) {
|
void Server::Connect(const std::string& Data) {
|
||||||
ModList.clear();
|
ModList.clear();
|
||||||
Terminate.store(false);
|
Terminate.store(false);
|
||||||
IP = GetAddress(Data.substr(1, Data.find(':') - 1));
|
IP = GetAddress(Data.substr(1, Data.find(':') - 1));
|
||||||
std::string port = Data.substr(Data.find(':') + 1);
|
std::string port = Data.substr(Data.find(':') + 1);
|
||||||
bool ValidPort = std::all_of(port.begin(), port.end(), ::isdigit);
|
bool ValidPort = std::all_of(port.begin(), port.end(), ::isdigit);
|
||||||
if (IP.find('.') == -1 || !ValidPort) {
|
if (IP.find('.') == -1 || !ValidPort) {
|
||||||
if (IP == "DNS") UStatus = "Connection Failed! (DNS Lookup Failed)";
|
if (IP == "DNS")
|
||||||
else if (!ValidPort) UStatus = "Connection Failed! (Invalid Port)";
|
UStatus = "Connection Failed! (DNS Lookup Failed)";
|
||||||
else UStatus = "Connection Failed! (WSA failed to start)";
|
else if (!ValidPort)
|
||||||
|
UStatus = "Connection Failed! (Invalid Port)";
|
||||||
|
else
|
||||||
|
UStatus = "Connection Failed! (WSA failed to start)";
|
||||||
ModList = "-";
|
ModList = "-";
|
||||||
Terminate.store(true);
|
Terminate.store(true);
|
||||||
return;
|
return;
|
||||||
@@ -160,12 +169,12 @@ std::string Server::GetSocketApiError() {
|
|||||||
err = WSAGetLastError();
|
err = WSAGetLastError();
|
||||||
|
|
||||||
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
nullptr,
|
nullptr,
|
||||||
err,
|
err,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
msgbuf,
|
msgbuf,
|
||||||
sizeof(msgbuf),
|
sizeof(msgbuf),
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
if (*msgbuf) {
|
if (*msgbuf) {
|
||||||
return std::to_string(WSAGetLastError()) + " - " + std::string(msgbuf);
|
return std::to_string(WSAGetLastError()) + " - " + std::string(msgbuf);
|
||||||
@@ -175,16 +184,22 @@ std::string Server::GetSocketApiError() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Server::ServerSend(std::string Data, bool Rel) {
|
void Server::ServerSend(std::string Data, bool Rel) {
|
||||||
if (Terminate || Data.empty())return;
|
if (Terminate || Data.empty())
|
||||||
|
return;
|
||||||
char C = 0;
|
char C = 0;
|
||||||
int DLen = int(Data.length());
|
int DLen = int(Data.length());
|
||||||
if (DLen > 3)C = Data.at(0);
|
if (DLen > 3)
|
||||||
|
C = Data.at(0);
|
||||||
bool Ack = C == 'O' || C == 'T';
|
bool Ack = C == 'O' || C == 'T';
|
||||||
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')Rel = true;
|
if (C == 'N' || C == 'W' || C == 'Y' || C == 'V' || C == 'E' || C == 'C')
|
||||||
|
Rel = true;
|
||||||
if (Ack || Rel) {
|
if (Ack || Rel) {
|
||||||
if (Ack || DLen > 1000)SendLarge(Data);
|
if (Ack || DLen > 1000)
|
||||||
else TCPSend(Data);
|
SendLarge(Data);
|
||||||
} else UDPSend(Data);
|
else
|
||||||
|
TCPSend(Data);
|
||||||
|
} else
|
||||||
|
UDPSend(Data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::PingLoop() {
|
void Server::PingLoop() {
|
||||||
@@ -211,7 +226,7 @@ void Server::Close() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Server::getMap() {
|
const std::string& Server::getMap() {
|
||||||
return MStatus;
|
return MStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +234,7 @@ bool Server::Terminated() {
|
|||||||
return Terminate;
|
return Terminate;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Server::getModList() {
|
const std::string& Server::getModList() {
|
||||||
return ModList;
|
return ModList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,24 +242,26 @@ int Server::getPing() const {
|
|||||||
return Ping;
|
return Ping;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &Server::getUIStatus() {
|
const std::string& Server::getUIStatus() {
|
||||||
return UStatus;
|
return UStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Server::GetAddress(const std::string &Data) {
|
std::string Server::GetAddress(const std::string& Data) {
|
||||||
if (Data.find_first_not_of("0123456789.") == -1)return Data;
|
if (Data.find_first_not_of("0123456789.") == -1)
|
||||||
hostent *host;
|
return Data;
|
||||||
|
hostent* host;
|
||||||
host = gethostbyname(Data.c_str());
|
host = gethostbyname(Data.c_str());
|
||||||
if (!host) {
|
if (!host) {
|
||||||
LOG(ERROR) << "DNS lookup failed! on " << Data;
|
LOG(ERROR) << "DNS lookup failed! on " << Data;
|
||||||
return "DNS";
|
return "DNS";
|
||||||
}
|
}
|
||||||
std::string Ret = inet_ntoa(*((struct in_addr *) host->h_addr));
|
std::string Ret = inet_ntoa(*((struct in_addr*)host->h_addr));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Server::KillSocket(uint64_t Dead) {
|
int Server::KillSocket(uint64_t Dead) {
|
||||||
if (Dead == (SOCKET) -1)return 0;
|
if (Dead == (SOCKET)-1)
|
||||||
|
return 0;
|
||||||
shutdown(Dead, SD_BOTH);
|
shutdown(Dead, SD_BOTH);
|
||||||
return closesocket(Dead);
|
return closesocket(Dead);
|
||||||
}
|
}
|
||||||
@@ -253,17 +270,17 @@ void Server::setModLoaded() {
|
|||||||
ModLoaded.store(true);
|
ModLoaded.store(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::UUl(const std::string &R) {
|
void Server::UUl(const std::string& R) {
|
||||||
UStatus = "Disconnected: " + R;
|
UStatus = "Disconnected: " + R;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::CheckBytes(int32_t Bytes) {
|
bool Server::CheckBytes(int32_t Bytes) {
|
||||||
if (Bytes == 0) {
|
if (Bytes == 0) {
|
||||||
//debug("(TCP) Connection closing... CheckBytes(16)");
|
// debug("(TCP) Connection closing... CheckBytes(16)");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
} else if (Bytes < 0) {
|
} else if (Bytes < 0) {
|
||||||
//debug("(TCP CB) recv failed with error: " + GetSocketApiError();
|
// debug("(TCP CB) recv failed with error: " + GetSocketApiError();
|
||||||
KillSocket(TCPSocket);
|
KillSocket(TCPSocket);
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
return false;
|
return false;
|
||||||
@@ -271,7 +288,7 @@ bool Server::CheckBytes(int32_t Bytes) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::TCPSend(const std::string &Data) {
|
void Server::TCPSend(const std::string& Data) {
|
||||||
|
|
||||||
if (TCPSocket == -1) {
|
if (TCPSocket == -1) {
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
@@ -346,6 +363,7 @@ std::string Server::TCPRcv() {
|
|||||||
Ret = Zlib::DeComp(Ret.substr(4));
|
Ret = Zlib::DeComp(Ret.substr(4));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ret[0] == 'E')UUl(Ret.substr(1));
|
if (Ret[0] == 'E')
|
||||||
|
UUl(Ret.substr(1));
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|||||||
+47
-33
@@ -3,12 +3,12 @@
|
|||||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||||
///
|
///
|
||||||
|
|
||||||
#include "Launcher.h"
|
|
||||||
#include "HttpAPI.h"
|
#include "HttpAPI.h"
|
||||||
#include "Logger.h"
|
|
||||||
#include "Json.h"
|
#include "Json.h"
|
||||||
|
#include "Launcher.h"
|
||||||
|
#include "Logger.h"
|
||||||
|
|
||||||
VersionParser::VersionParser(const std::string &from_string) {
|
VersionParser::VersionParser(const std::string& from_string) {
|
||||||
std::string token;
|
std::string token;
|
||||||
std::istringstream tokenStream(from_string);
|
std::istringstream tokenStream(from_string);
|
||||||
while (std::getline(tokenStream, token, '.')) {
|
while (std::getline(tokenStream, token, '.')) {
|
||||||
@@ -17,19 +17,25 @@ VersionParser::VersionParser(const std::string &from_string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::strong_ordering VersionParser::operator<=>(const VersionParser &rhs) const noexcept {
|
std::strong_ordering VersionParser::operator<=>(const VersionParser& rhs) const noexcept {
|
||||||
size_t const fields = std::min(data.size(), rhs.data.size());
|
size_t const fields = std::min(data.size(), rhs.data.size());
|
||||||
for(size_t i = 0; i != fields; ++i) {
|
for (size_t i = 0; i != fields; ++i) {
|
||||||
if(data[i] == rhs.data[i]) continue;
|
if (data[i] == rhs.data[i])
|
||||||
else if(data[i] < rhs.data[i]) return std::strong_ordering::less;
|
continue;
|
||||||
else return std::strong_ordering::greater;
|
else if (data[i] < rhs.data[i])
|
||||||
|
return std::strong_ordering::less;
|
||||||
|
else
|
||||||
|
return std::strong_ordering::greater;
|
||||||
}
|
}
|
||||||
if(data.size() == rhs.data.size()) return std::strong_ordering::equal;
|
if (data.size() == rhs.data.size())
|
||||||
else if(data.size() > rhs.data.size()) return std::strong_ordering::greater;
|
return std::strong_ordering::equal;
|
||||||
else return std::strong_ordering::less;
|
else if (data.size() > rhs.data.size())
|
||||||
|
return std::strong_ordering::greater;
|
||||||
|
else
|
||||||
|
return std::strong_ordering::less;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VersionParser::operator==(const VersionParser &rhs) const noexcept {
|
bool VersionParser::operator==(const VersionParser& rhs) const noexcept {
|
||||||
return std::is_eq(*this <=> rhs);
|
return std::is_eq(*this <=> rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,51 +43,54 @@ void Launcher::UpdateCheck() {
|
|||||||
std::string link;
|
std::string link;
|
||||||
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true");
|
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true");
|
||||||
bool fallback = false;
|
bool fallback = false;
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos){
|
if (HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||||
HTTP = HTTP::Get("https://backup1.beammp.com/builds/launcher?version=true");
|
HTTP = HTTP::Get("https://backup1.beammp.com/builds/launcher?version=true");
|
||||||
fallback = true;
|
fallback = true;
|
||||||
if(HTTP.find_first_of("0123456789") == std::string::npos) {
|
if (HTTP.find_first_of("0123456789") == std::string::npos) {
|
||||||
LOG(FATAL) << "Primary Servers Offline! sorry for the inconvenience!";
|
LOG(FATAL) << "Primary Servers Offline! sorry for the inconvenience!";
|
||||||
throw ShutdownException("Fatal Error");
|
throw ShutdownException("Fatal Error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(fallback){
|
if (fallback) {
|
||||||
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
link = "https://backup1.beammp.com/builds/launcher?download=true";
|
||||||
}else link = "https://beammp.com/builds/launcher?download=true";
|
} else
|
||||||
|
link = "https://beammp.com/builds/launcher?download=true";
|
||||||
|
|
||||||
std::string EP(CurrentPath.string()), Back(CurrentPath.parent_path().string() + "\\BeamMP-Launcher.back");
|
std::string EP(CurrentPath.string()), Back(CurrentPath.parent_path().string() + "\\BeamMP-Launcher.back");
|
||||||
|
|
||||||
if(fs::exists(Back))remove(Back.c_str());
|
if (fs::exists(Back))
|
||||||
|
remove(Back.c_str());
|
||||||
std::string RemoteVer;
|
std::string RemoteVer;
|
||||||
for(char& c : HTTP) {
|
for (char& c : HTTP) {
|
||||||
if(std::isdigit(c) || c == '.') {
|
if (std::isdigit(c) || c == '.') {
|
||||||
RemoteVer += c;
|
RemoteVer += c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(VersionParser(RemoteVer) > VersionParser(FullVersion)){
|
if (VersionParser(RemoteVer) > VersionParser(FullVersion)) {
|
||||||
system("cls");
|
system("cls");
|
||||||
LOG(INFO) << "Update found! Downloading...";
|
LOG(INFO) << "Update found! Downloading...";
|
||||||
if(std::rename(EP.c_str(), Back.c_str())){
|
if (std::rename(EP.c_str(), Back.c_str())) {
|
||||||
LOG(ERROR) << "Failed to create a backup!";
|
LOG(ERROR) << "Failed to create a backup!";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!HTTP::Download(link, EP)){
|
if (!HTTP::Download(link, EP)) {
|
||||||
LOG(ERROR) << "Launcher Update failed! trying again...";
|
LOG(ERROR) << "Launcher Update failed! trying again...";
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||||
|
|
||||||
if(!HTTP::Download(link, EP)){
|
if (!HTTP::Download(link, EP)) {
|
||||||
LOG(ERROR) << "Launcher Update failed!";
|
LOG(ERROR) << "Launcher Update failed!";
|
||||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||||
AdminRelaunch();
|
AdminRelaunch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Relaunch();
|
Relaunch();
|
||||||
}else LOG(INFO) << "Launcher version is up to date";
|
} else
|
||||||
|
LOG(INFO) << "Launcher version is up to date";
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t DirCount(const std::filesystem::path& path){
|
size_t DirCount(const std::filesystem::path& path) {
|
||||||
return (size_t)std::distance(std::filesystem::directory_iterator{path}, std::filesystem::directory_iterator{});
|
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::ResetMods() {
|
void Launcher::ResetMods() {
|
||||||
@@ -99,20 +108,23 @@ void Launcher::ResetMods() {
|
|||||||
|
|
||||||
void Launcher::EnableMP() {
|
void Launcher::EnableMP() {
|
||||||
std::string File(BeamUserPath + "mods\\db.json");
|
std::string File(BeamUserPath + "mods\\db.json");
|
||||||
if(!fs::exists(File))return;
|
if (!fs::exists(File))
|
||||||
|
return;
|
||||||
auto Size = fs::file_size(File);
|
auto Size = fs::file_size(File);
|
||||||
if(Size < 2)return;
|
if (Size < 2)
|
||||||
|
return;
|
||||||
std::ifstream db(File);
|
std::ifstream db(File);
|
||||||
if(db.is_open()) {
|
if (db.is_open()) {
|
||||||
std::string Data(Size, 0);
|
std::string Data(Size, 0);
|
||||||
db.read(&Data[0], std::streamsize(Size));
|
db.read(&Data[0], std::streamsize(Size));
|
||||||
db.close();
|
db.close();
|
||||||
Json d = Json::parse(Data, nullptr, false);
|
Json d = Json::parse(Data, nullptr, false);
|
||||||
if(Data.at(0) != '{' || d.is_discarded())return;
|
if (Data.at(0) != '{' || d.is_discarded())
|
||||||
if(!d["mods"].is_null() && !d["mods"]["multiplayerbeammp"].is_null()){
|
return;
|
||||||
|
if (!d["mods"].is_null() && !d["mods"]["multiplayerbeammp"].is_null()) {
|
||||||
d["mods"]["multiplayerbeammp"]["active"] = true;
|
d["mods"]["multiplayerbeammp"]["active"] = true;
|
||||||
std::ofstream ofs(File);
|
std::ofstream ofs(File);
|
||||||
if(ofs.is_open()){
|
if (ofs.is_open()) {
|
||||||
ofs << std::setw(4) << d;
|
ofs << std::setw(4) << d;
|
||||||
ofs.close();
|
ofs.close();
|
||||||
} else {
|
} else {
|
||||||
@@ -127,5 +139,7 @@ void Launcher::SetupMOD() {
|
|||||||
EnableMP();
|
EnableMP();
|
||||||
LOG(INFO) << "Downloading mod please wait";
|
LOG(INFO) << "Downloading mod please wait";
|
||||||
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
HTTP::Download("https://backend.beammp.com/builds/client?download=true"
|
||||||
"&pk=" + PublicKey + "&branch=" + TargetBuild, MPUserPath + "\\BeamMP.zip");
|
"&pk="
|
||||||
|
+ PublicKey + "&branch=" + TargetBuild,
|
||||||
|
MPUserPath + "\\BeamMP.zip");
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-17
@@ -7,10 +7,10 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include <wx/wxprec.h>
|
#include <wx/wxprec.h>
|
||||||
#ifndef WX_PRECOMP
|
#ifndef WX_PRECOMP
|
||||||
#include <wx/wx.h>
|
#include "gifs.h"
|
||||||
#include <wx/animate.h>
|
#include <wx/animate.h>
|
||||||
#include <wx/mstream.h>
|
#include <wx/mstream.h>
|
||||||
#include "gifs.h"
|
#include <wx/wx.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
class MyApp : public wxApp {
|
class MyApp : public wxApp {
|
||||||
@@ -20,6 +20,7 @@ public:
|
|||||||
class MyFrame : public wxFrame {
|
class MyFrame : public wxFrame {
|
||||||
public:
|
public:
|
||||||
MyFrame();
|
MyFrame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnHello(wxCommandEvent& event);
|
void OnHello(wxCommandEvent& event);
|
||||||
void OnExit(wxCommandEvent& event);
|
void OnExit(wxCommandEvent& event);
|
||||||
@@ -29,28 +30,28 @@ private:
|
|||||||
enum {
|
enum {
|
||||||
ID_Hello = 1
|
ID_Hello = 1
|
||||||
};
|
};
|
||||||
wxSize MyFrame::FixedSize(370,400);
|
wxSize MyFrame::FixedSize(370, 400);
|
||||||
|
|
||||||
bool MyApp::OnInit() {
|
bool MyApp::OnInit() {
|
||||||
auto *frame = new MyFrame();
|
auto* frame = new MyFrame();
|
||||||
frame->Show(true);
|
frame->Show(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
MyFrame::MyFrame()
|
MyFrame::MyFrame()
|
||||||
: wxFrame(nullptr, wxID_ANY, "BeamMP V3.0", wxDefaultPosition, FixedSize) {
|
: wxFrame(nullptr, wxID_ANY, "BeamMP V3.0", wxDefaultPosition, FixedSize) {
|
||||||
//SetMaxSize(FixedSize);
|
// SetMaxSize(FixedSize);
|
||||||
//SetMinSize(FixedSize);
|
// SetMinSize(FixedSize);
|
||||||
Center();
|
Center();
|
||||||
|
|
||||||
//27 35 35
|
// 27 35 35
|
||||||
|
|
||||||
wxColour Colour(27,35,35,1);
|
wxColour Colour(27, 35, 35, 1);
|
||||||
SetBackgroundColour(Colour);
|
SetBackgroundColour(Colour);
|
||||||
|
|
||||||
auto* menuFile = new wxMenu;
|
auto* menuFile = new wxMenu;
|
||||||
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
|
menuFile->Append(ID_Hello, "&Hello...\tCtrl-H",
|
||||||
"Help string shown in status bar for this menu item");
|
"Help string shown in status bar for this menu item");
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(wxID_EXIT);
|
menuFile->Append(wxID_EXIT);
|
||||||
auto* menuHelp = new wxMenu;
|
auto* menuHelp = new wxMenu;
|
||||||
@@ -60,13 +61,12 @@ MyFrame::MyFrame()
|
|||||||
menuBar->SetOwnBackgroundColour(Colour);
|
menuBar->SetOwnBackgroundColour(Colour);
|
||||||
menuBar->Append(menuFile, "&File");
|
menuBar->Append(menuFile, "&File");
|
||||||
menuBar->Append(menuHelp, "&Help");
|
menuBar->Append(menuHelp, "&Help");
|
||||||
//SetMenuBar(menuBar);
|
// SetMenuBar(menuBar);
|
||||||
|
|
||||||
auto* m_ani = new wxAnimationCtrl(this, wxID_ANY);
|
auto* m_ani = new wxAnimationCtrl(this, wxID_ANY);
|
||||||
wxMemoryInputStream stream(gif::Logo, sizeof(gif::Logo));
|
wxMemoryInputStream stream(gif::Logo, sizeof(gif::Logo));
|
||||||
if (m_ani->Load(stream)) m_ani->Play();
|
if (m_ani->Load(stream))
|
||||||
|
m_ani->Play();
|
||||||
|
|
||||||
|
|
||||||
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
|
Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello);
|
||||||
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
|
Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT);
|
||||||
@@ -77,14 +77,13 @@ void MyFrame::OnExit(wxCommandEvent& event) {
|
|||||||
}
|
}
|
||||||
void MyFrame::OnAbout(wxCommandEvent& event) {
|
void MyFrame::OnAbout(wxCommandEvent& event) {
|
||||||
wxMessageBox("This is a wxWidgets Hello World example",
|
wxMessageBox("This is a wxWidgets Hello World example",
|
||||||
"About Hello World", wxOK | wxICON_INFORMATION);
|
"About Hello World", wxOK | wxICON_INFORMATION);
|
||||||
}
|
}
|
||||||
void MyFrame::OnHello(wxCommandEvent& event) {
|
void MyFrame::OnHello(wxCommandEvent& event) {
|
||||||
wxLogMessage("Hello world from wxWidgets!");
|
wxLogMessage("Hello world from wxWidgets!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int GUIEntry(int argc, char* argv[]) {
|
||||||
int GUIEntry (int argc, char *argv[]) {
|
|
||||||
new MyApp();
|
new MyApp();
|
||||||
return wxEntry(argc, argv);
|
return wxEntry(argc, argv);
|
||||||
}
|
}
|
||||||
+1
-2
@@ -5,8 +5,7 @@
|
|||||||
|
|
||||||
#include "gifs.h"
|
#include "gifs.h"
|
||||||
|
|
||||||
const unsigned char gif::Logo[30427] =
|
const unsigned char gif::Logo[30427] = {
|
||||||
{
|
|
||||||
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x80, 0x00, 0x80, 0x00, 0xf6, 0x00,
|
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x80, 0x00, 0x80, 0x00, 0xf6, 0x00,
|
||||||
0x00, 0x0f, 0x37, 0x57, 0x17, 0x27, 0x37, 0x17, 0x27, 0x3f, 0x0f, 0x37,
|
0x00, 0x0f, 0x37, 0x57, 0x17, 0x27, 0x37, 0x17, 0x27, 0x3f, 0x0f, 0x37,
|
||||||
0x5f, 0x00, 0x77, 0xef, 0x07, 0x4f, 0x8f, 0x17, 0x2f, 0x47, 0x0f, 0x3f,
|
0x5f, 0x00, 0x77, 0xef, 0x07, 0x4f, 0x8f, 0x17, 0x2f, 0x47, 0x0f, 0x3f,
|
||||||
|
|||||||
+1
-1
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
class gif{
|
class gif {
|
||||||
public:
|
public:
|
||||||
static const unsigned char Logo[30427];
|
static const unsigned char Logo[30427];
|
||||||
};
|
};
|
||||||
|
|||||||
+3
-3
@@ -10,11 +10,11 @@ int main(int argc, char* argv[]) {
|
|||||||
try {
|
try {
|
||||||
Launcher launcher(argc, argv);
|
Launcher launcher(argc, argv);
|
||||||
launcher.RunDiscordRPC();
|
launcher.RunDiscordRPC();
|
||||||
launcher.LoadConfig(); //check if json (issue)
|
launcher.LoadConfig(); // check if json (issue)
|
||||||
launcher.CheckKey();
|
launcher.CheckKey();
|
||||||
launcher.QueryRegistry();
|
launcher.QueryRegistry();
|
||||||
//UI call
|
// UI call
|
||||||
//launcher.SetupMOD();
|
// launcher.SetupMOD();
|
||||||
launcher.LaunchGame();
|
launcher.LaunchGame();
|
||||||
launcher.WaitForGame();
|
launcher.WaitForGame();
|
||||||
LOG(INFO) << "Launcher shutting down";
|
LOG(INFO) << "Launcher shutting down";
|
||||||
|
|||||||
Reference in New Issue
Block a user