shithub: choc

Download patch

ref: 75270ad54ac92830f43b4bcaa088fdf65c5acc83
parent: 694292fa55e926ca4d7be4a26bd55a9faa41a589
author: Simon Howard <fraggle@gmail.com>
date: Fri Dec 30 13:58:22 EST 2005

Fix client code to correctly send reply to server on connection.
Add "waiting screen" while waiting for the game to start.
Hook in the new networking code into the main game code.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 235

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,11 +59,13 @@
 m_swap.c             m_swap.h              \
 net_client.c                               \
 net_defs.h                                 \
+net_gui.c            net_gui.h             \
 net_io.c             net_io.h              \
 net_loop.c           net_loop.h            \
 net_packet.c         net_packet.h          \
 net_sdl.c            net_sdl.h             \
 net_server.c         net_server.h          \
+net_structrw.c       net_structrw.h        \
 p_ceilng.c                                 \
 p_doors.c                                  \
 p_enemy.c                                  \
--- a/src/d_main.c
+++ b/src/d_main.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: d_main.c 223 2005-10-24 18:50:39Z fraggle $
+// $Id: d_main.c 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.32  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.31  2005/10/24 18:50:39  fraggle
 // Allow the game version to emulate to be specified from the command line
 // and set compatibility options accordingly.
@@ -141,7 +146,7 @@
 //-----------------------------------------------------------------------------
 
 
-static const char rcsid[] = "$Id: d_main.c 223 2005-10-24 18:50:39Z fraggle $";
+static const char rcsid[] = "$Id: d_main.c 235 2005-12-30 18:58:22Z fraggle $";
 
 #define	BGCOLOR		7
 #define	FGCOLOR		8
@@ -194,6 +199,7 @@
 #include "wi_stuff.h"
 #include "st_stuff.h"
 #include "am_map.h"
+#include "net_gui.h"
 
 #include "p_setup.h"
 #include "r_local.h"
@@ -389,6 +395,10 @@
       case GS_DEMOSCREEN:
 	D_PageDrawer ();
 	break;
+
+      case GS_WAITINGSTART:
+        NET_Drawer();
+        break;
     }
     
     // draw buffered stuff to screen
@@ -1571,8 +1581,10 @@
 	G_LoadGame (file);
     }
 	
+    // TODO: Remove this test here for GS_WAITINGSTART.  Temporary hack
+    // for new network code.
 
-    if ( gameaction != ga_loadgame )
+    if (gamestate != GS_WAITINGSTART && gameaction != ga_loadgame )
     {
 	if (autostart || netgame)
 	    G_InitNew (startskill, startepisode, startmap);
@@ -1580,6 +1592,6 @@
 	    D_StartTitle ();                // start up intro loop
 
     }
-
+    
     D_DoomLoop ();  // never returns
 }
--- a/src/d_net.c
+++ b/src/d_net.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: d_net.c 120 2005-09-22 13:13:47Z fraggle $
+// $Id: d_net.c 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.9  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.8  2005/09/22 13:13:47  fraggle
 // Remove external statistics driver support (-statcopy):
 // nonfunctional on modern systems and never used.
@@ -58,7 +63,7 @@
 //-----------------------------------------------------------------------------
 
 
-static const char rcsid[] = "$Id: d_net.c 120 2005-09-22 13:13:47Z fraggle $";
+static const char rcsid[] = "$Id: d_net.c 235 2005-12-30 18:58:22Z fraggle $";
 
 
 #include "m_menu.h"
@@ -69,6 +74,9 @@
 #include "doomdef.h"
 #include "doomstat.h"
 
+#include "net_client.h"
+#include "net_server.h"
+
 #define	NCMD_EXIT		0x80000000
 #define	NCMD_RETRANSMIT		0x40000000
 #define	NCMD_SETUP		0x20000000
@@ -408,6 +416,11 @@
     int				realstart;
     int				gameticdiv;
     
+    // Temporary hack - hook new client/server code into Doom
+
+    NET_ClientRun();
+    NET_ServerRun();
+    
     // check time
     nowtime = I_GetTime ()/ticdup;
     newtics = nowtime - gametime;
@@ -581,6 +594,11 @@
     }
 }
 
+#include "m_argv.h"
+#include "net_loop.h"
+#include "net_client.h"
+#include "net_server.h"
+
 //
 // D_CheckNetGame
 // Works out player numbers among the net participants
