mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-02 07:56:26 +00:00
Ack system
This commit is contained in:
parent
07f7b69a88
commit
6a3ecfc307
@ -21,8 +21,8 @@ extern bool TCPTerminate;
|
||||
extern bool MPDEV;
|
||||
|
||||
void StartSync(const std::string &Data){
|
||||
std::thread t1(SyncResources,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||
//std::thread t1(SyncResources,"127.0.0.1",30814);
|
||||
//std::thread t1(SyncResources,Data.substr(1,Data.find(':')-1),std::stoi(Data.substr(Data.find(':')+1)));
|
||||
std::thread t1(SyncResources,"127.0.0.1",30814);
|
||||
t1.detach();
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
extern bool Terminate;
|
||||
extern int ClientID;
|
||||
extern bool MPDEV;
|
||||
SOCKET UDPSock;
|
||||
sockaddr_in ToServer{};
|
||||
|
||||
@ -25,24 +26,25 @@ void UDPSend(const std::string&Data){
|
||||
void LOOP(){
|
||||
while(UDPSock != -1) {
|
||||
for (const std::pair<int, std::string>& a : BigDataAcks) {
|
||||
//UDPSend(a.second);
|
||||
UDPSend(a.second);
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
}
|
||||
}
|
||||
|
||||
void AckID(int ID){
|
||||
if(BigDataAcks.empty())return;
|
||||
for(const std::pair<int,std::string>& a : BigDataAcks){
|
||||
if(a.first == ID)BigDataAcks.erase(a);
|
||||
if(a.first == ID){
|
||||
BigDataAcks.erase(a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSendLarge(const std::string&Data){
|
||||
static int ID = 0;
|
||||
std::string Header = "BD:" + std::to_string(ID) + ":";
|
||||
//BigDataAcks.insert(std::make_pair(ID,Header+Data));
|
||||
UDPSend(Header+Data);
|
||||
BigDataAcks.insert(std::make_pair(ID,Header+Data));
|
||||
if(ID > 483647)ID = 0;
|
||||
else ID++;
|
||||
}
|
||||
@ -51,6 +53,7 @@ void ServerParser(const std::string& Data);
|
||||
void UDPParser(const std::string&Packet){
|
||||
if(Packet.substr(0,4) == "ACK:"){
|
||||
AckID(stoi(Packet.substr(4)));
|
||||
if(MPDEV)std::cout << "Got Ack for sending large data" << std::endl;
|
||||
return;
|
||||
}else if(Packet.substr(0,3) == "BD:"){
|
||||
int pos = Packet.find(':',4);
|
||||
|
@ -14,7 +14,6 @@ void CheckForUpdates(const std::string& CV){
|
||||
system ("cls");
|
||||
std::string link = "https://beamng-mp.com/builds/launcher?version=true";
|
||||
std::string HTTP = HTTP_REQUEST(link,443);
|
||||
HTTP = HTTP.substr(HTTP.find_last_of("ver=")+1);
|
||||
link = "https://beamng-mp.com/builds/launcher?download=true";
|
||||
struct stat buffer{};
|
||||
if(stat ("BeamMP-Launcher.back", &buffer) == 0)remove("BeamMP-Launcher.back");
|
||||
|
@ -116,6 +116,7 @@ int main(int argc, char* argv[]){
|
||||
}
|
||||
}
|
||||
}else MPDEV = true;
|
||||
|
||||
//Security
|
||||
auto*Sec = new std::thread(Check);
|
||||
Sec->join();
|
||||
|
Loading…
x
Reference in New Issue
Block a user