mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-02 15:55:30 +00:00
Ack system
This commit is contained in:
parent
ba47f21898
commit
49c38a0f00
@ -14,7 +14,6 @@
|
||||
SOCKET UDPSock;
|
||||
|
||||
std::set<std::tuple<int,Client*,std::string>> BigDataAcks;
|
||||
|
||||
void UDPSend(Client*c,const std::string&Data){
|
||||
if(!c->isConnected())return;
|
||||
sockaddr_in Addr = c->GetUDPAddr();
|
||||
@ -24,17 +23,18 @@ void UDPSend(Client*c,const std::string&Data){
|
||||
}
|
||||
|
||||
void AckID(int ID){
|
||||
if(BigDataAcks.empty())return;
|
||||
for(std::tuple<int,Client*,std::string> a : BigDataAcks){
|
||||
if(get<0>(a) == ID)BigDataAcks.erase(a);
|
||||
if(get<0>(a) == ID){
|
||||
BigDataAcks.erase(a);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCPSendLarge(Client*c,const std::string&Data){
|
||||
static int ID = 0;
|
||||
std::string Header = "BD:" + std::to_string(ID) + ":";
|
||||
//BigDataAcks.insert(std::make_tuple(ID,c,Header+Data));
|
||||
UDPSend(c,Header+Data);
|
||||
BigDataAcks.insert(std::make_tuple(ID,c,Header+Data));
|
||||
if(ID > 483647)ID = 0;
|
||||
else ID++;
|
||||
}
|
||||
@ -58,6 +58,7 @@ void GlobalParser(Client*c, const std::string&Packet);
|
||||
void UDPParser(Client*c, const std::string&Packet){
|
||||
if(Packet.substr(0,4) == "ACK:"){
|
||||
AckID(stoi(Packet.substr(4)));
|
||||
std::cout << "Got Ack from " << c->GetName() << std::endl;
|
||||
return;
|
||||
}else if(Packet.substr(0,3) == "BD:"){
|
||||
int pos = Packet.find(':',4);
|
||||
@ -130,9 +131,9 @@ void LOOP(){
|
||||
for (std::tuple<int, Client *, std::string> a : BigDataAcks) {
|
||||
if (get<1>(a)->GetTCPSock() == -1) {
|
||||
BigDataAcks.erase(a);
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
//UDPSend(get<1>(a), get<2>(a));
|
||||
UDPSend(get<1>(a), get<2>(a));
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ void PostHTTP(const std::string& IP,const std::string& Fields);
|
||||
|
||||
void Heartbeat()
|
||||
{
|
||||
|
||||
string UUID = HTTP_REQUEST("https://beamng-mp.com/new-server-startup",443);
|
||||
std::string State = Private ? "true" : "false";
|
||||
std::string State;
|
||||
while(true)
|
||||
{
|
||||
State = Private ? "true" : "false";
|
||||
PostHTTP("https://beamng-mp.com/heartbeat","uuid="+UUID+"&players="+to_string(Clients.size())+"&maxplayers="+to_string(MaxPlayers)+"&port="
|
||||
+ to_string(Port) + "&map=" + MapName + "&private="+State+"&version="+ServerVersion+"&clientversion="+ClientVersion+"&name="+ServerName);
|
||||
std::this_thread::sleep_for (std::chrono::seconds(5));
|
||||
|
@ -18,7 +18,7 @@ void addToLog(const string& Data);
|
||||
//void ServerMain(int Port, int MaxClients);
|
||||
void HeartbeatInit();
|
||||
string ServerVersion = "0.1";
|
||||
string ClientVersion = "0.21";
|
||||
string ClientVersion = "1.1";
|
||||
void HandleResources(const std::string& path);
|
||||
//void TCPMain(int Port);
|
||||
void NetMain();
|
||||
@ -26,6 +26,7 @@ void NetMain();
|
||||
int main() {
|
||||
LogInit();
|
||||
ParseConfig();
|
||||
info("BeamMP Server Running version " + ServerVersion);
|
||||
HandleResources(Resource);
|
||||
HeartbeatInit();
|
||||
if(Debug)DebugData();
|
||||
|
Loading…
x
Reference in New Issue
Block a user