@@ -590,6 +608,29 @@
 void D_CheckNetGame (void)
 {
     int             i;
+
+    // temporary hack 
+
+    if (M_CheckParm("-server") > 0)
+    {
+        net_addr_t *addr;
+        NET_ServerInit();
+
+        addr = net_loop_client_module.ResolveAddress("");
+
+        printf("address resolved: %p\n", addr);
+
+        if (NET_ClientConnect(addr))
+        {
+            printf("connected to local server\n");
+            
+            gamestate = GS_WAITINGSTART;
+        }
+        else
+        {
+            printf("failed to connect\n");
+        }
+    }
 	
     for (i=0 ; i<MAXNETNODES ; i++)
     {
--- a/src/doomdef.h
+++ b/src/doomdef.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: doomdef.h 223 2005-10-24 18:50:39Z fraggle $
+// $Id: doomdef.h 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -132,12 +132,16 @@
 // The current state of the game: whether we are
 // playing, gazing at the intermission screen,
 // the game final animation, or a demo. 
+//
+// fraggle: GS_WAITINGSTART indicates that we are in a netgame, waiting
+// for a signal from the server to start the game.
 typedef enum
 {
     GS_LEVEL,
     GS_INTERMISSION,
     GS_FINALE,
-    GS_DEMOSCREEN
+    GS_DEMOSCREEN,
+    GS_WAITINGSTART,
 } gamestate_t;
 
 //
@@ -373,6 +377,11 @@
 //-----------------------------------------------------------------------------
 //
 // $Log$
+// Revision 1.9  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.8  2005/10/24 18:50:39  fraggle
 // Allow the game version to emulate to be specified from the command line
 // and set compatibility options accordingly.
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: g_game.c 206 2005-10-17 20:27:05Z fraggle $
+// $Id: g_game.c 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 1993-1996 Id Software, Inc.
 // Copyright(C) 2005 Simon Howard
@@ -22,6 +22,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.17  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.16  2005/10/17 20:27:05  fraggle
 // Start of Dehacked 'Misc' section support.  Initial Health+Bullets,
 // and bfg cells/shot are supported.
@@ -89,7 +94,7 @@
 
 
 static const char
-rcsid[] = "$Id: g_game.c 206 2005-10-17 20:27:05Z fraggle $";
+rcsid[] = "$Id: g_game.c 235 2005-12-30 18:58:22Z fraggle $";
 
 #include <string.h>
 #include <stdlib.h>
@@ -100,6 +105,8 @@
 #include "deh_main.h"
 #include "deh_misc.h"
 
+#include "net_gui.h"
+
 #include "z_zone.h"
 #include "f_finale.h"
 #include "m_argv.h"
@@ -639,6 +646,13 @@
 	} 
 	return false; 
     } 
+
+    // waiting for a network game to start
+
+    if (gamestate == GS_WAITINGSTART)
+    {
+        return NET_Responder(ev);
+    }
  
     if (gamestate == GS_LEVEL) 
     { 
@@ -851,7 +865,10 @@
  
       case GS_DEMOSCREEN: 
 	D_PageTicker (); 
-	break; 
+	break;
+
+      case GS_WAITINGSTART:
+        break;
     }        
 } 
  
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_client.c 233 2005-12-29 21:29:55Z fraggle $
+// $Id: net_client.c 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.2  2005/12/29 21:29:55  fraggle
 // Working client connect code
 //
@@ -37,6 +42,7 @@
 #include "i_system.h"
 #include "net_client.h"
 #include "net_defs.h"
+#include "net_gui.h"
 #include "net_io.h"
 #include "net_packet.h"
 #include "net_server.h"
@@ -56,11 +62,53 @@
     CLIENT_STATE_IN_GAME,
 } net_clientstate_t;
 
+static boolean client_initialised = false;
+
 static net_clientstate_t client_state;
 static net_addr_t *server_addr;
 static net_context_t *client_context;
 static int last_send_time;
 
