summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-09-17 18:01:16 +0000
committerSimon Howard2006-09-17 18:01:16 +0000
commite48ea79eb19b130f2aa569401f57e460d6417091 (patch)
tree9b1b34740ef1175a7f31a8c20863eb8c86d6df09
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
-rw-r--r--src/net_query.c50
-rw-r--r--src/net_sdl.c5
2 files changed, 47 insertions, 8 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;
}
diff --git a/src/net_sdl.c b/src/net_sdl.c
index 4ccc6067..820c9ca9 100644
--- 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 @@ static void NET_SDL_SendPacket(net_addr_t *addr, net_packet_t *packet)
if (addr == &net_broadcast_addr)
{
- SDLNet_ResolveHost(&ip, NULL, DEFAULT_PORT);
+ SDLNet_ResolveHost(&ip, NULL, port);
+ ip.host = INADDR_BROADCAST;
}
else
{