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