mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-04 00:47:23 +00:00
Stability improvements, launch behavior tweaks
This commit is contained in:
parent
85813e4f63
commit
434cf26b7b
@ -43,7 +43,7 @@ std::string Parse(const std::string& Data){
|
|||||||
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));
|
||||||
}
|
}
|
||||||
if(ListOfMods == "-")return "";
|
if(ListOfMods == "-")return "L";
|
||||||
else return "L"+ListOfMods;
|
else return "L"+ListOfMods;
|
||||||
case 'U':
|
case 'U':
|
||||||
if(SubCode == 'l')return UlStatus;
|
if(SubCode == 'l')return UlStatus;
|
||||||
@ -123,8 +123,6 @@ bool once = false;
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
freeaddrinfo(result);
|
|
||||||
|
|
||||||
iResult = listen(ListenSocket, SOMAXCONN);
|
iResult = listen(ListenSocket, SOMAXCONN);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
if (MPDEV)std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl;
|
if (MPDEV)std::cout << "(Core) listen failed with error: " << WSAGetLastError() << std::endl;
|
||||||
|
@ -54,7 +54,7 @@ void LOOP(){
|
|||||||
void AckID(int ID){
|
void AckID(int ID){
|
||||||
for(PacketData* p : BigDataAcks){
|
for(PacketData* p : BigDataAcks){
|
||||||
if(p->ID == ID){
|
if(p->ID == ID){
|
||||||
BigDataAcks.erase(p);
|
p->Tries = 25;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ void Exit(const std::string& Msg);
|
|||||||
namespace fs = std::experimental::filesystem;
|
namespace fs = std::experimental::filesystem;
|
||||||
extern std::string UlStatus;
|
extern std::string UlStatus;
|
||||||
extern bool TCPTerminate;
|
extern bool TCPTerminate;
|
||||||
|
extern std::string ver;
|
||||||
extern bool Terminate;
|
extern bool Terminate;
|
||||||
extern bool Confirm;
|
extern bool Confirm;
|
||||||
extern bool MPDEV;
|
extern bool MPDEV;
|
||||||
@ -89,6 +90,7 @@ void SyncResources(SOCKET Sock){
|
|||||||
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
|
if(MPDEV)std::cout << "SyncResources Called" << std::endl;
|
||||||
CheckForDir();
|
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);
|
auto Res = STCPRecv(Sock);
|
||||||
std::string msg = Res.first;
|
std::string msg = Res.first;
|
||||||
if(msg.size() < 2 || msg.substr(0,2) != "WS"){
|
if(msg.size() < 2 || msg.substr(0,2) != "WS"){
|
||||||
@ -100,11 +102,10 @@ void SyncResources(SOCKET Sock){
|
|||||||
}
|
}
|
||||||
STCPSend(Sock,"SR");
|
STCPSend(Sock,"SR");
|
||||||
Res = STCPRecv(Sock);
|
Res = STCPRecv(Sock);
|
||||||
if(strlen(Res.first) == 0){
|
if(strlen(Res.first) == 0 || std::string(Res.first) == "-"){
|
||||||
std::cout << "Didn't Receive any mod from server skipping..." << std::endl;
|
std::cout << "Didn't Receive any mods..." << std::endl;
|
||||||
STCPSend(Sock,"Done");
|
|
||||||
UlStatus = "UlDone";
|
|
||||||
ListOfMods = "-";
|
ListOfMods = "-";
|
||||||
|
STCPSend(Sock,"Done");
|
||||||
std::cout << "Done!" << std::endl;
|
std::cout << "Done!" << std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -149,6 +150,7 @@ void SyncResources(SOCKET Sock){
|
|||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
|
do {
|
||||||
STCPSend(Sock, "f" + *FN);
|
STCPSend(Sock, "f" + *FN);
|
||||||
do {
|
do {
|
||||||
auto Pair = STCPRecv(Sock);
|
auto Pair = STCPRecv(Sock);
|
||||||
@ -163,8 +165,9 @@ void SyncResources(SOCKET Sock){
|
|||||||
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
UlStatus = "UlDownloading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||||
"): " + a.substr(a.find_last_of('/')) + " (" +
|
"): " + a.substr(a.find_last_of('/')) + " (" +
|
||||||
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
||||||
} while (LFS.tellp() != std::stoi(*FS));
|
} while (LFS.tellp() != std::stoi(*FS) && LFS.tellp() < std::stoi(*FS));
|
||||||
LFS.close();
|
LFS.close();
|
||||||
|
}while(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));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
@ -174,7 +177,6 @@ void SyncResources(SOCKET Sock){
|
|||||||
FNames.clear();
|
FNames.clear();
|
||||||
FSizes.clear();
|
FSizes.clear();
|
||||||
a.clear();
|
a.clear();
|
||||||
UlStatus = "UlDone";
|
|
||||||
STCPSend(Sock,"Done");
|
STCPSend(Sock,"Done");
|
||||||
std::cout << "Done!" << std::endl;
|
std::cout << "Done!" << std::endl;
|
||||||
}
|
}
|
@ -23,7 +23,7 @@ std::string HTA(const std::string& hex)
|
|||||||
for (size_t i = 0; i < hex.length(); i += 2)
|
for (size_t i = 0; i < hex.length(); i += 2)
|
||||||
{
|
{
|
||||||
std::string part = hex.substr(i, 2);
|
std::string part = hex.substr(i, 2);
|
||||||
char ch = stoul(part, nullptr, 16);
|
char ch = char(stoul(part, nullptr, 16));
|
||||||
ascii += ch;
|
ascii += ch;
|
||||||
}
|
}
|
||||||
return ascii;
|
return ascii;
|
||||||
@ -231,17 +231,17 @@ char* HashMD5(char* data, DWORD *result)
|
|||||||
char *strHash;
|
char *strHash;
|
||||||
strHash = (char*)malloc(500);
|
strHash = (char*)malloc(500);
|
||||||
memset(strHash, '\0', 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();
|
dwStatus = GetLastError();
|
||||||
printf("CryptAcquireContext failed: %d\n", dwStatus);
|
printf("CryptAcquireContext failed: %lu\n", dwStatus);
|
||||||
*result = dwStatus;
|
*result = dwStatus;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (!CryptCreateHash(cryptProv, CALG_MD5, 0, 0, &cryptHash))
|
if (!CryptCreateHash(cryptProv, CALG_MD5, 0, 0, &cryptHash))
|
||||||
{
|
{
|
||||||
dwStatus = GetLastError();
|
dwStatus = GetLastError();
|
||||||
printf("CryptCreateHash failed: %d\n", dwStatus);
|
printf("CryptCreateHash failed: %lu\n", dwStatus);
|
||||||
CryptReleaseContext(cryptProv, 0);
|
CryptReleaseContext(cryptProv, 0);
|
||||||
*result = dwStatus;
|
*result = dwStatus;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -249,7 +249,7 @@ char* HashMD5(char* data, DWORD *result)
|
|||||||
if (!CryptHashData(cryptHash, (BYTE*)data, strlen(data), 0))
|
if (!CryptHashData(cryptHash, (BYTE*)data, strlen(data), 0))
|
||||||
{
|
{
|
||||||
dwStatus = GetLastError();
|
dwStatus = GetLastError();
|
||||||
printf("CryptHashData failed: %d\n", dwStatus);
|
printf("CryptHashData failed: %lu\n", dwStatus);
|
||||||
CryptReleaseContext(cryptProv, 0);
|
CryptReleaseContext(cryptProv, 0);
|
||||||
CryptDestroyHash(cryptHash);
|
CryptDestroyHash(cryptHash);
|
||||||
*result = dwStatus;
|
*result = dwStatus;
|
||||||
@ -258,7 +258,7 @@ char* HashMD5(char* data, DWORD *result)
|
|||||||
if (!CryptGetHashParam(cryptHash, HP_HASHVAL, hash, &cbHash, 0))
|
if (!CryptGetHashParam(cryptHash, HP_HASHVAL, hash, &cbHash, 0))
|
||||||
{
|
{
|
||||||
dwStatus = GetLastError();
|
dwStatus = GetLastError();
|
||||||
printf("CryptGetHashParam failed: %d\n", dwStatus);
|
printf("CryptGetHashParam failed: %lu\n", dwStatus);
|
||||||
CryptReleaseContext(cryptProv, 0);
|
CryptReleaseContext(cryptProv, 0);
|
||||||
CryptDestroyHash(cryptHash);
|
CryptDestroyHash(cryptHash);
|
||||||
*result = dwStatus;
|
*result = dwStatus;
|
||||||
|
@ -85,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) {
|
||||||
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);
|
if(file.stream)fclose(file.stream);
|
||||||
|
24
src/main.cpp
24
src/main.cpp
@ -18,14 +18,13 @@ std::vector<std::string> GetDiscordInfo();
|
|||||||
extern std::vector<std::string> SData;
|
extern std::vector<std::string> SData;
|
||||||
std::vector<std::string> GlobalInfo;
|
std::vector<std::string> GlobalInfo;
|
||||||
std::string getHardwareID();
|
std::string getHardwareID();
|
||||||
|
std::string ver = "1.41";
|
||||||
int DEFAULT_PORT = 4444;
|
int DEFAULT_PORT = 4444;
|
||||||
void Discord_Main();
|
void Discord_Main();
|
||||||
bool MPDEV = false;
|
bool MPDEV = false;
|
||||||
void ProxyStart();
|
void ProxyStart();
|
||||||
void ExitError();
|
void ExitError();
|
||||||
void Check();
|
void Check();
|
||||||
|
|
||||||
|
|
||||||
void SystemExec(const std::string& cmd){
|
void SystemExec(const std::string& cmd){
|
||||||
system(cmd.c_str());
|
system(cmd.c_str());
|
||||||
}
|
}
|
||||||
@ -40,10 +39,19 @@ void Exit(const std::string& Msg){
|
|||||||
std::cin.ignore();
|
std::cin.ignore();
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
void ReLaunch(int argc,char*args[]){
|
||||||
std::string CheckDir(char*dir){
|
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{};
|
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(FN != DN){
|
||||||
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
if(stat(DN.c_str(),&info)==0)remove(DN.c_str());
|
||||||
SystemExec("rename \""+ FN +"\" " + DN + ">nul");
|
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()\"");
|
//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("");
|
if(!stat("BeamNG\\mods",&info))ReLaunch(argc,args);
|
||||||
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";
|
||||||
@ -76,7 +84,7 @@ int main(int argc, char* argv[]){
|
|||||||
const unsigned long long NPos = std::string::npos;
|
const unsigned long long NPos = std::string::npos;
|
||||||
struct stat info{};
|
struct stat info{};
|
||||||
system("cls");
|
system("cls");
|
||||||
std::string ver = "1.4", link, HTTP_Result;
|
std::string link, HTTP_Result;
|
||||||
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + ver).c_str());
|
SetWindowTextA(GetConsoleWindow(),("BeamMP Launcher v" + ver).c_str());
|
||||||
std::thread t1(Discord_Main);
|
std::thread t1(Discord_Main);
|
||||||
t1.detach();
|
t1.detach();
|
||||||
@ -96,7 +104,7 @@ int main(int argc, char* argv[]){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else MPDEV = true;
|
}else MPDEV = true;
|
||||||
std::string Path = CheckDir(argv[0]);
|
std::string Path = CheckDir(argc,argv);
|
||||||
std::thread CFU(CheckForUpdates,ver);
|
std::thread CFU(CheckForUpdates,ver);
|
||||||
CFU.join();
|
CFU.join();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user