mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-18 14:40:56 +00:00
major bug/crash fixing ready for release
This commit is contained in:
+15
-10
@@ -19,6 +19,7 @@ extern bool TCPTerminate;
|
|||||||
extern bool Dev;
|
extern bool Dev;
|
||||||
extern std::string ListOfMods;
|
extern std::string ListOfMods;
|
||||||
bool Confirm = false;
|
bool Confirm = false;
|
||||||
|
void Reset();
|
||||||
std::set<std::string> Conf;
|
std::set<std::string> Conf;
|
||||||
void StartSync(const std::string &Data){
|
void StartSync(const std::string &Data){
|
||||||
UlStatus = "UlLoading...";
|
UlStatus = "UlLoading...";
|
||||||
@@ -36,6 +37,9 @@ std::string Parse(const std::string& Data){
|
|||||||
case 'A':
|
case 'A':
|
||||||
return Data.substr(0,1);
|
return Data.substr(0,1);
|
||||||
case 'B':
|
case 'B':
|
||||||
|
Reset();
|
||||||
|
Terminate = true;
|
||||||
|
TCPTerminate = true;
|
||||||
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
||||||
case 'C':
|
case 'C':
|
||||||
ListOfMods.clear();
|
ListOfMods.clear();
|
||||||
@@ -54,6 +58,7 @@ std::string Parse(const std::string& Data){
|
|||||||
return MStatus;
|
return MStatus;
|
||||||
case 'Q':
|
case 'Q':
|
||||||
if(SubCode == 'S'){
|
if(SubCode == 'S'){
|
||||||
|
Reset();
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
TCPTerminate = true;
|
TCPTerminate = true;
|
||||||
}
|
}
|
||||||
@@ -113,16 +118,16 @@ bool once = false;
|
|||||||
if (Dev)std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl;
|
if (Dev)std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
WSACleanup();
|
WSACleanup();
|
||||||
|
}else{
|
||||||
|
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
|
||||||
|
if (iResult == SOCKET_ERROR) {
|
||||||
|
if (Dev)Exit("(Core) bind failed with error: " + std::to_string(WSAGetLastError()));
|
||||||
|
freeaddrinfo(result);
|
||||||
|
closesocket(ListenSocket);
|
||||||
|
WSACleanup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the TCP listening socket
|
|
||||||
iResult = bind(ListenSocket, result->ai_addr, (int) result->ai_addrlen);
|
|
||||||
if (iResult == SOCKET_ERROR) {
|
|
||||||
if (Dev)Exit("(Core) bind failed with error: " + std::to_string(WSAGetLastError()));
|
|
||||||
freeaddrinfo(result);
|
|
||||||
closesocket(ListenSocket);
|
|
||||||
WSACleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
iResult = listen(ListenSocket, SOMAXCONN);
|
iResult = listen(ListenSocket, SOMAXCONN);
|
||||||
if (iResult == SOCKET_ERROR) {
|
if (iResult == SOCKET_ERROR) {
|
||||||
@@ -148,7 +153,7 @@ bool once = false;
|
|||||||
if (iResult > 0) {
|
if (iResult > 0) {
|
||||||
std::string data = recvbuf;
|
std::string data = recvbuf;
|
||||||
data.resize(iResult);
|
data.resize(iResult);
|
||||||
Response = Parse(data) + "\n";
|
Response = Parse(data);
|
||||||
} else if (iResult == 0) {
|
} else if (iResult == 0) {
|
||||||
if (Dev)std::cout << "(Core) Connection closing...\n";
|
if (Dev)std::cout << "(Core) Connection closing...\n";
|
||||||
} else {
|
} else {
|
||||||
@@ -157,7 +162,7 @@ bool once = false;
|
|||||||
WSACleanup();
|
WSACleanup();
|
||||||
}
|
}
|
||||||
if (!Response.empty()) {
|
if (!Response.empty()) {
|
||||||
iSendResult = send(ClientSocket, Response.c_str(), Response.length(), 0);
|
iSendResult = send(ClientSocket, (Response+"\n").c_str(), int(Response.length())+1, 0);
|
||||||
if (iSendResult == SOCKET_ERROR) {
|
if (iSendResult == SOCKET_ERROR) {
|
||||||
if (Dev)std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
if (Dev)std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
||||||
closesocket(ClientSocket);
|
closesocket(ClientSocket);
|
||||||
|
|||||||
@@ -97,13 +97,15 @@ void NetMain(const std::string& IP, int Port){
|
|||||||
}
|
}
|
||||||
extern SOCKET UDPSock;
|
extern SOCKET UDPSock;
|
||||||
extern SOCKET TCPSock;
|
extern SOCKET TCPSock;
|
||||||
void Reset() {
|
void Reset(){
|
||||||
TCPTerminate = false;
|
TCPTerminate = false;
|
||||||
gameConected = false;
|
gameConected = false;
|
||||||
Terminate = false;
|
Terminate = false;
|
||||||
UlStatus = "Ulstart";
|
UlStatus = "Ulstart";
|
||||||
MStatus = " ";
|
MStatus = " ";
|
||||||
|
if(UDPSock != SOCKET_ERROR)closesocket(UDPSock);
|
||||||
UDPSock = -1;
|
UDPSock = -1;
|
||||||
|
if(TCPSock != SOCKET_ERROR)closesocket(TCPSock);
|
||||||
TCPSock = -1;
|
TCPSock = -1;
|
||||||
}
|
}
|
||||||
std::string Compress(const std::string&Data);
|
std::string Compress(const std::string&Data);
|
||||||
|
|||||||
+10
-5
@@ -148,7 +148,6 @@ void SyncResources(SOCKET Sock){
|
|||||||
}else remove(a.c_str());
|
}else remove(a.c_str());
|
||||||
}
|
}
|
||||||
CheckForDir();
|
CheckForDir();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
STCPSend(Sock, "f" + *FN);
|
STCPSend(Sock, "f" + *FN);
|
||||||
int Recv = 0,Size = std::stoi(*FS);
|
int Recv = 0,Size = std::stoi(*FS);
|
||||||
@@ -159,7 +158,7 @@ void SyncResources(SOCKET Sock){
|
|||||||
char* Data = Pair.first;
|
char* Data = Pair.first;
|
||||||
size_t BytesRcv = Pair.second;
|
size_t BytesRcv = Pair.second;
|
||||||
if (strcmp(Data, "Cannot Open") == 0 || Terminate){
|
if (strcmp(Data, "Cannot Open") == 0 || Terminate){
|
||||||
delete[] Data;
|
if(BytesRcv != 0)delete[] Data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
memcpy_s(File+Recv,BytesRcv,Data,BytesRcv);
|
memcpy_s(File+Recv,BytesRcv,Data,BytesRcv);
|
||||||
@@ -171,6 +170,7 @@ void SyncResources(SOCKET Sock){
|
|||||||
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
||||||
delete[] Data;
|
delete[] Data;
|
||||||
} while (Recv != Size && Recv < Size && !Terminate);
|
} while (Recv != Size && Recv < Size && !Terminate);
|
||||||
|
if(Terminate)break;
|
||||||
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::ofstream LFS;
|
std::ofstream LFS;
|
||||||
@@ -182,12 +182,17 @@ void SyncResources(SOCKET Sock){
|
|||||||
ZeroMemory(File,Size);
|
ZeroMemory(File,Size);
|
||||||
delete[] File;
|
delete[] File;
|
||||||
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
}while(fs::file_size(a) != std::stoi(*FS) && !Terminate);
|
||||||
fs::copy_file(a, "BeamNG/mods"+a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing);
|
if(!Terminate)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();
|
||||||
STCPSend(Sock,"Done");
|
if(!Terminate){
|
||||||
std::cout << "Done!" << std::endl;
|
STCPSend(Sock,"Done");
|
||||||
|
std::cout << "Done!" << std::endl;
|
||||||
|
}else{
|
||||||
|
UlStatus = "Ulstart";
|
||||||
|
std::cout << "Connection Terminated!" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+9
-4
@@ -82,6 +82,7 @@ std::string CheckVer(const std::string &path){
|
|||||||
}
|
}
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
std::string HTA(const std::string& hex);
|
||||||
int main(int argc, char* argv[]){
|
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{};
|
||||||
@@ -99,13 +100,17 @@ int main(int argc, char* argv[]){
|
|||||||
std::cout << "Client Connected!" << std::endl;
|
std::cout << "Client Connected!" << std::endl;
|
||||||
link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2);
|
link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2);
|
||||||
HTTP_Result = HTTP_REQUEST(link,443);
|
HTTP_Result = HTTP_REQUEST(link,443);
|
||||||
if(HTTP_Result.find("\"MDEV\"") == NPos){
|
/*if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){
|
||||||
if (HTTP_Result.find("\"MOD\"") == NPos && HTTP_Result.find("\"EA\"") == NPos){
|
|
||||||
if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){
|
if (HTTP_Result.find("\"SUPPORT\"") == NPos && HTTP_Result.find("\"YT\"") == NPos){
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}else Dev = true;
|
if(HTTP_Result.find('"') == NPos && HTTP_Result != "[]"){
|
||||||
|
std::cout << HTA("596f7520617265206e6f7420696e20746865206f6666696369616c204265616d4d5020446973636f726420706c65617365206a6f696e20616e642074727920616761696e2068747470733a2f2f646973636f72642e67672f6265616d6d70") << std::endl;
|
||||||
|
std::this_thread::sleep_for(std::chrono::seconds(3));
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
if(HTTP_Result.find("\"MDEV\"") != NPos)Dev = true;
|
||||||
std::string Path = CheckDir(argc,argv);
|
std::string Path = CheckDir(argc,argv);
|
||||||
std::thread CFU(CheckForUpdates,argc,argv,std::string(ver));
|
std::thread CFU(CheckForUpdates,argc,argv,std::string(ver));
|
||||||
CFU.join();
|
CFU.join();
|
||||||
|
|||||||
Reference in New Issue
Block a user