Possible fix for new backend linix ~Anonymous275

This commit is contained in:
Starystars67 2021-03-29 19:00:23 +01:00
parent fff747afca
commit ae6725ece3
6 changed files with 45 additions and 25 deletions

View File

@ -1,35 +1,41 @@
cmake_minimum_required(VERSION 3.10) cmake_minimum_required(VERSION 3.10)
project(Launcher) project(Launcher)
if (WIN32)
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
endif(WIN32)
add_subdirectory("evpp")
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h") file(GLOB source_files "src/*.cpp" "src/*/*.cpp" "src/*/*.hpp" "include/*.h" "include/*/*.h" "include/*/*/*.h")
#file(GLOB evpp_src evpp/evpp/*.cc evpp/evpp/*/*.cc evpp/evpp/*.h evpp/evpp/*/*.h)
add_executable(${PROJECT_NAME} ${source_files}) add_executable(${PROJECT_NAME} ${source_files})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher") set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "BeamMP-Launcher")
target_include_directories(${PROJECT_NAME} PUBLIC include evpp)
add_definitions("-DEVPP_HTTP_CLIENT_SUPPORTS_SSL") add_definitions("-DEVPP_HTTP_CLIENT_SUPPORTS_SSL")
add_subdirectory("evpp")
if (WIN32) if (WIN32)
find_package(glog CONFIG REQUIRED) find_package(glog CONFIG REQUIRED)
find_package(Libevent CONFIG REQUIRED) find_package(Libevent CONFIG REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(CURL REQUIRED)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
message(STATUS "MSVC -> forcing use of statically-linked runtime.")
STRING(REPLACE "/MD" "/MT" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
#-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static #-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-windows-static
set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}) set(VcpkgRoot ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET})
include_directories(${VcpkgRoot}/include) include_directories(${VcpkgRoot}/include)
link_directories(${VcpkgRoot}/lib) link_directories(${VcpkgRoot}/lib)
target_link_libraries(${PROJECT_NAME} PRIVATE discord-rpc evpp_static target_link_libraries(${PROJECT_NAME} PRIVATE ${VcpkgRoot}/debug/lib/discord-rpc.lib evpp_static
libevent::core libevent::extra glog::glog ZLIB::ZLIB ${VcpkgRoot}/debug/lib/event.lib libevent::core libevent::extra glog::glog ZLIB::ZLIB
OpenSSL::SSL OpenSSL::Crypto libevent::openssl) OpenSSL::SSL OpenSSL::Crypto libevent::openssl ws2_32)
else(WIN32) #MINGW else(WIN32) #MINGW
add_definitions("-D_WIN32_WINNT=0x0600") add_definitions("-D_WIN32_WINNT=0x0600")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s -static-libgcc -static-libstdc++ --static") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s -static-libgcc -static-libstdc++ --static")
target_link_libraries(${PROJECT_NAME} discord-rpc evpp_static glog event pthread ssl crypto event_openssl ws2_32 ssp dbghelp iphlpapi z) target_link_libraries(${PROJECT_NAME} discord-rpc evpp_static glog event pthread ssl crypto event_openssl ws2_32 ssp dbghelp iphlpapi z)
endif(WIN32) endif(WIN32)
target_include_directories(${PROJECT_NAME} PUBLIC include evpp)

View File

