From e72a1b6213790545c3248b3580d0d0cf360c5971 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Mon, 22 Jun 2020 19:00:11 +0300 Subject: [PATCH] added checks --- src/CoreNetwork.cpp | 21 ++++++++++++--------- src/Memory/Reader.cpp | 3 ++- src/Resources.cpp | 5 +++-- src/http.cpp | 5 +++-- src/main.cpp | 1 + 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/CoreNetwork.cpp b/src/CoreNetwork.cpp index 2d4d25f..01bad16 100644 --- a/src/CoreNetwork.cpp +++ b/src/CoreNetwork.cpp @@ -6,10 +6,8 @@ #include #include #include -#define DEFAULT_BUFLEN 64000 - +#include extern int DEFAULT_PORT; - std::string HTTP_REQUEST(const std::string&url,int port); void ProxyThread(const std::string& IP, int port); void Exit(const std::string& Msg); @@ -21,8 +19,10 @@ extern bool TCPTerminate; extern bool MPDEV; extern std::string ListOfMods; bool Confirm = false; +std::set Conf; void StartSync(const std::string &Data){ Terminate = false; + Conf.clear(); std::thread t1(ProxyThread,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1))); //std::thread t1(ProxyThread,"127.0.0.1",30814); t1.detach(); @@ -39,7 +39,7 @@ std::string Parse(const std::string& Data){ case 'C': ListOfMods.clear(); StartSync(Data); - std::cout << "Called Connect" << std::endl; + std::cout << "Connecting to server" << std::endl; while(ListOfMods.empty() && !Terminate){ std::this_thread::sleep_for(std::chrono::seconds(1)); } @@ -54,12 +54,15 @@ std::string Parse(const std::string& Data){ case 'Q': if(SubCode == 'S'){ Terminate = true; - TCPTerminate = true; ////Revisit later when TCP is stable + TCPTerminate = true; } if(SubCode == 'G')exit(2); return ""; - case 'R': //will send mod name useful?? - Confirm = true; + case 'R': //will send mod name + if(Conf.find(Data) == Conf.end()){ + Conf.insert(Data); + Confirm = true; + } return ""; default: return ""; @@ -81,8 +84,8 @@ bool once = false; struct addrinfo hints{}; int iSendResult; - char recvbuf[DEFAULT_BUFLEN]; - int recvbuflen = DEFAULT_BUFLEN; + char recvbuf[64000]; + int recvbuflen = 64000; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); diff --git a/src/Memory/Reader.cpp b/src/Memory/Reader.cpp index 7f81951..5000667 100644 --- a/src/Memory/Reader.cpp +++ b/src/Memory/Reader.cpp @@ -4,6 +4,7 @@ #include "Memory.hpp" #include #include +extern std::string MStatus; extern bool MPDEV; Memory Game; std::string GameVer(HANDLE processHandle, long long Address){ @@ -34,7 +35,7 @@ void SetPID(DWORD PID){ while(true){ Map = LoadedMap(processHandle,Lib1); if(!Map.empty() && Map != "-1" && Map.find("/info.json") != std::string::npos && Map != Temp){ - std::cout << "You just loaded: " << Map << std::endl; + if(MStatus.find(Map) == std::string::npos)exit(5); Temp = Map; } Map.clear(); diff --git a/src/Resources.cpp b/src/Resources.cpp index a4170c3..01a0137 100644 --- a/src/Resources.cpp +++ b/src/Resources.cpp @@ -79,7 +79,7 @@ void CheckForDir(){ } void WaitForConfirm(){ while(!Terminate && !Confirm){ - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } Confirm = false; } @@ -131,6 +131,7 @@ void SyncResources(SOCKET Sock){ if (fs::file_size(a) == std::stoi(*FS)){ UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + "): " + a.substr(a.find_last_of('/')); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing); WaitForConfirm(); continue; @@ -156,13 +157,13 @@ void SyncResources(SOCKET Sock){ LFS.close(); UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + "): " + a.substr(a.find_last_of('/')); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing); WaitForConfirm(); } FNames.clear(); FSizes.clear(); a.clear(); - std::this_thread::sleep_for(std::chrono::seconds(2)); UlStatus = "UlDone"; STCPSend(Sock,"Done"); std::cout << "Done!" << std::endl; diff --git a/src/http.cpp b/src/http.cpp index 038f015..e7cc16a 100644 --- a/src/http.cpp +++ b/src/http.cpp @@ -5,7 +5,8 @@ #define CURL_STATICLIB #include "curl/curl.h" #include - +#include +void Exit(const std::string& Msg); static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { ((std::string*)userp)->append((char*)contents, size * nmemb); @@ -84,7 +85,7 @@ void Download(const std::string& URL,const std::string& Path) res = curl_easy_perform(curl); curl_easy_cleanup(curl); if(CURLE_OK != res) { - fprintf(stderr, "Failed to download! Code : %d\n", res); + Exit("Failed to download! Code : " + std::to_string(res) + "\n Maybe try as admin?"); } } if(file.stream)fclose(file.stream); diff --git a/src/main.cpp b/src/main.cpp index 2afe760..55726a0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,6 +51,7 @@ std::string CheckDir(char*dir){ //SystemExec(R"(powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('%userprofile%\Desktop\BeamMP-Launcher.lnk');$s.TargetPath=')"+AD+"\\"+DN+"';$s.Save()\""); if(stat("BeamNG",&info))SystemExec("mkdir BeamNG>nul"); if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul"); + if(!stat("BeamNG\\mods",&info))Exit(""); SystemExec("mkdir BeamNG\\mods>nul"); if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul"); return CDir.substr(0,CDir.find_last_of('\\')) + "\\BeamNG";