Stability improvements, launch behavior tweaks

This commit is contained in:
Anonymous275 2020-06-27 16:58:39 +03:00
parent 85813e4f63
commit 434cf26b7b
6 changed files with 49 additions and 41 deletions

View File

@ -43,7 +43,7 @@ std::string Parse(const std::string& Data){
while(ListOfMods.empty() && !Terminate){
std::this_thread::sleep_for(std::chrono::seconds(1));
}
if(ListOfMods == "-")return "";
if(ListOfMods == "-")return "L";
else return "L"+ListOfMods;
case 'U':
if(SubCode == 'l')return UlStatus;
@ -123,8 +123,6 @@ bool once = false;
WSACleanup();
}
freeaddrinfo(result);
iResult = listen(ListenSocket, SOMAXCONN);
if (iResult == SOCKET_ERROR) {
if (MPDEV)std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl;

View File

@ -54,7 +54,7 @@ void LOOP(){
void AckID(int ID){
for(PacketData* p : BigDataAcks){
if(p->ID == ID){
BigDataAcks.erase(p);
p->Tries = 25;
break;
}
}

View File

@ -15,6 +15,7 @@ void Exit(const std::string& Msg);
namespace fs = std::experimental::filesystem;
extern std::string UlStatus;
extern bool TCPTerminate;
extern std::string ver;
extern bool Terminate;
extern bool Confirm;
extern bool MPDEV;
@ -88,7 +89,8 @@ void WaitForConfirm(){
void SyncResources(SOCKET Sock){
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
CheckForDir();
STCPSend(Sock,"NR" + GlobalInfo.at(0)+":"+GlobalInfo.at(2));
STCPSend(Sock,"NR" + GlobalInfo.at(0) + ":" +GlobalInfo.at(2));
STCPSend(Sock,"VC" + ver);
auto Res = STCPRecv(Sock);
std::string msg = Res.first;
if(msg.size() < 2 || msg.substr(0,2) != "WS"){
@ -100,11 +102,10 @@ void SyncResources(SOCKET Sock){
}
STCPSend(Sock,"SR");
Res = STCPRecv(Sock);
if(strlen(Res.first) == 0){
std::cout << "Didn't Receive any mod from server skipping..." << std::endl;
STCPSend(Sock,"Done");
UlStatus = "UlDone";
if(strlen(Res.first) == 0 || std::string(Res.first) == "-"){
std::cout << "Didn't Receive any mods..." << std::endl;
ListOfMods = "-";
STCPSend(Sock,"Done");
std::cout << "Done!" << std::endl;
return;
}
@ -149,22 +150,24 @@ void SyncResources(SOCKET Sock){
}
CheckForDir();
std::ofstream LFS;
STCPSend(Sock, "f" + *FN);
do {
auto Pair = STCPRecv(Sock);
Data = Pair.first;
if (strcmp(Data, "Cannot Open") == 0 || Terminate)break;
if(!LFS.is_open()){
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
}
LFS.write(Data, Pair.second);
float per = LFS.tellp() / std::stof(*FS) * 100;
std::string Percent = std::to_string(truncf(per * 10) / 10);
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')) + " (" +
Percent.substr(0, Percent.find('.') + 2) + "%)";
} while (LFS.tellp() != std::stoi(*FS));
LFS.close();
STCPSend(Sock, "f" + *FN);
do {
auto Pair = STCPRecv(Sock);
Data = Pair.first;
if (strcmp(Data, "Cannot Open") == 0 || Terminate)break;
if (!LFS.is_open()) {
LFS.open(a.c_str(), std::ios_base::app | std::ios::binary);
}
LFS.write(Data, Pair.second);
float per = LFS.tellp() / std::stof(*FS) * 100;
std::string Percent = std::to_string(truncf(per * 10) / 10);
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
"): " + a.substr(a.find_last_of('/')) + " (" +
Percent.substr(0, Percent.find('.') + 2) + "%)";
} while (LFS.tellp() != std::stoi(*FS) && LFS.tellp() < std::stoi(*FS));
LFS.close();
}while(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));
@ -174,7 +177,6 @@ void SyncResources(SOCKET Sock){
FNames.clear();
FSizes.clear();
a.clear();
UlStatus = "UlDone";
STCPSend(Sock,"Done");
std::cout << "Done!" << std::endl;
}

View File

@ -23,7 +23,7 @@ std::string HTA(const std::string& hex)
for (size_t i = 0; i < hex.length(); i += 2)
{
std::string part = hex.substr(i, 2);
char ch = stoul(part, nullptr, 16);
char ch = char(stoul(part, nullptr, 16));
ascii += ch;
}
return ascii;
@ -231,17 +231,17 @@ char* HashMD5(char* data, DWORD *result)
char *strHash;
strHash = (char*)malloc(500);
memset(strHash, '\0', 500);
if (!CryptAcquireContext(&cryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
if (!CryptAcquireContext(&cryptProv, nullptr, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
{
dwStatus = GetLastError();
printf("CryptAcquireContext failed: %d\n", dwStatus);
printf("CryptAcquireContext failed: %lu\n", dwStatus);
*result = dwStatus;
return nullptr;
}
if (!CryptCreateHash(cryptProv, CALG_MD5, 0, 0, &cryptHash))
{
dwStatus = GetLastError();
printf("CryptCreateHash failed: %d\n", dwStatus);
printf("CryptCreateHash failed: %lu\n", dwStatus);
CryptReleaseContext(cryptProv, 0);
*result = dwStatus;
return nullptr;
@ -249,7 +249,7 @@ char* HashMD5(char* data, DWORD *result)
if (!CryptHashData(cryptHash, (BYTE*)data, strlen(data), 0))
{
dwStatus = GetLastError();
printf("CryptHashData failed: %d\n", dwStatus);
printf("CryptHashData failed: %lu\n", dwStatus);
CryptReleaseContext(cryptProv, 0);
CryptDestroyHash(cryptHash);
*result = dwStatus;
@ -258,7 +258,7 @@ char* HashMD5(char* data, DWORD *result)
if (!CryptGetHashParam(cryptHash, HP_HASHVAL, hash, &cbHash, 0))
{
dwStatus = GetLastError();
printf("CryptGetHashParam failed: %d\n", dwStatus);
printf("CryptGetHashParam failed: %lu\n", dwStatus);
CryptReleaseContext(cryptProv, 0);
CryptDestroyHash(cryptHash);
*result = dwStatus;

View File

@ -85,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) {
Exit("Failed to download! Code : " + std::to_string(res) + "\n Maybe try as admin?");
Exit("Failed to download! Code : " + std::to_string(res));
}
}
if(file.stream)fclose(file.stream);

View File

@ -18,14 +18,13 @@ std::vector<std::string> GetDiscordInfo();
extern std::vector<std::string> SData;
std::vector<std::string> GlobalInfo;
std::string getHardwareID();
std::string ver = "1.41";
int DEFAULT_PORT = 4444;
void Discord_Main();
bool MPDEV = false;
void ProxyStart();
void ExitError();
void Check();
void SystemExec(const std::string& cmd){
system(cmd.c_str());
}
@ -40,10 +39,19 @@ void Exit(const std::string& Msg){
std::cin.ignore();
exit(-1);
}
std::string CheckDir(char*dir){
void ReLaunch(int argc,char*args[]){
std::string Arg;
for(int c = 2; c <= argc; c++){
Arg += " ";
Arg += args[c-1];
}
system("cls");
ShellExecute(nullptr,"runas","BeamMP-Launcher.exe",Arg.c_str(),nullptr,SW_SHOWNORMAL);
exit(1);
}
std::string CheckDir(int argc,char*args[]){
struct stat info{};
std::string DN = "BeamMP-Launcher.exe",CDir = dir,FN = CDir.substr(CDir.find_last_of('\\')+1);
std::string DN = "BeamMP-Launcher.exe",CDir = args[0],FN = CDir.substr(CDir.find_last_of('\\')+1);
if(FN != DN){
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
@ -51,7 +59,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("");
if(!stat("BeamNG\\mods",&info))ReLaunch(argc,args);
SystemExec("mkdir BeamNG\\mods>nul");
if(stat("BeamNG\\settings",&info))SystemExec("mkdir BeamNG\\settings>nul");
return CDir.substr(0,CDir.find_last_of('\\')) + "\\BeamNG";
@ -76,7 +84,7 @@ int main(int argc, char* argv[]){
const unsigned long long NPos = std::string::npos;
struct stat info{};
system("cls");
std::string ver = "1.4", link, HTTP_Result;
std::string link, HTTP_Result;
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + ver).c_str());
std::thread t1(Discord_Main);
t1.detach();
@ -96,7 +104,7 @@ int main(int argc, char* argv[]){
}
}
}else MPDEV = true;
std::string Path = CheckDir(argv[0]);
std::string Path = CheckDir(argc,argv);
std::thread CFU(CheckForUpdates,ver);
CFU.join();