shithub: choc

Download patch

ref: a4567e04c7f90f12ae7e2bedf840d80e14409283
parent: e5806af05eb31c18250bf74c9b8ae052a0666b6b
author: Simon Howard <[email protected]>
date: Wed Oct 19 14:10:11 EDT 2011

Change MAXPLAYERS to NET_MAXPLAYERS and add back individual MAXPLAYERS
defines for each game. Refactor "waiting screen" data code.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2441

--- a/src/d_loop.c
+++ b/src/d_loop.c
@@ -52,8 +52,8 @@
 
 typedef struct
 {
-    ticcmd_t cmds[MAXPLAYERS];
-    boolean ingame[MAXPLAYERS];
+    ticcmd_t cmds[NET_MAXPLAYERS];
+    boolean ingame[NET_MAXPLAYERS];
 } ticcmd_set_t;
 
 //
@@ -113,7 +113,7 @@
 // This is distinct from playeringame[] used by the game code, which may
 // modify playeringame[] when playing back multiplayer demos.
 
-static boolean local_playeringame[MAXPLAYERS];
+static boolean local_playeringame[NET_MAXPLAYERS];
 
 
 // 35 fps clock adjusted by offsetms milliseconds
@@ -282,7 +282,7 @@
         return;
     }
 
-    for (i = 0; i < MAXPLAYERS; ++i)
+    for (i = 0; i < NET_MAXPLAYERS; ++i)
     {
         if (!drone && i == localplayer)
         {
@@ -457,7 +457,7 @@
 
     localplayer = settings->consoleplayer;
 
-    for (i = 0; i < MAXPLAYERS; ++i)
+    for (i = 0; i < NET_MAXPLAYERS; ++i)
     {
         local_playeringame[i] = i < settings->num_players;
     }
@@ -524,7 +524,7 @@
     // ideally maketic should be 1 - 3 tics above lowtic
     // if we are consistantly slower, speed up time
 
-    for (i=0 ; i<MAXPLAYERS ; i++)
+    for (i=0 ; i<NET_MAXPLAYERS ; i++)
     {
         if (local_playeringame[i])
         {
@@ -575,7 +575,7 @@
 
     if (net_client_connected)
     {
-        for (i = 0; i < MAXPLAYERS; ++i)
+        for (i = 0; i < NET_MAXPLAYERS; ++i)
         {
             result = result || local_playeringame[i];
         }
@@ -600,7 +600,7 @@
     ticcmd_t *cmd;
     unsigned int i;
 
-    for (i = 0; i < MAXPLAYERS ; ++i)
+    for (i = 0; i < NET_MAXPLAYERS ; ++i)
     {
         cmd = &set->cmds[i];
         cmd->chatchar = 0;
@@ -616,7 +616,7 @@
 {
     unsigned int i;
 
-    for (i = 0; i < MAXPLAYERS; ++i)
+    for (i = 0; i < NET_MAXPLAYERS; ++i)
     {
         if (i != localplayer)
         {
@@ -750,4 +750,3 @@
 {
     loop_interface = i;
 }
-
--- a/src/doom/doomdef.h
+++ b/src/doom/doomdef.h
@@ -49,6 +49,9 @@
 // most parameter validation debugging code will not be compiled
 #define RANGECHECK
 
+// The maximum number of players, multiplayer/networking.
+#define MAXPLAYERS 4
+
 // The current state of the game: whether we are
 // playing, gazing at the intermission screen,
 // the game final animation, or a demo. 
@@ -171,4 +174,3 @@
 } powerduration_t;
 
 #endif          // __DOOMDEF__
-
--- a/src/heretic/doomdef.h
+++ b/src/heretic/doomdef.h
@@ -78,6 +78,7 @@
 */
 
 #define NUMARTIFCTS	28
+#define MAXPLAYERS	4
 
 #define	BT_ATTACK		1
 #define	BT_USE			2
--- a/src/hexen/g_game.c
+++ b/src/hexen/g_game.c
@@ -1815,6 +1815,7 @@
         playeringame[i] = *demo_p++;
         PlayerClass[i] = *demo_p++;
     }
+    demo_p += 8;
 
     // Initialize world info, etc.
     G_StartNewInit();
--- a/src/hexen/h2def.h
+++ b/src/hexen/h2def.h
@@ -98,6 +98,7 @@
 */
 
 //#define NUMARTIFCTS   28
+#define MAXPLAYERS	8
 
 #define	BT_ATTACK		1
 #define	BT_USE			2
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -118,37 +118,8 @@
 
 boolean net_client_received_wait_data;
 
-// if true, this client is the controller of the game
+net_waitdata_t net_client_wait_data;
 
-boolean net_client_controller = false;
-
-// Number of clients currently connected to the server
-
-unsigned int net_clients_in_game;
-
-// Number of drone players connected to the server
-
-unsigned int net_drones_in_game;
-
-// Names of all players
-
-char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
-char net_player_names[MAXPLAYERS][MAXPLAYERNAME];
-
-// MD5 checksums of the wad directory and dehacked data that the server
-// has sent to us.
-
-md5_digest_t net_server_wad_md5sum;
-md5_digest_t net_server_deh_md5sum;
-
-// Is the server a freedoom game?
-
-unsigned int net_server_is_freedoom;
-
-// Player number
-
-int net_player_number;
-
 // Waiting for the game to start?
 
 boolean net_waiting_for_start = false;
@@ -171,7 +142,7 @@
 
 // Receive window
 
-static ticcmd_t recvwindow_cmd_base[MAXPLAYERS];
+static ticcmd_t recvwindow_cmd_base[NET_MAXPLAYERS];
 static int recvwindow_start;
 static net_server_recv_t recvwindow[BACKUPTICS];
 
@@ -269,7 +240,7 @@
 
     // Expand tic diffs for all players
     
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (i == settings.consoleplayer && !drone)
         {
@@ -298,7 +269,7 @@
 
 static void NET_CL_AdvanceWindow(void)
 {
-    ticcmd_t ticcmds[MAXPLAYERS];
+    ticcmd_t ticcmds[NET_MAXPLAYERS];
 
     while (recvwindow[0].active)
     {
@@ -456,27 +427,16 @@
 
 static void NET_CL_ParseWaitingData(net_packet_t *packet)
 {
-    unsigned int num_players;
-    unsigned int num_drones;
-    unsigned int is_controller;
-    signed int player_number;
-    char *player_names[MAXPLAYERS];
-    char *player_addr[MAXPLAYERS];
-    md5_digest_t wad_md5sum, deh_md5sum;
-    unsigned int server_is_freedoom;
-    size_t i;
+    net_waitdata_t wait_data;
 
-    if (!NET_ReadInt8(packet, &num_players)
-     || !NET_ReadInt8(packet, &num_drones)
-     || !NET_ReadInt8(packet, &is_controller)
-     || !NET_ReadSInt8(packet, &player_number))
+    if (!NET_ReadWaitData(packet, &wait_data))
     {
-        // invalid packet
-
+        // Invalid packet?
         return;
     }
 
-    if (num_players > MAXPLAYERS)
+    if (wait_data.num_players > wait_data.max_players
+     || wait_data.max_players > NET_MAXPLAYERS)
     {
         // insane data
 
@@ -483,52 +443,16 @@
         return;
     }
 
-    if ((player_number >= 0 && drone)
-     || (player_number < 0 && !drone)
-     || (player_number >= (signed int) num_players))
+    if ((wait_data.consoleplayer >= 0 && drone)
+     || (wait_data.consoleplayer < 0 && !drone)
+     || (wait_data.consoleplayer >= wait_data.num_players))
     {
         // Invalid player number
 
         return;
     }
- 
-    // Read the player names
 
-    for (i=0; i<num_players; ++i)
-    {
-        player_names[i] = NET_ReadString(packet);
-        player_addr[i] = NET_ReadString(packet);
-
-        if (player_names[i] == NULL || player_addr[i] == NULL)
-        {
-            return;
-        }
-    }
-
-    if (!NET_ReadMD5Sum(packet, wad_md5sum)
-     || !NET_ReadMD5Sum(packet, deh_md5sum)
-     || !NET_ReadInt8(packet, &server_is_freedoom))
-    {
-        return;
-    }
-
-    net_clients_in_game = num_players;
-    net_drones_in_game = num_drones;
-    net_client_controller = is_controller != 0;
-    net_player_number = player_number;
-
-    for (i=0; i<num_players; ++i)
-    {
-        strncpy(net_player_names[i], player_names[i], MAXPLAYERNAME);
-        net_player_names[i][MAXPLAYERNAME-1] = '\0';
-        strncpy(net_player_addresses[i], player_addr[i], MAXPLAYERNAME);
-        net_player_addresses[i][MAXPLAYERNAME-1] = '\0';
-    }
-
-    memcpy(net_server_wad_md5sum, wad_md5sum, sizeof(md5_digest_t));
-    memcpy(net_server_deh_md5sum, deh_md5sum, sizeof(md5_digest_t));
-    net_server_is_freedoom = server_is_freedoom;
-
+    memcpy(&net_client_wait_data, &wait_data, sizeof(net_waitdata_t));
     net_client_received_wait_data = true;
 }
 
@@ -544,7 +468,7 @@
         return;
     }
 
-    if (settings.num_players > MAXPLAYERS
+    if (settings.num_players > NET_MAXPLAYERS
      || settings.consoleplayer >= (signed int) settings.num_players)
     {
         // insane values
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -29,8 +29,6 @@
 #include "md5.h"
 #include "net_defs.h"
 
-#define MAXPLAYERNAME 30
-
 boolean NET_CL_Connect(net_addr_t *addr, net_connect_data_t *data);
 void NET_CL_Disconnect(void);
 void NET_CL_Run(void);
@@ -44,13 +42,8 @@
 
 extern boolean net_client_connected;
 extern boolean net_client_received_wait_data;
-extern boolean net_client_controller;
-extern unsigned int net_clients_in_game;
-extern unsigned int net_drones_in_game;
+extern net_waitdata_t net_client_wait_data;
 extern boolean net_waiting_for_start;
-extern char net_player_names[MAXPLAYERS][MAXPLAYERNAME];
-extern char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
-extern int net_player_number;
 extern char *net_player_name;
 
 extern md5_digest_t net_server_wad_md5sum;
@@ -63,4 +56,3 @@
 extern boolean drone;
 
 #endif /* #ifndef NET_CLIENT_H */
-
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -33,18 +33,24 @@
 #include "md5.h"
 
 // Absolute maximum number of "nodes" in the game.  This is different to
-// MAXPLAYERS, as there may be observers that are not participating
+// NET_MAXPLAYERS, as there may be observers that are not participating
 // (eg. left/right monitors)
 
 #define MAXNETNODES 16
 
 // The maximum number of players, multiplayer/networking.
+// This is the maximum supported by the networking code; individual games
+// have their own values for MAXPLAYERS that can be smaller.
 
-#define MAXPLAYERS		4
+#define NET_MAXPLAYERS 8
 
+// Maximum length of a player's name.
+
+#define MAXPLAYERNAME 30
+
 // Networking and tick handling related.
 
-#define BACKUPTICS		128
+#define BACKUPTICS 128
 
 typedef struct _net_module_s net_module_t;
 typedef struct _net_packet_s net_packet_t;
@@ -179,7 +185,7 @@
 
     // Hexen player classes:
 
-    int player_classes[MAXPLAYERS];
+    int player_classes[NET_MAXPLAYERS];
 
 } net_gamesettings_t;
 
@@ -204,8 +210,8 @@
 {
     signed int latency;
     unsigned int seq;
-    boolean playeringame[MAXPLAYERS];
-    net_ticdiff_t cmds[MAXPLAYERS];
+    boolean playeringame[NET_MAXPLAYERS];
+    net_ticdiff_t cmds[NET_MAXPLAYERS];
 } net_full_ticcmd_t;
 
 // Data sent in response to server queries
@@ -220,5 +226,21 @@
     int gamemission;
     char *description;
 } net_querydata_t;
+
+// Data sent by the server while waiting for the game to start.
+
+typedef struct
+{
+    int num_players;
+    int num_drones;
+    int max_players;
+    int is_controller;
+    int consoleplayer;
+    char player_names[NET_MAXPLAYERS][MAXPLAYERNAME];
+    char player_addrs[NET_MAXPLAYERS][MAXPLAYERNAME];
+    md5_digest_t wad_md5sum;
+    md5_digest_t deh_md5sum;
+    int is_freedoom;
+} net_waitdata_t;
 
 #endif /* #ifndef NET_DEFS_H */
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -42,8 +42,8 @@
 #include "textscreen.h"
 
 static txt_window_t *window;
-static txt_label_t *player_labels[MAXPLAYERS];
-static txt_label_t *ip_labels[MAXPLAYERS];
+static txt_label_t *player_labels[NET_MAXPLAYERS];
+static txt_label_t *ip_labels[NET_MAXPLAYERS];
 static txt_label_t *drone_label;
 static boolean had_warning;
 
@@ -83,7 +83,7 @@
 
     // Player labels
     
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         sprintf(buf, " %i. ", i + 1);
         TXT_AddWidget(table, TXT_NewLabel(buf));
@@ -109,11 +109,11 @@
     char buf[50];
     unsigned int i;
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         txt_color_t color = TXT_COLOR_BRIGHT_WHITE;
 
-        if ((signed) i == net_player_number)
+        if ((signed) i == net_client_wait_data.consoleplayer)
         {
             color = TXT_COLOR_YELLOW;
         }
@@ -121,10 +121,12 @@
         TXT_SetFGColor(player_labels[i], color);
         TXT_SetFGColor(ip_labels[i], color);
 
-        if (i < net_clients_in_game)
+        if (i < net_client_wait_data.num_players)
         {
-            TXT_SetLabel(player_labels[i], net_player_names[i]);
-            TXT_SetLabel(ip_labels[i], net_player_addresses[i]);
+            TXT_SetLabel(player_labels[i],
+                         net_client_wait_data.player_names[i]);
+            TXT_SetLabel(ip_labels[i],
+                         net_client_wait_data.player_addrs[i]);
         }
         else
         {
@@ -133,9 +135,10 @@
         }
     }
 
-    if (net_drones_in_game > 0)
+    if (net_client_wait_data.num_drones > 0)
     {
-        sprintf(buf, " (+%i observer clients)", net_drones_in_game);
+        sprintf(buf, " (+%i observer clients)",
+                     net_client_wait_data.num_drones);
         TXT_SetLabel(drone_label, buf);
     }
     else
@@ -143,7 +146,7 @@
         TXT_SetLabel(drone_label, "");
     }
 
-    if (net_client_controller)
+    if (net_client_wait_data.is_controller)
     {
         startgame = TXT_NewWindowAction(' ', "Start game");
         TXT_SignalConnect(startgame, "pressed", StartGame, settings);
@@ -181,11 +184,13 @@
         return;
     }
 
-    correct_wad = memcmp(net_local_wad_md5sum, net_server_wad_md5sum, 
+    correct_wad = memcmp(net_local_wad_md5sum,
+                         net_client_wait_data.wad_md5sum, 
                          sizeof(md5_digest_t)) == 0;
-    correct_deh = memcmp(net_local_deh_md5sum, net_server_deh_md5sum, 
+    correct_deh = memcmp(net_local_deh_md5sum,
+                         net_client_wait_data.deh_md5sum, 
                          sizeof(md5_digest_t)) == 0;
-    same_freedoom = net_server_is_freedoom == net_local_is_freedoom;
+    same_freedoom = net_client_wait_data.is_freedoom == net_local_is_freedoom;
 
     if (correct_wad && correct_deh && same_freedoom)
     {
@@ -196,7 +201,7 @@
     {
         printf("Warning: WAD MD5 does not match server:\n");
         PrintMD5Digest("Local", net_local_wad_md5sum);
-        PrintMD5Digest("Server", net_server_wad_md5sum);
+        PrintMD5Digest("Server", net_client_wait_data.wad_md5sum);
     }
 
     if (!same_freedoom)
@@ -204,7 +209,7 @@
         printf("Warning: Mixing Freedoom with non-Freedoom\n");
         printf("Local: %i  Server: %i\n", 
                net_local_is_freedoom, 
-               net_server_is_freedoom);
+               net_client_wait_data.is_freedoom);
     }
 
     if (!correct_deh)
@@ -211,7 +216,7 @@
     {
         printf("Warning: Dehacked MD5 does not match server:\n");
         PrintMD5Digest("Local", net_local_deh_md5sum);
-        PrintMD5Digest("Server", net_server_deh_md5sum);
+        PrintMD5Digest("Server", net_client_wait_data.deh_md5sum);
     }
 
     window = TXT_NewWindow("WARNING");
@@ -295,4 +300,3 @@
     
     TXT_Shutdown();
 }
-
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -136,7 +136,7 @@
 static net_server_state_t server_state;
 static boolean server_initialized = false;
 static net_client_t clients[MAXNETNODES];
-static net_client_t *sv_players[MAXPLAYERS];
+static net_client_t *sv_players[NET_MAXPLAYERS];
 static net_context_t *server_context;
 static unsigned int sv_gamemode;
 static unsigned int sv_gamemission;
@@ -150,7 +150,7 @@
 // receive window
 
 static unsigned int recvwindow_start;
-static net_client_recv_t recvwindow[BACKUPTICS][MAXPLAYERS];
+static net_client_recv_t recvwindow[BACKUPTICS][NET_MAXPLAYERS];
 
 #define NET_SV_ExpandTicNum(b) NET_ExpandTicNum(recvwindow_start, (b))
 
@@ -239,7 +239,7 @@
         }
     }
 
-    for (; pl<MAXPLAYERS; ++pl)
+    for (; pl<NET_MAXPLAYERS; ++pl)
     {
         sv_players[pl] = NULL;
     }
@@ -254,7 +254,7 @@
 
     result = 0;
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (sv_players[i] != NULL && ClientConnected(sv_players[i]))
         {
@@ -354,7 +354,7 @@
         
         should_advance = true;
 
-        for (i=0; i<MAXPLAYERS; ++i)
+        for (i=0; i<NET_MAXPLAYERS; ++i)
         {
             if (sv_players[i] == NULL || !ClientConnected(sv_players[i]))
             {
@@ -599,7 +599,7 @@
         NET_SV_AssignPlayers();
         num_players = NET_SV_NumPlayers();
 
-        if ((!data.drone && num_players >= MAXPLAYERS)
+        if ((!data.drone && num_players >= NET_MAXPLAYERS)
          || NET_SV_NumClients() >= MAXNETNODES)
         {
             NET_SV_SendReject(addr, "Server is full!");
@@ -694,7 +694,7 @@
 
     settings.lowres_turn = false;
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (sv_players[i] != NULL && sv_players[i]->recording_lowres)
         {
@@ -706,7 +706,7 @@
 
     // Copy player classes:
 
-    for (i = 0; i < MAXPLAYERS; ++i)
+    for (i = 0; i < NET_MAXPLAYERS; ++i)
     {
         if (sv_players[i] != NULL)
         {
@@ -1120,7 +1120,7 @@
     // Number of players/maximum players
 
     querydata.num_players = NET_SV_NumPlayers();
-    querydata.max_players = MAXPLAYERS;
+    querydata.max_players = NET_MAXPLAYERS;
 
     // Game mode/mission
 
@@ -1234,9 +1234,9 @@
 
 static void NET_SV_SendWaitingData(net_client_t *client)
 {
+    net_waitdata_t wait_data;
     net_packet_t *packet;
     net_client_t *controller;
-    int num_players;
     int i;
 
     NET_SV_AssignPlayers();
@@ -1243,62 +1243,49 @@
 
     controller = NET_SV_Controller();
 
-    num_players = NET_SV_NumPlayers();
+    wait_data.num_players = NET_SV_NumPlayers();
+    wait_data.num_drones = NET_SV_NumDrones();
+    wait_data.max_players = NET_MAXPLAYERS;
+    wait_data.is_controller = (client == controller);
+    wait_data.consoleplayer = client->player_number;
 
-    // time to send the client another status packet
+    // Send the WAD and dehacked checksums of the controlling client.
+    // If no controller found (?), send the details that the client
+    // is expecting anyway.
 
-    packet = NET_NewPacket(10);
-    NET_WriteInt16(packet, NET_PACKET_TYPE_WAITING_DATA);
+    if (controller != NULL)
+    {
+        controller = client;
+    }
 
-    // include the number of players waiting
+    memcpy(&wait_data.wad_md5sum, &controller->wad_md5sum,
+           sizeof(md5_digest_t));
+    memcpy(&wait_data.deh_md5sum, &controller->deh_md5sum,
+           sizeof(md5_digest_t));
+    wait_data.is_freedoom = controller->is_freedoom;
 
-    NET_WriteInt8(packet, num_players);
+    // set name and address of each player:
 
-    // send the number of drone clients
-
-    NET_WriteInt8(packet, NET_SV_NumDrones());
-
-    // indicate whether the client is the controller
-
-    NET_WriteInt8(packet, client == controller);
-
-    // send the player number of this client
-
-    NET_WriteInt8(packet, client->player_number);
-
-    // send the addresses of all players
-
-    for (i=0; i<num_players; ++i)
+    for (i = 0; i < wait_data.num_players; ++i)
     {
-        char *addr;
+        strncpy(wait_data.player_names[i],
+                sv_players[i]->name,
+                MAXPLAYERNAME);
+        wait_data.player_names[i][MAXPLAYERNAME-1] = '\0';
 
-        // name
-
-        NET_WriteString(packet, sv_players[i]->name);
-
-        // address
-
-        addr = NET_AddrToString(sv_players[i]->addr);
-
-        NET_WriteString(packet, addr);
+        strncpy(wait_data.player_addrs[i],
+                NET_AddrToString(sv_players[i]->addr),
+                MAXPLAYERNAME);
+        wait_data.player_addrs[i][MAXPLAYERNAME-1] = '\0';
     }
 
-    // Send the WAD and dehacked checksums of the controlling client.
+    // Construct packet:
 
-    if (controller != NULL)
-    {
-        NET_WriteMD5Sum(packet, controller->wad_md5sum);
-        NET_WriteMD5Sum(packet, controller->deh_md5sum);
-        NET_WriteInt8(packet, controller->is_freedoom);
-    }
-    else
-    {
-        NET_WriteMD5Sum(packet, client->wad_md5sum);
-        NET_WriteMD5Sum(packet, client->deh_md5sum);
-        NET_WriteInt8(packet, client->is_freedoom);
-    }
+    packet = NET_NewPacket(10);
+    NET_WriteInt16(packet, NET_PACKET_TYPE_WAITING_DATA);
+    NET_WriteWaitData(packet, &wait_data);
 
-    // send packet to client and free
+    // Send packet to client and free
 
     NET_Conn_SendPacket(&client->connection, packet);
     NET_FreePacket(packet);
@@ -1334,7 +1321,7 @@
 
     num_players = 0;
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (sv_players[i] == client)
         {
@@ -1380,7 +1367,7 @@
 
     cmd.latency = 0;
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         net_client_recv_t *recvobj;
 
@@ -1660,7 +1647,7 @@
     {
         NET_SV_AdvanceWindow();
 
-        for (i=0; i<MAXPLAYERS; ++i)
+        for (i=0; i<NET_MAXPLAYERS; ++i)
         {
             if (sv_players[i] != NULL && ClientConnected(sv_players[i]))
             {
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -31,34 +31,6 @@
 #include "net_packet.h"
 #include "net_structrw.h"
 
-static void NET_WriteMD5(net_packet_t *packet, md5_digest_t digest)
-{
-    int i;
-
-    for (i = 0; i < sizeof(md5_digest_t); ++i)
-    {
-        NET_WriteInt8(packet, digest[i]);
-    }
-}
-
-static boolean NET_ReadMD5(net_packet_t *packet, md5_digest_t digest)
-{
-    unsigned int val;
-    int i;
-
-    for (i = 0; i < sizeof(md5_digest_t); ++i)
-    {
-        if (!NET_ReadInt8(packet, &val))
-        {
-            return false;
-        }
-
-        digest[i] = (uint8_t) val;
-    }
-
-    return true;
-}
-
 void NET_WriteConnectData(net_packet_t *packet, net_connect_data_t *data)
 {
     NET_WriteInt8(packet, data->gamemode);
@@ -66,8 +38,8 @@
     NET_WriteInt8(packet, data->lowres_turn);
     NET_WriteInt8(packet, data->drone);
     NET_WriteInt8(packet, data->is_freedoom);
-    NET_WriteMD5(packet, data->wad_md5sum);
-    NET_WriteMD5(packet, data->deh_md5sum);
+    NET_WriteMD5Sum(packet, data->wad_md5sum);
+    NET_WriteMD5Sum(packet, data->deh_md5sum);
     NET_WriteInt8(packet, data->player_class);
 }
 
@@ -78,8 +50,8 @@
         && NET_ReadInt8(packet, (unsigned int *) &data->lowres_turn)
         && NET_ReadInt8(packet, (unsigned int *) &data->drone)
         && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom)
-        && NET_ReadMD5(packet, data->wad_md5sum)
-        && NET_ReadMD5(packet, data->deh_md5sum)
+        && NET_ReadMD5Sum(packet, data->wad_md5sum)
+        && NET_ReadMD5Sum(packet, data->deh_md5sum)
         && NET_ReadInt8(packet, (unsigned int *) &data->player_class);
 }
 
@@ -415,7 +387,7 @@
         return false;
     }
           
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         cmd->playeringame[i] = (bitfield & (1 << i)) != 0;
     }
@@ -422,7 +394,7 @@
         
     // Read cmds
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (cmd->playeringame[i])
         {
@@ -450,7 +422,7 @@
 
     bitfield = 0;
     
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (cmd->playeringame[i])
         {
@@ -462,7 +434,7 @@
 
     // Write player ticcmds
 
-    for (i=0; i<MAXPLAYERS; ++i)
+    for (i=0; i<NET_MAXPLAYERS; ++i)
     {
         if (cmd->playeringame[i])
         {
@@ -469,6 +441,67 @@
             NET_WriteTiccmdDiff(packet, &cmd->cmds[i], lowres_turn);
         }
     }
+}
+
+void NET_WriteWaitData(net_packet_t *packet, net_waitdata_t *data)
+{
+    int i;
+
+    NET_WriteInt8(packet, data->num_players);
+    NET_WriteInt8(packet, data->num_drones);
+    NET_WriteInt8(packet, data->max_players);
+    NET_WriteInt8(packet, data->is_controller);
+    NET_WriteInt8(packet, data->consoleplayer);
+
+    for (i = 0; i < data->num_players && i < NET_MAXPLAYERS; ++i)
+    {
+        NET_WriteString(packet, data->player_names[i]);
+        NET_WriteString(packet, data->player_addrs[i]);
+    }
+
+    NET_WriteMD5Sum(packet, data->wad_md5sum);
+    NET_WriteMD5Sum(packet, data->deh_md5sum);
+    NET_WriteInt8(packet, data->is_freedoom);
+}
+
+boolean NET_ReadWaitData(net_packet_t *packet, net_waitdata_t *data)
+{
+    int i;
+    char *s;
+
+    if (!NET_ReadInt8(packet, (unsigned int *) &data->num_players)
+     || !NET_ReadInt8(packet, (unsigned int *) &data->num_drones)
+     || !NET_ReadInt8(packet, (unsigned int *) &data->max_players)
+     || !NET_ReadInt8(packet, (unsigned int *) &data->is_controller)
+     || !NET_ReadSInt8(packet, (unsigned int *) &data->consoleplayer))
+    {
+        return false;
+    }
+
+    for (i = 0; i < data->num_players && i < NET_MAXPLAYERS; ++i)
+    {
+        s = NET_ReadString(packet);
+
+        if (s == NULL || strlen(s) >= MAXPLAYERNAME)
+        {
+            return false;
+        }
+
+        strcpy(data->player_names[i], s);
+
+        s = NET_ReadString(packet);
+
+        if (s == NULL || strlen(s) >= MAXPLAYERNAME)
+        {
+            return false;
+        }
+
+        strcpy(data->player_addrs[i], s);
+    }
+
+    return NET_ReadMD5Sum(packet, data->wad_md5sum)
+        && NET_ReadMD5Sum(packet, data->deh_md5sum)
+        && NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom);
 }
 
 boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest)
--- a/src/net_structrw.h
+++ b/src/net_structrw.h
@@ -46,7 +46,9 @@
 boolean NET_ReadMD5Sum(net_packet_t *packet, md5_digest_t digest);
 void NET_WriteMD5Sum(net_packet_t *packet, md5_digest_t digest);
 
+void NET_WriteWaitData(net_packet_t *packet, net_waitdata_t *data);
+boolean NET_ReadWaitData(net_packet_t *packet, net_waitdata_t *data);
+
 void NET_SafePuts(char *msg);
 
 #endif /* #ifndef NET_STRUCTRW_H */
-
--- a/src/strife/doomdef.h
+++ b/src/strife/doomdef.h
@@ -47,6 +47,9 @@
 #define DOOM_191_VERSION 111
 
 
+// Maximum players for Strife:
+#define MAXPLAYERS 8
+
 // If rangecheck is undefined,
 // most parameter validation debugging code will not be compiled
 #define RANGECHECK
@@ -294,4 +297,3 @@
 } powerduration_t;
 
 #endif          // __DOOMDEF__
-