switched to normal filesystem + crash fixes

This commit is contained in:
Anonymous275 2020-12-26 22:52:01 +02:00
parent 757ac6303b
commit ab2a58bf42
5 changed files with 43 additions and 52 deletions

View File

@ -21,7 +21,7 @@
#include <vector> #include <vector>
#include <future> #include <future>
namespace fs = std::experimental::filesystem; namespace fs = std::filesystem;
std::string ListOfMods; std::string ListOfMods;
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;
@ -126,11 +126,10 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){
} }
char* File = new char[Size]; char* File = new char[Size];
uint64_t Rcv = 0; uint64_t Rcv = 0;
int32_t Temp;
do{ do{
int Len = int(Size-Rcv); int Len = int(Size-Rcv);
if(Len > 1000000)Len = 1000000; if(Len > 1000000)Len = 1000000;
Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL); int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL);
if(Temp < 1){ if(Temp < 1){
info(std::to_string(Temp)); info(std::to_string(Temp));
UUl("Socket Closed Code 1"); UUl("Socket Closed Code 1");
@ -153,6 +152,7 @@ SOCKET 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);
Terminate = true; Terminate = true;
return 0; return 0;
} }
@ -244,6 +244,7 @@ void SyncResources(SOCKET Sock){
} }
if(!FNames.empty())info("Syncing..."); if(!FNames.empty())info("Syncing...");
SOCKET DSock = InitDSock(); SOCKET DSock = InitDSock();
uint64_t ModSize;
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) {
@ -252,7 +253,8 @@ void SyncResources(SOCKET Sock){
Pos++; Pos++;
if (fs::exists(a)) { if (fs::exists(a)) {
if (FS->find_first_not_of("0123456789") != std::string::npos)continue; if (FS->find_first_not_of("0123456789") != std::string::npos)continue;
if (fs::file_size(a) == std::stoi(*FS)){ ModSize = std::stoull(*FS);
if (fs::file_size(a) == ModSize){
UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); 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 {
@ -284,7 +286,7 @@ void SyncResources(SOCKET Sock){
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(Sock,DSock,std::stoull(*FS), Name); Data = MultiDownload(Sock,DSock,ModSize, Name);
if(Terminate)break; if(Terminate)break;
UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName); UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName);
@ -295,7 +297,7 @@ void SyncResources(SOCKET Sock){
LFS.close(); LFS.close();
} }
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate); }while(fs::file_size(a) != ModSize && !Terminate);
if(!Terminate){ if(!Terminate){
if(!fs::exists(GetGamePath() + "mods/multiplayer")){ if(!fs::exists(GetGamePath() + "mods/multiplayer")){
fs::create_directory(GetGamePath() + "mods/multiplayer"); fs::create_directory(GetGamePath() + "mods/multiplayer");

View File

@ -13,6 +13,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <thread> #include <thread>
#include <ShlDisp.h>
#define MAX_KEY_LENGTH 255 #define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383 #define MAX_VALUE_NAME 16383
@ -124,11 +125,10 @@ std::string QueryKey(HKEY hKey,int ID){
delete [] buffer; delete [] buffer;
return ""; return "";
} }
namespace fs = std::experimental::filesystem; namespace fs = std::filesystem;
void FileList(std::vector<std::string>&a,const std::string& Path){ void FileList(std::vector<std::string>&a,const std::string& Path){
for (const auto &entry : fs::directory_iterator(Path)) { for (const auto &entry : fs::directory_iterator(Path)) {
auto pos = entry.path().filename().string().find('.'); if (!entry.is_directory()) {
if (pos != std::string::npos) {
a.emplace_back(entry.path().string()); a.emplace_back(entry.path().string());
}else FileList(a,entry.path().string()); }else FileList(a,entry.path().string());
} }
@ -241,7 +241,9 @@ void LegitimacyCheck(){
std::string K2 = R"(Software\Valve\Steam\Apps\284160)"; std::string K2 = R"(Software\Valve\Steam\Apps\284160)";
std::string K3 = R"(Software\BeamNG\BeamNG.drive)"; std::string K3 = R"(Software\BeamNG\BeamNG.drive)";
HKEY hKey; HKEY hKey;
LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey); LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey);
if(dwRegOPenKey == ERROR_SUCCESS) { if(dwRegOPenKey == ERROR_SUCCESS) {
Result = QueryKey(hKey, 1); Result = QueryKey(hKey, 1);
if(Result.empty())Exit(1); if(Result.empty())Exit(1);
@ -249,10 +251,12 @@ void LegitimacyCheck(){
if(!Find("284160.json", Result))Exit(2); if(!Find("284160.json", Result))Exit(2);
if(FindHack(Result))SteamExit(1); if(FindHack(Result))SteamExit(1);
}else Exit(3); }else Exit(3);
T = Result; T = Result;
Result.clear(); Result.clear();
TraceBack++; TraceBack++;
}else Exit(4); }else Exit(4);
K1.clear(); K1.clear();
RegCloseKey(hKey); RegCloseKey(hKey);
dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey); dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey);

View File

@ -40,6 +40,11 @@ std::string GetFail(const std::string& R){
} }
std::string Login(const std::string& fields){ std::string Login(const std::string& fields){
if(fields == "LO"){
LoginAuth = false;
UpdateKey(nullptr);
return "";
}
info("Attempting to authenticate..."); info("Attempting to authenticate...");
std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields); std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields);
json::Document d; json::Document d;
@ -47,6 +52,7 @@ std::string Login(const std::string& fields){
if(Buffer == "-1"){ if(Buffer == "-1"){
return GetFail("Failed to communicate with the auth system!"); return GetFail("Failed to communicate with the auth system!");
} }
if (Buffer.find('{') == -1 || d.HasParseError()) { if (Buffer.find('{') == -1 || d.HasParseError()) {
return GetFail("Invalid answer from authentication servers, please try again later!"); return GetFail("Invalid answer from authentication servers, please try again later!");
} }

View File

@ -19,7 +19,7 @@
extern int TraceBack; extern int TraceBack;
bool Dev = false; bool Dev = false;
namespace fs = std::experimental::filesystem; namespace fs = std::filesystem;
std::string GetEN(){ std::string GetEN(){
return "BeamMP-Launcher.exe"; return "BeamMP-Launcher.exe";
} }
@ -27,7 +27,7 @@ std::string GetVer(){
return "1.80"; return "1.80";
} }
std::string GetPatch(){ std::string GetPatch(){
return ".2"; return ".3";
} }
void ReLaunch(int argc,char*args[]){ void ReLaunch(int argc,char*args[]){
std::string Arg; std::string Arg;
@ -182,7 +182,7 @@ void InitLauncher(int argc, char* argv[]) {
CheckName(argc, argv); CheckName(argc, argv);
CheckLocalKey(); //will replace RequestRole CheckLocalKey(); //will replace RequestRole
Discord_Main(); Discord_Main();
Dev = true; //Dev = true;
//RequestRole(); //RequestRole();
CustomPort(argc, argv); CustomPort(argc, argv);
CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch());
@ -190,47 +190,25 @@ void InitLauncher(int argc, char* argv[]) {
void PreGame(int argc, char* argv[],const std::string& GamePath){ void PreGame(int argc, char* argv[],const std::string& GamePath){
info("Game Version : " + CheckVer(GamePath)); info("Game Version : " + CheckVer(GamePath));
std::string DUI = R"(BeamNG\settings\uiapps-layouts.json)";
std::string GS = R"(BeamNG\settings\game-settings.ini)";
std::string link = "https://beammp.com/client-ui-data";
bool fallback = false;
int i;
if(!fs::exists(DUI)){
info("Downloading default ui data...");
i = Download(link,DUI,true);
if(i != -1){
fallback = true;
remove(DUI.c_str());
link = "https://backup1.beammp.com/client-ui-data";
i = Download(link,DUI,true);
if(i != -1) {
error("Failed to download code : " + std::to_string(i));
std::this_thread::sleep_for(std::chrono::seconds(3));
ReLaunch(argc, argv);
}
}
info("Download Complete!");
}
if(!fs::exists(GS)) {
info("Downloading default game settings...");
if(fallback)link = "https://backup1.beammp.com/client-settings-data";
else link = "https://beammp.com/client-settings-data";
Download(link, GS,true);
info("Download Complete!");
}
if(!Dev) { if(!Dev) {
info("Downloading mod..."); info("Downloading mod...");
if(fallback)link = "https://backup1.beammp.com/builds/client"; //if(fallback)link = "https://backup1.beammp.com/builds/client";
else link ="https://beammp.com/builds/client"; std::string link = "https://beammp.com/builds/client";
try {
if (!fs::exists(GetGamePath() + "mods")) { if (!fs::exists(GetGamePath() + "mods")) {
fs::create_directory(GetGamePath() + "mods"); fs::create_directory(GetGamePath() + "mods");
} }
if (!fs::exists(GetGamePath() + "mods/multiplayer")) { if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
fs::create_directory(GetGamePath() + "mods/multiplayer"); fs::create_directory(GetGamePath() + "mods/multiplayer");
} }
Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true); }catch(std::exception&e){
fatal(e.what());
}
Download(link, GetGamePath() + R"(mods/multiplayer/BeamMP.zip)", true);
info("Download Complete!"); info("Download Complete!");
} }
/*debug("Name : " + GetDName()); /*debug("Name : " + GetDName());
debug("Discriminator : " + GetDTag()); debug("Discriminator : " + GetDTag());
debug("Unique ID : " + GetDID());*/ debug("Unique ID : " + GetDID());*/

View File

@ -8,13 +8,14 @@
#include "Network/network.h" #include "Network/network.h"
#include "Security/Init.h" #include "Security/Init.h"
#include "Startup.h" #include "Startup.h"
#include <thread>
#include <iostream> #include <iostream>
#include <thread>
[[noreturn]] void flush(){ [[noreturn]] void flush(){
while(true){ while(true){
std::cout.flush(); std::cout.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(500)); std::this_thread::sleep_for(std::chrono::milliseconds(100));
} }
} }
@ -24,7 +25,7 @@ int main(int argc, char* argv[]) {
th.detach(); th.detach();
#endif #endif
InitLauncher(argc,argv); InitLauncher(argc,argv);
CheckDir(argc,argv); //CheckDir(argc,argv);
LegitimacyCheck(); LegitimacyCheck();
PreGame(argc,argv,GetGameDir()); PreGame(argc,argv,GetGameDir());
InitGame(GetGameDir()); InitGame(GetGameDir());