From 17116622414396af013fe8ac8a69134de5267bab Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Fri, 3 Jul 2020 00:58:46 +0300 Subject: [PATCH] tweaked connection logic | launcher now retries to auto update --- src/Resources.cpp | 9 ++++++--- src/UpdateCheck.cpp | 14 +++++++++++--- src/main.cpp | 3 ++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Resources.cpp b/src/Resources.cpp index d3e7c33..911b73a 100644 --- a/src/Resources.cpp +++ b/src/Resources.cpp @@ -87,7 +87,7 @@ void WaitForConfirm(){ void SyncResources(SOCKET Sock){ std::cout << "Checking Resources..." << std::endl; - std::string HandShakeVer = "1.43"; + std::string HandShakeVer = "1.46"; CheckForDir(); STCPSend(Sock,"NR" + GlobalInfo.at(0) + ":" +GlobalInfo.at(2)); STCPSend(Sock,"VC" + HandShakeVer); @@ -96,7 +96,7 @@ void SyncResources(SOCKET Sock){ if(msg.size() < 2 || msg.substr(0,2) != "WS"){ Terminate = true; TCPTerminate = true; - UlStatus = "UlDisconnected: outdated server/client"; + UlStatus = "UlDisconnected: full or outdated server"; std::cout << "Terminated!" << std::endl; return; } @@ -158,7 +158,10 @@ void SyncResources(SOCKET Sock){ auto Pair = STCPRecv(Sock); char* Data = Pair.first; size_t BytesRcv = Pair.second; - if (strcmp(Data, "Cannot Open") == 0 || Terminate)break; + if (strcmp(Data, "Cannot Open") == 0 || Terminate){ + delete[] Data; + break; + } memcpy_s(File+Recv,BytesRcv,Data,BytesRcv); Recv += BytesRcv; float per = float(Recv)/std::stof(*FS) * 100; diff --git a/src/UpdateCheck.cpp b/src/UpdateCheck.cpp index ffc4640..374d6c2 100644 --- a/src/UpdateCheck.cpp +++ b/src/UpdateCheck.cpp @@ -3,7 +3,7 @@ /// #include - +#include int Download(const std::string& URL,const std::string& path); std::string HTTP_REQUEST(const std::string&url,int port); std::string HTA(const std::string& hex); @@ -21,12 +21,20 @@ void CheckForUpdates(int argc,char*args[],const std::string& CV){ struct stat buffer{}; if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back"); if(HTTP > CV){ - ReLaunch(argc,args); system("cls"); std::cout << "Update found!" << std::endl; std::cout << "Updating..." << std::endl; SystemExec("rename BeamMP-Launcher.exe BeamMP-Launcher.back>nul"); - Download(link, "BeamMP-Launcher.exe"); + if(int i = Download(link, "BeamMP-Launcher.exe") != -1){ + std::cout << "Launcher Update failed! trying again... code : " << i << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(2)); + if(int i2 = Download(link, "BeamMP-Launcher.exe") != -1){ + std::cout << "Launcher Update failed! code : " << i2 << std::endl; + std::this_thread::sleep_for(std::chrono::seconds(5)); + ReLaunch(argc,args); + } + + } WinExec("BeamMP-Launcher.exe"); exit(1); }else{ diff --git a/src/main.cpp b/src/main.cpp index 144efce..476736d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ std::vector GetDiscordInfo(); extern std::vector SData; std::vector GlobalInfo; std::string getHardwareID(); -char* ver = (char*)"1.45"; +char* ver = (char*)"1.46"; int DEFAULT_PORT = 4444; void Discord_Main(); bool Dev = false; @@ -136,6 +136,7 @@ int main(int argc, char* argv[]){ link = "https://beamng-mp.com/client-ui-data"; std::cout << "Downloading default config..." << std::endl; if(int i = Download(link,DUI) != -1){ + remove(DUI.c_str()); std::cout << "Error! Failed to download code : " << i << std::endl; std::this_thread::sleep_for(std::chrono::seconds(3)); ReLaunch(argc,argv);