shithub: choc

Download patch

ref: 89b2315275de48ee66241e883b6e7d8695af3c75
parent: d1f2b422e6cbcf2b50b0e02b989cb3fbb314eb9e
author: Simon Howard <fraggle@soulsphere.org>
date: Sat Feb 9 20:09:41 EST 2019

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.

--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -166,6 +166,7 @@
     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.
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -170,8 +170,15 @@
 {
     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);
 }