@ -58,7 +58,7 @@ void Parse(std::string Data,SOCKET CSocket){
NetReset(); NetReset();
Terminate = true; Terminate = true;
TCPTerminate = true; TCPTerminate = true;
Data = Code + HTTP::Get("https://beammp.com/servers-info"); Data = Code + HTTP::Post("backend.beammp.com/servers", "");
break; break;
case 'C': case 'C':
ListOfMods.clear(); ListOfMods.clear();

View File

@ -7,7 +7,7 @@
/// ///
#include <string> #include <string>
#include <winsock.h> #include <winsock2.h>
#include "Logger.h" #include "Logger.h"
std::string GetAddr(const std::string&IP){ std::string GetAddr(const std::string&IP){

View File

@ -39,13 +39,17 @@ std::string HTTP::Get(const std::string &IP) {
evpp::EventLoopThread t; evpp::EventLoopThread t;
t.Start(true); t.Start(true);
auto* r = new evpp::httpc::GetRequest(t.loop(), IP, evpp::Duration(10.0)); auto pos = IP.find('/');
std::shared_ptr<evpp::httpc::ConnPool> pool = std::make_shared<evpp::httpc::ConnPool>("www." + IP.substr(0,pos), 443, true, evpp::Duration(10.0));
auto* r = new evpp::httpc::Request(pool.get(), t.loop(), IP.substr(pos), "");
r->Execute(Response); r->Execute(Response);
while (!responded) { while (!responded) {
usleep(1); usleep(1);
} }
pool->Clear();
pool.reset();
t.Stop(true); t.Stop(true);
return Res_; return Res_;
} }
@ -58,7 +62,9 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
evpp::EventLoopThread t; evpp::EventLoopThread t;
t.Start(true); t.Start(true);
auto* r = new evpp::httpc::PostRequest(t.loop(), IP, Fields, evpp::Duration(10.0)); auto pos = IP.find('/');
std::shared_ptr<evpp::httpc::ConnPool> pool = std::make_shared<evpp::httpc::ConnPool>( IP.substr(0,pos), 443, true, evpp::Duration(10.0));
auto* r = new evpp::httpc::Request(pool.get(), t.loop(), IP.substr(pos), Fields);
r->AddHeader("Content-Type","application/json"); r->AddHeader("Content-Type","application/json");
r->Execute(Response); r->Execute(Response);
@ -66,6 +72,8 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
usleep(1); usleep(1);
} }
pool->Clear();
pool.reset();
t.Stop(true); t.Stop(true);
if(Res_.empty())return "-1"; if(Res_.empty())return "-1";
else return Res_; else return Res_;
@ -92,7 +100,9 @@ bool HTTP::Download(const std::string &IP, const std::string &Path) {
Res_.clear(); Res_.clear();
evpp::EventLoopThread t; evpp::EventLoopThread t;
t.Start(true); t.Start(true);
auto* r = new evpp::httpc::GetRequest(t.loop(), IP, evpp::Duration(10.0)); auto pos = IP.find('/');
std::shared_ptr<evpp::httpc::ConnPool> pool = std::make_shared<evpp::httpc::ConnPool>("www." + IP.substr(0,pos), 443, true, evpp::Duration(10.0));
auto* r = new evpp::httpc::Request(pool.get(), t.loop(), IP.substr(pos), "");
r->set_progress_callback(ProgressBar); r->set_progress_callback(ProgressBar);
r->Execute(Response); r->Execute(Response);
@ -100,6 +110,8 @@ bool HTTP::Download(const std::string &IP, const std::string &Path) {
usleep(1); usleep(1);
} }
pool->Clear();
pool.reset();
t.Stop(true); t.Stop(true);
if(Res_.empty())return false; if(Res_.empty())return false;

View File

@ -47,7 +47,7 @@ std::string Login(const std::string& fields){
return ""; return "";
} }
info("Attempting to authenticate..."); info("Attempting to authenticate...");
std::string Buffer = HTTP::Post("https://auth.beammp.com/userlogin", fields); std::string Buffer = HTTP::Post("auth.beammp.com/userlogin", fields);
json::Document d; json::Document d;
d.Parse(Buffer.c_str()); d.Parse(Buffer.c_str());
if(Buffer == "-1"){ if(Buffer == "-1"){
@ -88,7 +88,7 @@ void CheckLocalKey(){
Key.read(&Buffer[0], Size); Key.read(&Buffer[0], Size);
Key.close(); Key.close();
Buffer = HTTP::Post("https://auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}"); Buffer = HTTP::Post("auth.beammp.com/userlogin", R"({"pk":")" + Buffer + "\"}");
json::Document d; json::Document d;
d.Parse(Buffer.c_str()); d.Parse(Buffer.c_str());

View File

@ -10,8 +10,10 @@
#include "Network/network.h" #include "Network/network.h"
#include "Security/Init.h" #include "Security/Init.h"
#include <filesystem> #include <filesystem>
#include "Startup.h" #ifndef WIN32
#include <windows.h> #include <windows.h>
#endif
#include "Startup.h"
#include "Logger.h" #include "Logger.h"
#include <thread> #include <thread>
#include "http.h" #include "http.h"
@ -71,18 +73,18 @@ void CheckName(int argc,char* args[]){
void CheckForUpdates(int argc,char*args[],const std::string& CV){ void CheckForUpdates(int argc,char*args[],const std::string& CV){
std::string link; std::string link;
std::string HTTP = HTTP::Get("https://beammp.com/builds/launcher?version=true"); std::string HTTP = HTTP::Get("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("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) {
fatal("Primary Servers Offline! sorry for the inconvenience!"); fatal("Primary Servers Offline! sorry for the inconvenience!");
} }
} }
if(fallback){ if(fallback){
link = "www.backup1.beammp.com/builds/launcher?download=true"; link = "backup1.beammp.com/builds/launcher?download=true";
}else link = "www.beammp.com/builds/launcher?download=true"; }else link = "beammp.com/builds/launcher?download=true";
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back"); std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
@ -180,7 +182,7 @@ void PreGame(const std::string& GamePath){
"&pk=" + PublicKey + "&pk=" + PublicKey +
"&branch=" + Branch, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);*/ "&branch=" + Branch, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true);*/
HTTP::Download("https://beammp.com/builds/client", GetGamePath() + R"(mods\multiplayer\BeamMP.zip)"); HTTP::Download("beammp.com/builds/client", GetGamePath() + R"(mods\multiplayer\BeamMP.zip)");
info("Download Complete!"); info("Download Complete!");
} }