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

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

View File

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

View File

@@ -39,13 +39,17 @@ std::string HTTP::Get(const std::string &IP) {
evpp::EventLoopThread t;
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);
while (!responded) {
usleep(1);
}
pool->Clear();
pool.reset();
t.Stop(true);
return Res_;
}
@@ -58,7 +62,9 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
evpp::EventLoopThread t;
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->Execute(Response);
@@ -66,6 +72,8 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
usleep(1);
}
pool->Clear();
pool.reset();
t.Stop(true);
if(Res_.empty())return "-1";
else return Res_;
@@ -92,7 +100,9 @@ bool HTTP::Download(const std::string &IP, const std::string &Path) {
Res_.clear();
evpp::EventLoopThread t;
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->Execute(Response);
@@ -100,6 +110,8 @@ bool HTTP::Download(const std::string &IP, const std::string &Path) {
usleep(1);
}
pool->Clear();
pool.reset();
t.Stop(true);
if(Res_.empty())return false;

View File

@@ -47,7 +47,7 @@ std::string Login(const std::string& fields){
return "";
}
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;
d.Parse(Buffer.c_str());
if(Buffer == "-1"){
@@ -88,7 +88,7 @@ void CheckLocalKey(){
Key.read(&Buffer[0], Size);
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;
d.Parse(Buffer.c_str());

View File

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