summaryrefslogtreecommitdiff
path: root/src/net_query.c
diff options
context:
space:
mode:
authorSimon Howard2006-09-17 18:01:16 +0000
committerSimon Howard2006-09-17 18:01:16 +0000
commite48ea79eb19b130f2aa569401f57e460d6417091 (patch)
tree9b1b34740ef1175a7f31a8c20863eb8c86d6df09 /src/net_query.c
parent93f55e498b63ac4da63d9190061b188db1c6c225 (diff)
downloadchocolate-doom-e48ea79eb19b130f2aa569401f57e460d6417091.tar.gz
chocolate-doom-e48ea79eb19b130f2aa569401f57e460d6417091.tar.bz2
chocolate-doom-e48ea79eb19b130f2aa569401f57e460d6417091.zip
Fix local LAN queries.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 611
Diffstat (limited to 'src/net_query.c')
-rw-r--r--src/net_query.c50
1 files changed, 44 insertions, 6 deletions
diff --git a/src/net_query.c b/src/net_query.c
index d4955061..07d947b5 100644
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -37,10 +37,40 @@
#include "net_query.h"
#include "net_sdl.h"
-static net_addr_t *first_response_addr;
static net_context_t *query_context;
+static net_addr_t **responders;
static int num_responses;
+// Add a new address to the list of hosts that has responded
+
+static void NET_Query_AddResponder(net_addr_t *addr)
+{
+ responders = realloc(responders,
+ sizeof(net_addr_t *) * (num_responses + 1));
+ responders[num_responses] = addr;
+ ++num_responses;
+}
+
+// Returns true if the reply is from a host that has not previously
+// responded.
+
+static boolean NET_Query_CheckResponder(net_addr_t *addr)
+{
+ int i;
+
+ for (i=0; i<num_responses; ++i)
+ {
+ if (responders[i] == addr)
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+// Transmit a query packet
+
static void NET_Query_SendQuery(net_addr_t *addr)
{
net_packet_t *request;
@@ -108,6 +138,13 @@ static void NET_Query_ParsePacket(net_addr_t *addr, net_packet_t *packet)
char *server_description;
int i;
+ // Have we already received a packet from this host?
+
+ if (!NET_Query_CheckResponder(addr))
+ {
+ return;
+ }
+
if (!NET_ReadInt16(packet, &packet_type)
|| !(server_version = NET_ReadString(packet))
|| !NET_ReadInt8(packet, &in_game)
@@ -131,8 +168,6 @@ static void NET_Query_ParsePacket(net_addr_t *addr, net_packet_t *packet)
for (i=0; i<70; ++i)
putchar('=');
putchar('\n');
-
- first_response_addr = addr;
}
formatted_printf(18, "%s: ", NET_AddrToString(addr));
@@ -150,7 +185,7 @@ static void NET_Query_ParsePacket(net_addr_t *addr, net_packet_t *packet)
NET_SafePuts(server_description);
- ++num_responses;
+ NET_Query_AddResponder(addr);
}
static void NET_Query_GetResponse(void)
@@ -198,7 +233,10 @@ static net_addr_t *NET_Query_QueryLoop(net_addr_t *addr,
I_Sleep(100);
}
- return first_response_addr;
+ if (num_responses > 0)
+ return responders[0];
+ else
+ return NULL;
}
void NET_Query_Init(void)
@@ -207,7 +245,7 @@ void NET_Query_Init(void)
NET_AddModule(query_context, &net_sdl_module);
net_sdl_module.InitClient();
- first_response_addr = NULL;
+ responders = NULL;
num_responses = 0;
}