ref: eb937f4d148a75c4f2b6d3f7687dae4ef2053105
parent: 6f76c8ee6b97097772c11cf3e75d1b641c4d29b7
author: Simon Howard <[email protected]>
date: Sat Apr 8 22:50:34 EDT 2006
Broadcast searches (currently broken) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 467
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: d_main.c 464 2006-04-06 20:48:35Z fraggle $
+// $Id: d_main.c 467 2006-04-09 02:50:34Z fraggle $
//
// Copyright(C) 1993-1996 Id Software, Inc.
// Copyright(C) 2005 Simon Howard
@@ -184,7 +184,7 @@
//-----------------------------------------------------------------------------
-static const char rcsid[] = "$Id: d_main.c 464 2006-04-06 20:48:35Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 467 2006-04-09 02:50:34Z fraggle $";
#define BGCOLOR 7
#define FGCOLOR 8
@@ -1367,6 +1367,10 @@
{
NET_QueryAddress(myargv[p+1]);
}
+
+ if (M_CheckParm("-search"))
+ NET_LANQuery();
+
#ifdef FEATURE_DEHACKED
--- a/src/net_io.c
+++ b/src/net_io.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_io.c 249 2006-01-02 21:02:16Z fraggle $
+// $Id: net_io.c 467 2006-04-09 02:50:34Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -48,6 +48,8 @@
int num_modules;
};
+net_addr_t net_broadcast_addr;
+
net_context_t *NET_NewContext(void)
{
net_context_t *context;
@@ -92,6 +94,16 @@
void NET_SendPacket(net_addr_t *addr, net_packet_t *packet)
{
addr->module->SendPacket(addr, packet);
+}
+
+void NET_SendBroadcast(net_context_t *context, net_packet_t *packet)
+{
+ int i;
+
+ for (i=0; i<context->num_modules; ++i)
+ {
+ context->modules[i]->SendPacket(&net_broadcast_addr, packet);
+ }
}
boolean NET_RecvPacket(net_context_t *context,
--- a/src/net_query.c
+++ b/src/net_query.c
@@ -46,7 +46,16 @@
request = NET_NewPacket(10);
NET_WriteInt16(request, NET_PACKET_TYPE_QUERY);
- NET_SendPacket(addr, request);
+
+ if (addr == NULL)
+ {
+ NET_SendBroadcast(query_context, request);
+ }
+ else
+ {
+ NET_SendPacket(addr, request);
+ }
+
NET_FreePacket(request);
}
@@ -164,6 +173,7 @@
void NET_QueryAddress(char *addr)
{
int start_time;
+ int last_send_time;
net_addr_t *net_addr;
NET_Query_Init();
@@ -177,12 +187,21 @@
printf("\nQuerying '%s'...\n\n", addr);
- NET_Query_SendQuery(net_addr);
-
+ last_send_time = -1;
start_time = I_GetTimeMS();
while (num_responses <= 0 && I_GetTimeMS() < start_time + 5000)
{
+ // Send a query once every second
+
+ if (last_send_time < 0 || I_GetTimeMS() > last_send_time + 1000)
+ {
+ NET_Query_SendQuery(net_addr);
+ last_send_time = I_GetTimeMS();
+ }
+
+ // Check for a response
+
NET_Query_GetResponse();
I_Sleep(100);
}
@@ -190,6 +209,40 @@
if (num_responses <= 0)
{
I_Error("No response from '%s'", addr);
+ }
+
+ exit(0);
+}
+
+void NET_LANQuery(void)
+{
+ int start_time;
+ int last_send_time;
+
+ NET_Query_Init();
+
+ printf("\nPerforming broadcast scan for servers ...\n\n");
+
+ start_time = I_GetTimeMS();
+ last_send_time = -1;
+
+ while (num_responses <= 0 && I_GetTimeMS() < start_time + 5000)
+ {
+ // Send a query once every second
+
+ if (last_send_time < 0 || I_GetTimeMS() > last_send_time + 1000)
+ {
+ NET_Query_SendQuery(NULL);
+ last_send_time = I_GetTimeMS();
+ }
+
+ NET_Query_GetResponse();
+ I_Sleep(100);
+ }
+
+ if (num_responses <= 0)
+ {
+ I_Error("No servers found");
}
exit(0);
--- a/src/net_sdl.c
+++ b/src/net_sdl.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_sdl.c 465 2006-04-06 20:49:16Z fraggle $
+// $Id: net_sdl.c 467 2006-04-09 02:50:34Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -43,6 +43,7 @@
#include "i_system.h"
#include "m_argv.h"
#include "net_defs.h"
+#include "net_io.h"
#include "net_packet.h"
#include "net_sdl.h"
#include "z_zone.h"
@@ -53,7 +54,9 @@
#include <SDL_net.h>
-static int port = 2342;
+#define DEFAULT_PORT 2342
+
+static int port = DEFAULT_PORT;
static UDPsocket udpsocket;
static UDPpacket *recvpacket;
@@ -208,7 +211,17 @@
static void NET_SDL_SendPacket(net_addr_t *addr, net_packet_t *packet)
{
UDPpacket sdl_packet;
- IPaddress *ip = (IPaddress *) addr->handle;
+ IPaddress ip;
+
+ if (addr == &net_broadcast_addr)
+ {
+ ip.host = INADDR_BROADCAST;
+ ip.port = DEFAULT_PORT;
+ }
+ else
+ {
+ ip = *((IPaddress *) addr->handle);
+ }
#if 0
{
@@ -229,7 +242,7 @@
sdl_packet.channel = 0;
sdl_packet.data = packet->data;
sdl_packet.len = packet->len;
- sdl_packet.address = *ip;
+ sdl_packet.address = ip;
if (!SDLNet_UDP_Send(udpsocket, -1, &sdl_packet))
{