From e69ea46982146f55341ec1e38cdb912a555623e4 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Thu, 22 Feb 2024 11:18:12 +0100 Subject: [PATCH] Respond to pings sent as vital messages with vital pongs Matching the requester allows "reliable" and "unreliable" pings. "Reliable" pings suffer from re-sends, thus might not accurately reflect the latency, "unreliable" pings might not arrive at all. --- src/engine/client/client.cpp | 6 ++++-- src/engine/server/server.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 2ed047512..7d1e5704f 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -1509,7 +1509,8 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy) else if(Msg == NETMSG_PING) { CMsgPacker MsgP(NETMSG_PING_REPLY, true); - SendMsg(Conn, &MsgP, MSGFLAG_FLUSH); + int Vital = (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 ? MSGFLAG_VITAL : 0; + SendMsg(Conn, &MsgP, MSGFLAG_FLUSH | Vital); } else if(Msg == NETMSG_PINGEX) { @@ -1520,7 +1521,8 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy) } CMsgPacker MsgP(NETMSG_PONGEX, true); MsgP.AddRaw(pID, sizeof(*pID)); - SendMsg(Conn, &MsgP, MSGFLAG_FLUSH); + int Vital = (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 ? MSGFLAG_VITAL : 0; + SendMsg(Conn, &MsgP, MSGFLAG_FLUSH | Vital); } else if(Conn == CONN_MAIN && Msg == NETMSG_PONGEX) { diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index cf37ae216..d9bcef7fd 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -1817,7 +1817,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) else if(Msg == NETMSG_PING) { CMsgPacker Msgp(NETMSG_PING_REPLY, true); - SendMsg(&Msgp, MSGFLAG_FLUSH, ClientID); + int Vital = (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 ? MSGFLAG_VITAL : 0; + SendMsg(&Msgp, MSGFLAG_FLUSH | Vital, ClientID); } else if(Msg == NETMSG_PINGEX) { @@ -1828,7 +1829,8 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket) } CMsgPacker Msgp(NETMSG_PONGEX, true); Msgp.AddRaw(pID, sizeof(*pID)); - SendMsg(&Msgp, MSGFLAG_FLUSH, ClientID); + int Vital = (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 ? MSGFLAG_VITAL : 0; + SendMsg(&Msgp, MSGFLAG_FLUSH | Vital, ClientID); } else {