+// data received while we are waiting for the game to start
+
+static void ClientParseWaitingData(net_packet_t *packet)
+{
+    unsigned int num_players;
+    unsigned int is_controller;
+
+    if (!NET_ReadInt8(packet, &num_players)
+     || !NET_ReadInt8(packet, &is_controller))
+    {
+        // invalid packet
+
+        return;
+    }
+
+    net_clients_in_game = num_players;
+    net_client_controller = is_controller != 0;
+}
+
+// Received an ACK
+
+static void ClientParseACK(net_packet_t *packet)
+{
+    net_packet_t *reply;
+
+    // send an ACK back
+
+    reply = NET_NewPacket(10);
+    NET_WriteInt16(reply, NET_PACKET_TYPE_ACK);
+    NET_SendPacket(server_addr, reply);
+    NET_FreePacket(reply);
+
+    // set the client state if we havent already
+ 
+    if (client_state == CLIENT_STATE_CONNECTING)
+    {
+        client_state = CLIENT_STATE_WAITING_START;
+    }
+}
+
 // parse a received packet
 
 static void ClientParsePacket(net_packet_t *packet)
@@ -78,12 +126,14 @@
 
             // received an acknowledgement to the SYN we sent
 
-            if (client_state == CLIENT_STATE_CONNECTING)
-            {
-                client_state = CLIENT_STATE_WAITING_START;
-            }
+            ClientParseACK(packet);
             break;
 
+        case NET_PACKET_TYPE_WAITING_DATA:
+
+            ClientParseWaitingData(packet);
+            break;
+
         case NET_PACKET_TYPE_GAMESTART:
             break;
 
@@ -134,6 +184,11 @@
     net_addr_t *addr;
     net_packet_t *packet;
     
+    if (!client_initialised)
+    {
+        return;
+    }
+    
     while (NET_RecvPacket(client_context, &addr, &packet))
     {
         // only accept packets from the server
@@ -181,6 +236,8 @@
     }
 
     NET_AddModule(client_context, addr->module);
+
+    client_initialised = true;
 
     // try to connect
  
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_client.h 233 2005-12-29 21:29:55Z fraggle $
+// $Id: net_client.h 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.2  2005/12/29 21:29:55  fraggle
 // Working client connect code
 //
@@ -38,6 +43,7 @@
 #include "net_defs.h"
 
 boolean NET_ClientConnect(net_addr_t *addr);
+void NET_ClientRun(void);
 
 #endif /* #ifndef NET_CLIENT_H */
 
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_defs.h 232 2005-12-29 17:48:25Z fraggle $
+// $Id: net_defs.h 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.2  2005/12/29 17:48:25  fraggle
 // Add initial client/server connect code.  Reorganise sources list in
 // Makefile.am.
@@ -101,11 +106,22 @@
 
 typedef enum 
 {
-        NET_PACKET_TYPE_SYN,
-        NET_PACKET_TYPE_ACK,
-        NET_PACKET_TYPE_GAMESTART,
-        NET_PACKET_TYPE_GAMEDATA,
+    NET_PACKET_TYPE_SYN,
+    NET_PACKET_TYPE_ACK,
+    NET_PACKET_TYPE_WAITING_DATA,
+    NET_PACKET_TYPE_GAMESTART,
+    NET_PACKET_TYPE_GAMEDATA,
 } net_packet_type_t;
+
+typedef struct 
+{
+    int ticdup;
+    int extratics;
+    int deathmatch;
+    int episode;
+    int map;
+    int skill;
+} net_gamesettings_t;
 
 #endif /* #ifndef NET_DEFS_H */
 
