ref: e48ea79eb19b130f2aa569401f57e460d6417091
parent: 93f55e498b63ac4da63d9190061b188db1c6c225
author: Simon Howard <[email protected]>
date: Sun Sep 17 14:01:16 EDT 2006
Fix local LAN queries. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 611
--- 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 @@
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 @@
for (i=0; i<70; ++i)
putchar('=');
putchar('\n');
-
- first_response_addr = addr;
}
formatted_printf(18, "%s: ", NET_AddrToString(addr));
@@ -150,7 +185,7 @@
NET_SafePuts(server_description);
- ++num_responses;
+ NET_Query_AddResponder(addr);
}
static void NET_Query_GetResponse(void)
@@ -198,7 +233,10 @@
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 @@
NET_AddModule(query_context, &net_sdl_module);
net_sdl_module.InitClient();
- first_response_addr = NULL;
+ responders = NULL;
num_responses = 0;
}
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_sdl.c 543 2006-05-29 20:04:08Z fraggle $
+// $Id: net_sdl.c 611 2006-09-17 18:01:16Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -221,7 +221,8 @@
if (addr == &net_broadcast_addr)
{
- SDLNet_ResolveHost(&ip, NULL, DEFAULT_PORT);
+ SDLNet_ResolveHost(&ip, NULL, port);
+ ip.host = INADDR_BROADCAST;
}
else
{