mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-03 00:16:50 +00:00
- add backend proxy
- fix crash bug
This commit is contained in:
parent
dd3d1494c6
commit
b09c9f4c7a
@ -1,17 +1,14 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(BeamMP-Launcher)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
if (WIN32)
|
||||
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
|
||||
STRING(REPLACE "/MD" "/MT /MP" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
|
||||
STRING(REPLACE "/MD" "/MT /MP" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
|
||||
STRING(REPLACE "/MDd" "/MTd /MP" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
|
||||
STRING(REPLACE "/MDd" "/MTd /MP" CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG})
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
find_package(minhook CONFIG REQUIRED)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
find_package(httplib CONFIG REQUIRED)
|
||||
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
|
||||
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
|
||||
include_directories(${VcpkgRoot}/include)
|
||||
@ -19,10 +16,15 @@ if (WIN32)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUNICODE")
|
||||
endif(WIN32)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
||||
|
||||
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
find_package(minhook CONFIG REQUIRED)
|
||||
find_package(nlohmann_json CONFIG REQUIRED)
|
||||
find_package(httplib CONFIG REQUIRED)
|
||||
|
||||
add_executable(${PROJECT_NAME}
|
||||
src/main.cpp
|
||||
src/Launcher.cpp include/Launcher.h include/Memory/Hook.h
|
||||
@ -44,11 +46,13 @@ add_executable(${PROJECT_NAME}
|
||||
|
||||
if (WIN32)
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE discord-rpc)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE discord-rpc easyloggingpp)
|
||||
else ()
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/debug/lib/easyloggingpp.lib)
|
||||
endif()
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE
|
||||
ZLIB::ZLIB OpenSSL::SSL OpenSSL::Crypto ws2_32
|
||||
Dbghelp comsuppw minhook::minhook nlohmann_json httplib::httplib easyloggingpp)
|
||||
Dbghelp comsuppw minhook::minhook nlohmann_json httplib::httplib)
|
||||
else(WIN32) #MINGW
|
||||
add_definitions("-D_WIN32_WINNT=0x0600")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -s --static")
|
||||
@ -57,4 +61,3 @@ else(WIN32) #MINGW
|
||||
endif(WIN32)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "include")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE "include/atomic_queue/include")
|
||||
|
@ -4,6 +4,8 @@
|
||||
///
|
||||
|
||||
#pragma once
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
#include <httplib.h>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
#include "Memory/IPC.h"
|
||||
@ -37,6 +39,7 @@ class Launcher {
|
||||
void UpdateCheck();
|
||||
void WaitForGame();
|
||||
void LaunchGame();
|
||||
void StartProxy();
|
||||
void CheckKey();
|
||||
void SetupMOD();
|
||||
|
||||
@ -86,12 +89,15 @@ class Launcher {
|
||||
std::string UserRole{};
|
||||
std::string PublicKey{};
|
||||
std::thread IPCSystem{};
|
||||
std::thread BackendProxy{};
|
||||
std::thread DiscordRPC{};
|
||||
std::string ConnectURI{};
|
||||
std::string BeamVersion{};
|
||||
std::string DiscordMessage{};
|
||||
Server ServerHandler{this};
|
||||
std::string TargetBuild{"default"};
|
||||
httplib::Server HTTPProxy;
|
||||
int ProxyPort{0};
|
||||
|
||||
static inline std::atomic<bool> Shutdown{false}, Exit{false};
|
||||
std::unique_ptr<IPC> IPCToGame{};
|
||||
|
@ -24,40 +24,46 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
|
||||
Launcher::Launcher(int argc, char* argv[]) :
|
||||
CurrentPath(fs::current_path()),
|
||||
DiscordMessage("Just launched") {
|
||||
Log::Init();
|
||||
Shutdown.store(false);
|
||||
Exit.store(false);
|
||||
Launcher::StaticAbort(this);
|
||||
DiscordTime = std::time(nullptr);
|
||||
WindowsInit();
|
||||
SetUnhandledExceptionFilter(CrashHandler);
|
||||
LOG(INFO) << "Starting Launcher v" << FullVersion;
|
||||
try {
|
||||
Log::Init();
|
||||
Shutdown.store(false);
|
||||
Exit.store(false);
|
||||
Launcher::StaticAbort(this);
|
||||
DiscordTime = std::time(nullptr);
|
||||
WindowsInit();
|
||||
SetUnhandledExceptionFilter(CrashHandler);
|
||||
LOG(INFO) << "Starting Launcher v" << FullVersion;
|
||||
BackendProxy = std::thread(&Launcher::StartProxy, this);
|
||||
|
||||
fs::path config_path(CurrentPath / "Launcher.toml");
|
||||
fs::path config_path(CurrentPath / "Launcher.toml");
|
||||
|
||||
std::string arg, arg2;
|
||||
if(argc > 2) {
|
||||
arg = argv[1];
|
||||
arg2 = argv[2];
|
||||
} else if (argc > 1) {
|
||||
arg = argv[1];
|
||||
}
|
||||
if (arg.starts_with('0')) {
|
||||
LOG(INFO) << "Debug param in effect";
|
||||
DebugMode = true;
|
||||
Memory::DebugMode = true;
|
||||
} else if (arg2.starts_with("beammp://")) {
|
||||
CurrentPath = arg;
|
||||
config_path = CurrentPath / "Launcher.toml";
|
||||
if (arg2.starts_with("beammp://connect/")) {
|
||||
std::string arg, arg2;
|
||||
if(argc > 2) {
|
||||
arg = argv[1];
|
||||
arg2 = argv[2];
|
||||
} else if (argc > 1) {
|
||||
arg = argv[1];
|
||||
}
|
||||
if (arg.starts_with('0')) {
|
||||
LOG(INFO) << "Debug param in effect";
|
||||
DebugMode = true;
|
||||
Memory::DebugMode = true;
|
||||
} else if (arg2.starts_with("beammp://")) {
|
||||
CurrentPath = arg;
|
||||
config_path = CurrentPath / "Launcher.toml";
|
||||
if (arg2.starts_with("beammp://connect/")) {
|
||||
ConnectURI = arg2.substr(17);
|
||||
}
|
||||
} else if (!arg.empty()) {
|
||||
config_path = CurrentPath / arg;
|
||||
}
|
||||
}
|
||||
} else if (!arg.empty()) {
|
||||
config_path = CurrentPath / arg;
|
||||
}
|
||||
|
||||
LoadConfig(config_path);
|
||||
LauncherCache = CurrentPath/"Resources";
|
||||
LoadConfig(config_path);
|
||||
LauncherCache = CurrentPath/"Resources";
|
||||
} catch (const ShutdownException& e) {
|
||||
Abort();
|
||||
throw ShutdownException(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void Launcher::Abort() {
|
||||
@ -69,6 +75,10 @@ void Launcher::Abort() {
|
||||
if (IPCSystem.joinable()) {
|
||||
IPCSystem.join();
|
||||
}
|
||||
HTTPProxy.stop();
|
||||
if (BackendProxy.joinable()) {
|
||||
BackendProxy.join();
|
||||
}
|
||||
if (!MPUserPath.empty()) {
|
||||
ResetMods();
|
||||
}
|
||||
@ -203,6 +213,31 @@ void Launcher::WaitForGame() {
|
||||
GamePID = 0;
|
||||
}
|
||||
|
||||
void Launcher::StartProxy() {
|
||||
HTTPProxy.Get("/:any", [](const httplib::Request& req, httplib::Response& res) {
|
||||
httplib::Client cli("https://backend.beammp.com");
|
||||
if (auto cli_res = cli.Get(req.path); cli_res) {
|
||||
res.set_content(cli_res->body,cli_res->get_header_value("Content-Type"));
|
||||
} else {
|
||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||
}
|
||||
});
|
||||
|
||||
HTTPProxy.Post("/:any", [](const httplib::Request& req, httplib::Response& res) {
|
||||
httplib::Client cli("https://backend.beammp.com");
|
||||
if (auto cli_res = cli.Post(req.path, req.body, req.get_header_value("Content-Type")); cli_res) {
|
||||
res.set_content(cli_res->body,cli_res->get_header_value("Content-Type"));
|
||||
} else {
|
||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||
}
|
||||
res.set_content(req.path, "text/plain");
|
||||
});
|
||||
|
||||
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
|
||||
LOG(INFO) << "HTTP Proxy running on port " << ProxyPort;
|
||||
HTTPProxy.listen_after_bind();
|
||||
}
|
||||
|
||||
void Launcher::ListenIPC() {
|
||||
while (!Shutdown.load()) {
|
||||
IPCFromGame->receive();
|
||||
|
@ -2,9 +2,8 @@
|
||||
/// Created by Anonymous275 on 1/17/22
|
||||
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
|
||||
///
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
|
||||
#include "HttpAPI.h"
|
||||
#include <httplib.h>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
Loading…
x
Reference in New Issue
Block a user