--- /dev/null
+++ b/src/net_gui.c
@@ -1,0 +1,92 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: net_gui.c 235 2005-12-30 18:58:22Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
+//
+// Graphical stuff related to the networking code:
+//
+//  * The client waiting screen when we are waiting for the server to
+//    start the game.
+//   
+
+#include "net_gui.h"
+#include "d_event.h"
+#include "r_defs.h"
+#include "v_video.h"
+#include "w_wad.h"
+#include "z_zone.h"
+
+extern void M_WriteText(int x, int y, char *string);
+
+// if TRUE, this client is the controller of the game
+
+boolean net_client_controller = false;
+
+// Number of clients currently connected to the server
+
+int net_clients_in_game;
+
+void NET_Drawer(void)
+{
+    patch_t *backdrop;
+    int backdrop_lumpnum;
+    char buf[128];
+
+    // Use INTERPIC or TITLEPIC if we don't have it
+
+    backdrop_lumpnum = W_CheckNumForName("INTERPIC");
+
+    if (backdrop_lumpnum < 0)
+    {
+        backdrop_lumpnum = W_CheckNumForName("TITLEPIC");
+    }
+
+    backdrop = (patch_t *) W_CacheLumpNum(backdrop_lumpnum, PU_CACHE);
+
+    // draw the backdrop
+    
+    V_DrawPatch(0, 0, 0, backdrop);
+
+    sprintf(buf, "%i clients connected to server.", net_clients_in_game);
+
+    M_WriteText(32, 100, buf);
+
+    if (net_client_controller)
+    {
+        M_WriteText(32, 150, "Press space to start the game...");
+    }
+    else
+    {
+        M_WriteText(32, 150, "Waiting for the game to start...");
+    }
+}
+
+boolean NET_Responder(event_t *event)
+{
+    return true;
+}
+
--- /dev/null
+++ b/src/net_gui.h
@@ -1,0 +1,50 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: net_gui.h 235 2005-12-30 18:58:22Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
+//
+// Graphical stuff related to the networking code:
+//
+//  * The client waiting screen when we are waiting for the server to
+//    start the game.
+//   
+
+
+#ifndef NET_GUI_H 
+#define NET_GUI_H
+
+#include "doomtype.h"
+#include "d_event.h"
+
+extern void NET_Drawer(void);
+extern boolean NET_Responder(event_t *event);
+
+extern boolean net_client_controller;
+extern int net_clients_in_game;
+
+#endif /* #ifndef NET_GUI_H */
+
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -1,7 +1,7 @@
 // Emacs style mode select   -*- C++ -*- 
 //-----------------------------------------------------------------------------
 //
-// $Id: net_server.c 233 2005-12-29 21:29:55Z fraggle $
+// $Id: net_server.c 235 2005-12-30 18:58:22Z fraggle $
 //
 // Copyright(C) 2005 Simon Howard
 //
@@ -21,6 +21,11 @@
 // 02111-1307, USA.
 //
 // $Log$
+// Revision 1.3  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
 // Revision 1.2  2005/12/29 21:29:55  fraggle
 // Working client connect code
 //
@@ -72,11 +77,50 @@
 static net_client_t clients[MAXNETNODES];
 static net_context_t *server_context;
 
+// returns the number of clients connected
+
+static int ServerNumClients(void)
+{
+    int count;
+    int i;
+
+    count = 0;
+
+    for (i=0; i<MAXNETNODES; ++i)
+    {
+        if (clients[i].active)
+        {
+            ++count;
+        }
+    }
+
+    return count;
+}
+
+// returns a pointer to the client which controls the server
+
+static net_client_t *ServerController(void)
+{
+    int i;
+
+    // first client in the list is the controller
+
+    for (i=0; i<MAXNETNODES; ++i)
+    {
+        if (clients[i].active)
+        {
+            return &clients[i];
+        }
+    }
+
+    return NULL;
+}
+
 // parse a SYN from a client(initiating a connection)
 
