From f9245137f5866c4ee3e60ed684e4b43da54ad643 Mon Sep 17 00:00:00 2001 From: Arisotura Date: Sun, 3 Sep 2023 20:11:33 +0200 Subject: [PATCH] attempt at receiving MP replies and such, let's see --- src/frontend/qt_sdl/LAN.cpp | 85 +++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/src/frontend/qt_sdl/LAN.cpp b/src/frontend/qt_sdl/LAN.cpp index 3be2ccde..86dcad48 100644 --- a/src/frontend/qt_sdl/LAN.cpp +++ b/src/frontend/qt_sdl/LAN.cpp @@ -203,6 +203,7 @@ u32 HostAddress; bool Lag; int MPRecvTimeout; +int LastHostID; std::queue RXQueue; @@ -221,6 +222,7 @@ bool Init() ConnectedBitmask = 0; MPRecvTimeout = 25; + LastHostID = -1; // TODO we init enet here but also in Netplay // that is redundant @@ -267,6 +269,7 @@ void StartHost(const char* playername, int numplayers) memcpy(&MyPlayer, player, sizeof(Player)); HostAddress = 0x0100007F; + LastHostID = -1; Active = true; IsHost = true; @@ -321,6 +324,7 @@ void StartClient(const char* playername, const char* host) player->Status = 3; HostAddress = addr.host; + LastHostID = -1; Active = true; IsHost = false; @@ -614,8 +618,9 @@ void SetMPRecvTimeout(int timeout) void MPBegin() { ConnectedBitmask |= (1<Length; if (len) + { + if (len > 2048) len = 2048; + memcpy(packet, &enetpacket->data[sizeof(MPPacketHeader)], len); + if (header->Type == 1) + LastHostID = header->SenderID; + } + if (timestamp) *timestamp = header->Timestamp; + enet_packet_destroy(enetpacket); return len; } @@ -716,12 +729,76 @@ int SendMPAck(u8* packet, int len, u64 timestamp) int RecvMPHostPacket(u8* packet, u64* timestamp) { - return 0; + if (LastHostID != -1) + { + // check if the host is still connected + + if (!(ConnectedBitmask & (1<data[0]; + bool good = true; + if (enetpacket->dataLength < sizeof(MPPacketHeader)) + good = false; + else if (header->Magic != 0x4946494E) + good = false; + else if (header->SenderID == MyPlayer.ID) + good = false; + else if ((header->Type & 0xFFFF) != 2) + good = false; + else if (header->Timestamp < (timestamp - 32)) + good = false; + + if (good) + { + u32 len = header->Length; + if (len) + { + if (len > 1024) len = 1024; + + u32 aid = header->Type >> 16; + memcpy(&packets[(aid-1)*1024], &enetpacket->data[sizeof(MPPacketHeader)], len); + + ret |= (1<SenderID); + if (((myinstmask & ConnectedBitmask) == ConnectedBitmask) || + ((ret & aidmask) == aidmask)) + { + // all the clients have sent their reply + enet_packet_destroy(enetpacket); + return ret; + } + } + + enet_packet_destroy(enetpacket); + } } }