From 1fd02147b650e9de8725bce43fc7156bdb4eac02 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Fri, 21 Oct 2022 12:27:01 -0700 Subject: [PATCH] Add a flag to only send udp if client has received udp packets --- include/server/SocketClient.hpp | 1 + source/server/SocketClient.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 34a2449..91fb96b 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -37,6 +37,7 @@ class SocketClient : public SocketBase { private: int maxBufSize = 100; + bool has_recv_udp; s32 udp_socket; sockaddr udp_addr; diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index a330b68..d782d04 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -138,7 +138,7 @@ bool SocketClient::SEND(Packet *packet) { int valread = 0; int fd = -1; - if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) { + if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) { Logger::log("Sending packet: %s\n", packetNames[packet->mType]); fd = this->socket_log_socket; } else { @@ -196,7 +196,8 @@ bool SocketClient::RECV() { if (fd == -1) { return true; } -if (index == 1) { + + if (index == 1) { int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags); if (result < headerSize){ return true; @@ -224,6 +225,7 @@ if (index == 1) { if(mPacketQueue.size() < maxBufSize - 1) { mPacketQueue.pushBack(packet); + this->has_recv_udp = true; } else { free(packetBuf); }