-static void NET_ServerParseSYN(net_packet_t *packet, 
-                               net_client_t *client,
-                               net_addr_t *addr)
+static void ServerParseSYN(net_packet_t *packet, 
+                           net_client_t *client,
+                           net_addr_t *addr)
 {
     unsigned int magic;
     int i;
@@ -132,7 +176,7 @@
 
 // parse an ACK packet from a client
 
-static void NET_ServerParseACK(net_packet_t *packet, net_client_t *client)
+static void ServerParseACK(net_packet_t *packet, net_client_t *client)
 {
     if (client == NULL)
     {
@@ -144,12 +188,16 @@
         // now waiting for the game to start
 
         client->state = CLIENT_STATE_WAITING_START;
+
+        // force a waiting data packet to be sent immediately
+
+        client->last_send_time = -1;
     }
 }
 
 // Process a packet received by the server
 
-static void NET_ServerPacket(net_packet_t *packet, net_addr_t *addr)
+static void ServerPacket(net_packet_t *packet, net_addr_t *addr)
 {
     net_client_t *client;
     unsigned int packet_type;
@@ -161,7 +209,7 @@
 
     for (i=0; i<MAXNETNODES; ++i) 
     {
-        if (clients[i].active && client[i].addr == addr)
+        if (clients[i].active && clients[i].addr == addr)
         {
             // found the client
 
@@ -180,10 +228,10 @@
     switch (packet_type)
     {
         case NET_PACKET_TYPE_SYN:
-            NET_ServerParseSYN(packet, client, addr);
+            ServerParseSYN(packet, client, addr);
             break;
         case NET_PACKET_TYPE_ACK:
-            NET_ServerParseACK(packet, client);
+            ServerParseACK(packet, client);
             break;
         case NET_PACKET_TYPE_GAMESTART:
             break;
@@ -196,9 +244,37 @@
     }
 }
 
+
+static void ServerSendWaitingData(net_client_t *client)
+{
+    net_packet_t *packet;
+
+    // time to send the client another status packet
+
+    packet = NET_NewPacket(10);
+    NET_WriteInt16(packet, NET_PACKET_TYPE_WAITING_DATA);
+
+    // include the number of clients waiting
+
+    NET_WriteInt8(packet, ServerNumClients());
+
+    // indicate whether the client is the controller
+
+    NET_WriteInt8(packet, ServerController() == client);
+    
+    // send packet to client and free
+
+    NET_SendPacket(client->addr, packet);
+    NET_FreePacket(packet);
+    
+    // update time
+
+    client->last_send_time = I_GetTimeMS();
+}
+
 // Perform any needed action on a client
 
-void NET_ServerRunClient(net_client_t *client)
+static void ServerRunClient(net_client_t *client)
 {
     net_packet_t *packet;
 
@@ -232,6 +308,17 @@
             }
         }
     }
+
+    // waiting for the game to start
+
+    if (client->state == CLIENT_STATE_WAITING_START)
+    {
+        if (client->last_send_time < 0 
+         || I_GetTimeMS() - client->last_send_time > 1000)
+        {
+            ServerSendWaitingData(client);
+        }
+    }
 }
 
 // Initialise server and wait for connections
@@ -272,7 +359,7 @@
 
     while (NET_RecvPacket(server_context, &addr, &packet)) 
     {
-        NET_ServerPacket(packet, addr);
+        ServerPacket(packet, addr);
     }
 
     // "Run" any clients that may have things to do, independent of responses
@@ -282,7 +369,7 @@
     {
         if (clients[i].active)
         {
-            NET_ServerRunClient(&clients[i]);
+            ServerRunClient(&clients[i]);
         }
     }
 }
--- /dev/null
+++ b/src/net_structrw.c
@@ -1,0 +1,54 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: net_structrw.c 235 2005-12-30 18:58:22Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
+//
+// Reading and writing various structures into packets
+//
+
+#include "net_packet.h"
+
+void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings)
+{
+    NET_WriteInt8(packet, settings->ticdup);
+    NET_WriteInt8(packet, settings->extratics);
+    NET_WriteInt8(packet, settings->deathmatch);
+    NET_WriteInt8(packet, settings->episode);
+    NET_WriteInt8(packet, settings->map);
+    NET_WriteInt8(packet, settings->skill);
+}
+
+boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings)
+{
+    return NET_ReadInt8(packet, (unsigned int *) &settings->ticdup)
+        && NET_ReadInt8(packet, (unsigned int *) &settings->extratics)
+        && NET_ReadInt8(packet, (unsigned int *) &settings->deathmatch)
+        && NET_ReadInt8(packet, (unsigned int *) &settings->episode)
+        && NET_ReadInt8(packet, (unsigned int *) &settings->map)
+        && NET_ReadInt8(packet, (unsigned int *) &settings->skill);
+}
+
--- /dev/null
+++ b/src/net_structrw.h
@@ -1,0 +1,41 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id: net_structrw.h 235 2005-12-30 18:58:22Z fraggle $
+//
+// Copyright(C) 2005 Simon Howard
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+// 02111-1307, USA.
+//
+// $Log$
+// Revision 1.1  2005/12/30 18:58:22  fraggle
+// Fix client code to correctly send reply to server on connection.
+// Add "waiting screen" while waiting for the game to start.
+// Hook in the new networking code into the main game code.
+//
+
+#ifndef NET_STRUCTRW_H
+#define NET_STRUCTRW_H
+
+#include "net_defs.h"
+#include "net_packet.h"
+
+extern void NET_WriteSettings(net_packet_t *packet, net_gamesettings_t *settings);
+extern boolean NET_ReadSettings(net_packet_t *packet, net_gamesettings_t *settings);
+
+
+#endif /* #ifndef NET_STRUCTRW_H */
+