foxygit / doom Log in
commit 89b2315275de48ee66241e883b6e7d8695af3c75
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun Feb 10 01:09:41 2019 -0500
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun Feb 10 01:09:41 2019 -0500

    net: Request hole punches when doing queries.

    Send HOLE_PUNCH_ALL messages to the master server when performing
    queries so that any servers behind NAT gateways will open themselves
    up. The subsequent queries should then succeed.

    This fixes #469.
---
 src/net_defs.h  | 1 +
 src/net_query.c | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/net_defs.h b/src/net_defs.h
index d12543df..ab852c08 100644
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -166,6 +166,7 @@ typedef enum
     NET_MASTER_PACKET_TYPE_SIGN_END,
     NET_MASTER_PACKET_TYPE_SIGN_END_RESPONSE,
     NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH,
+    NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH_ALL,
 } net_master_packet_type_t;

 // Settings specified when the client connects to the server.
diff --git a/src/net_query.c b/src/net_query.c
index ed71db27..4f19a8b7 100644
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -170,10 +170,17 @@ static void NET_Query_SendMasterQuery(net_addr_t *addr)
 {
     net_packet_t *packet;

-    packet = NET_NewPacket(10);
+    packet = NET_NewPacket(4);
     NET_WriteInt16(packet, NET_MASTER_PACKET_TYPE_QUERY);
     NET_SendPacket(addr, packet);
     NET_FreePacket(packet);
+
+    // We also send a NAT_HOLE_PUNCH_ALL packet so that servers behind
+    // NAT gateways will open themselves up to us.
+    packet = NET_NewPacket(4);
+    NET_WriteInt16(packet, NET_MASTER_PACKET_TYPE_NAT_HOLE_PUNCH_ALL);
+    NET_SendPacket(addr, packet);
+    NET_FreePacket(packet);
 }

 // Send a hole punch request to the master server for the server at the