mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 07:56:26 +00:00
major bug/crash fixing ready for release
This commit is contained in:
parent
1711662241
commit
2c93c953ec
@ -19,6 +19,7 @@ extern bool TCPTerminate;
|
||||
extern bool Dev;
|
||||
extern std::string ListOfMods;
|
||||
bool Confirm = false;
|
||||
void Reset();
|
||||
std::set<std::string> Conf;
|
||||
void StartSync(const std::string &Data){
|
||||
UlStatus = "UlLoading...";
|
||||
@ -36,6 +37,9 @@ std::string Parse(const std::string& Data){
|
||||
case 'A':
|
||||
return Data.substr(0,1);
|
||||
case 'B':
|
||||
Reset();
|
||||
Terminate = true;
|
||||
TCPTerminate = true;
|
||||
return Code + HTTP_REQUEST("s1.yourthought.co.uk/servers-info",3599);
|
||||
case 'C':
|
||||
ListOfMods.clear();
|
||||
@ -54,6 +58,7 @@ std::string Parse(const std::string& Data){
|
||||
return MStatus;
|
||||
case 'Q':
|
||||
if(SubCode == 'S'){
|
||||
Reset();
|
||||
Terminate = true;
|
||||
TCPTerminate = true;
|
||||
}
|
||||
@ -113,16 +118,16 @@ bool once = false;
|
||||
if (Dev)std::cout << "(Core) socket failed with error: " << WSAGetLastError() << std::endl;
|
||||
freeaddrinfo(result);
|
||||
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);
|
||||
if (iResult == SOCKET_ERROR) {
|
||||
@ -148,7 +153,7 @@ bool once = false;
|
||||
if (iResult > 0) {
|
||||
std::string data = recvbuf;
|
||||
data.resize(iResult);
|
||||
Response = Parse(data) + "\n";
|
||||
Response = Parse(data);
|
||||
} else if (iResult == 0) {
|
||||
if (Dev)std::cout << "(Core) Connection closing...\n";
|
||||
} else {
|
||||
@ -157,7 +162,7 @@ bool once = false;
|
||||
WSACleanup();
|
||||
}
|
||||
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 (Dev)std::cout << "send failed with error: " << WSAGetLastError() << std::endl;
|
||||
closesocket(ClientSocket);
|
||||
|
@ -97,13 +97,15 @@ void NetMain(const std::string& IP, int Port){
|
||||
}
|
||||
extern SOCKET UDPSock;
|
||||
extern SOCKET TCPSock;
|
||||
void Reset() {
|
||||
void Reset(){
|
||||
TCPTerminate = false;
|
||||
gameConected = false;
|
||||
Terminate = false;
|
||||
UlStatus = "Ulstart";
|
||||
MStatus = " ";
|
||||
if(UDPSock != SOCKET_ERROR)closesocket(UDPSock);
|
||||
UDPSock = -1;
|
||||
if(TCPSock != SOCKET_ERROR)closesocket(TCPSock);
|
||||
TCPSock = -1;
|
||||
}
|
||||
std::string Compress(const std::string&Data);
|
||||
|
@ -148,7 +148,6 @@ void SyncResources(SOCKET Sock){
|
||||
}else remove(a.c_str());
|
||||
}
|
||||
CheckForDir();
|
||||
|
||||
do {
|
||||
STCPSend(Sock, "f" + *FN);
|
||||
int Recv = 0,Size = std::stoi(*FS);
|
||||
@ -159,7 +158,7 @@ void SyncResources(SOCKET Sock){
|
||||
char* Data = Pair.first;
|
||||
size_t BytesRcv = Pair.second;
|
||||
if (strcmp(Data, "Cannot Open") == 0 || Terminate){
|
||||
delete[] Data;
|
||||
if(BytesRcv != 0)delete[] Data;
|
||||
break;
|
||||
}
|
||||
memcpy_s(File+Recv,BytesRcv,Data,BytesRcv);
|
||||
@ -171,6 +170,7 @@ void SyncResources(SOCKET Sock){
|
||||
Percent.substr(0, Percent.find('.') + 2) + "%)";
|
||||
delete[] Data;
|
||||
} while (Recv != Size && Recv < Size && !Terminate);
|
||||
if(Terminate)break;
|
||||
UlStatus = "UlLoading Resource: (" + std::to_string(Pos) + "/" + std::to_string(Amount) +
|
||||
"): " + a.substr(a.find_last_of('/'));
|
||||
std::ofstream LFS;
|
||||
@ -182,12 +182,17 @@ void SyncResources(SOCKET Sock){
|
||||
ZeroMemory(File,Size);
|
||||
delete[] File;
|
||||
}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();
|
||||
}
|
||||
FNames.clear();
|
||||
FSizes.clear();
|
||||
a.clear();
|
||||
STCPSend(Sock,"Done");
|
||||
std::cout << "Done!" << std::endl;
|
||||
if(!Terminate){
|
||||
STCPSend(Sock,"Done");
|
||||
std::cout << "Done!" << std::endl;
|
||||
}else{
|
||||
UlStatus = "Ulstart";
|
||||
std::cout << "Connection Terminated!" << std::endl;
|
||||
}
|
||||
}
|
13
src/main.cpp
13
src/main.cpp
@ -82,6 +82,7 @@ std::string CheckVer(const std::string &path){
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
std::string HTA(const std::string& hex);
|
||||
int main(int argc, char* argv[]){
|
||||
const unsigned long long NPos = std::string::npos;
|
||||
struct stat info{};
|
||||
@ -99,13 +100,17 @@ int main(int argc, char* argv[]){
|
||||
std::cout << "Client Connected!" << std::endl;
|
||||
link = "https://beamng-mp.com/entitlement?did="+GlobalInfo.at(2);
|
||||
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){
|
||||
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::thread CFU(CheckForUpdates,argc,argv,std::string(ver));
|
||||
CFU.join();
|
||||
|
Loading…
x
Reference in New Issue
Block a user