mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-12 18:56:06 +00:00
added checks
This commit is contained in:
@@ -6,10 +6,8 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#define DEFAULT_BUFLEN 64000
|
||||
|
||||
#include <set>
|
||||
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<std::string> 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);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Memory.hpp"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#define CURL_STATICLIB
|
||||
#include "curl/curl.h"
|
||||
#include <iostream>
|
||||
|
||||
#include <string>
|
||||
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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user