added checks

This commit is contained in:
Anonymous275
2020-06-22 19:00:11 +03:00
parent 050db169f5
commit e72a1b6213
5 changed files with 21 additions and 14 deletions
+12 -9
View File
@@ -6,10 +6,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <thread> #include <thread>
#define DEFAULT_BUFLEN 64000 #include <set>
extern int DEFAULT_PORT; extern int DEFAULT_PORT;
std::string HTTP_REQUEST(const std::string&url,int port); std::string HTTP_REQUEST(const std::string&url,int port);
void ProxyThread(const std::string& IP, int port); void ProxyThread(const std::string& IP, int port);
void Exit(const std::string& Msg); void Exit(const std::string& Msg);
@@ -21,8 +19,10 @@ extern bool TCPTerminate;
extern bool MPDEV; extern bool MPDEV;
extern std::string ListOfMods; extern std::string ListOfMods;
bool Confirm = false; bool Confirm = false;
std::set<std::string> Conf;
void StartSync(const std::string &Data){ void StartSync(const std::string &Data){
Terminate = false; 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,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
//std::thread t1(ProxyThread,"127.0.0.1",30814); //std::thread t1(ProxyThread,"127.0.0.1",30814);
t1.detach(); t1.detach();
@@ -39,7 +39,7 @@ std::string Parse(const std::string& Data){
case 'C': case 'C':
ListOfMods.clear(); ListOfMods.clear();
StartSync(Data); StartSync(Data);
std::cout << "Called Connect" << std::endl; std::cout << "Connecting to server" << std::endl;
while(ListOfMods.empty() && !Terminate){ while(ListOfMods.empty() && !Terminate){
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
} }
@@ -54,12 +54,15 @@ std::string Parse(const std::string& Data){
case 'Q': case 'Q':
if(SubCode == 'S'){ if(SubCode == 'S'){
Terminate = true; Terminate = true;
TCPTerminate = true; ////Revisit later when TCP is stable TCPTerminate = true;
} }
if(SubCode == 'G')exit(2); if(SubCode == 'G')exit(2);
return ""; return "";
case 'R': //will send mod name useful?? case 'R': //will send mod name
Confirm = true; if(Conf.find(Data) == Conf.end()){
Conf.insert(Data);
Confirm = true;
}
return ""; return "";
default: default:
return ""; return "";
@@ -81,8 +84,8 @@ bool once = false;
struct addrinfo hints{}; struct addrinfo hints{};
int iSendResult; int iSendResult;
char recvbuf[DEFAULT_BUFLEN]; char recvbuf[64000];
int recvbuflen = DEFAULT_BUFLEN; int recvbuflen = 64000;
// Initialize Winsock // Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
+2 -1
View File
@@ -4,6 +4,7 @@
#include "Memory.hpp" #include "Memory.hpp"
#include <iostream> #include <iostream>
#include <thread> #include <thread>
extern std::string MStatus;
extern bool MPDEV; extern bool MPDEV;
Memory Game; Memory Game;
std::string GameVer(HANDLE processHandle, long long Address){ std::string GameVer(HANDLE processHandle, long long Address){
@@ -34,7 +35,7 @@ void SetPID(DWORD PID){
while(true){ while(true){
Map = LoadedMap(processHandle,Lib1); Map = LoadedMap(processHandle,Lib1);
if(!Map.empty() && Map != "-1" && Map.find("/info.json") != std::string::npos && Map != Temp){ 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; Temp = Map;
} }
Map.clear(); Map.clear();
+3 -2
View File
@@ -79,7 +79,7 @@ void CheckForDir(){
} }
void WaitForConfirm(){ void WaitForConfirm(){
while(!Terminate && !Confirm){ while(!Terminate && !Confirm){
std::this_thread::sleep_for(std::chrono::milliseconds(100)); std::this_thread::sleep_for(std::chrono::milliseconds(10));
} }
Confirm = false; Confirm = false;
} }
@@ -131,6 +131,7 @@ void SyncResources(SOCKET Sock){
if (fs::file_size(a) == std::stoi(*FS)){ if (fs::file_size(a) == std::stoi(*FS)){
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')); "): " + 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); fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
WaitForConfirm(); WaitForConfirm();
continue; continue;
@@ -156,13 +157,13 @@ void SyncResources(SOCKET Sock){
LFS.close(); LFS.close();
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) + UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')); "): " + 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); fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
WaitForConfirm(); WaitForConfirm();
} }
FNames.clear(); FNames.clear();
FSizes.clear(); FSizes.clear();
a.clear(); a.clear();
std::this_thread::sleep_for(std::chrono::seconds(2));
UlStatus = "UlDone"; UlStatus = "UlDone";
STCPSend(Sock,"Done"); STCPSend(Sock,"Done");
std::cout << "Done!" << std::endl; std::cout << "Done!" << std::endl;
+3 -2
View File
@@ -5,7 +5,8 @@
#define CURL_STATICLIB #define CURL_STATICLIB
#include "curl/curl.h" #include "curl/curl.h"
#include <iostream> #include <iostream>
#include <string>
void Exit(const std::string& Msg);
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{ {
((std::string*)userp)->append((char*)contents, size * nmemb); ((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); res = curl_easy_perform(curl);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
if(CURLE_OK != res) { 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); if(file.stream)fclose(file.stream);
+1
View File
@@ -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()\""); //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",&info))SystemExec("mkdir BeamNG>nul");
if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul"); if(!stat("BeamNG\\mods",&info))SystemExec("RD /S /Q BeamNG\\mods>nul");
if(!stat("BeamNG\\mods",&info))Exit("");
SystemExec("mkdir BeamNG\\mods>nul"); SystemExec("mkdir BeamNG\\mods>nul");
if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul"); if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul");
return CDir.substr(0,CDir.find_last_of('\\')) + "\\BeamNG"; return CDir.substr(0,CDir.find_last_of('\\')) + "\\BeamNG";