ref: 845a5d31b27c15f5b61f15e1cfc5f5d305b4878c
parent: a4567e04c7f90f12ae7e2bedf840d80e14409283
author: Simon Howard <fraggle@gmail.com>
date: Wed Oct 19 14:48:53 EDT 2011
Send MAXPLAYERS value for game on connect to server. Make server adapt its player limit to match. Update GUI code to adjust waiting screen list size appropriately. Subversion-branch: /branches/v2-branch Subversion-revision: 2442
--- a/src/doom/d_net.c
+++ b/src/doom/d_net.c
@@ -174,6 +174,7 @@
&& M_CheckParm("-longtics") == 0;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net
--- a/src/heretic/d_net.c
+++ b/src/heretic/d_net.c
@@ -159,10 +159,10 @@
settings->nomonsters = nomonsters;
settings->respawn_monsters = respawnparm;
settings->timelimit = 0;
-
settings->lowres_turn = false;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//
// Connect data
--- a/src/hexen/d_net.c
+++ b/src/hexen/d_net.c
@@ -167,7 +167,6 @@
settings->nomonsters = nomonsters;
settings->respawn_monsters = respawnparm;
settings->timelimit = 0;
-
settings->lowres_turn = false;
//
@@ -181,6 +180,7 @@
connect_data->lowres_turn = false;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -151,6 +151,7 @@
int gamemission;
int lowres_turn;
int drone;
+ int max_players;
int is_freedoom;
md5_digest_t wad_md5sum;
md5_digest_t deh_md5sum;
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -42,6 +42,7 @@
#include "textscreen.h"
static txt_window_t *window;
+static int old_max_players;
static txt_label_t *player_labels[NET_MAXPLAYERS];
static txt_label_t *ip_labels[NET_MAXPLAYERS];
static txt_label_t *drone_label;
@@ -60,18 +61,31 @@
NET_CL_StartGame(settings);
}
-static void BuildGUI(void)
+static void OpenWaitDialog(void)
{
- char buf[50];
- txt_table_t *table;
txt_window_action_t *cancel;
- int i;
-
- had_warning = false;
TXT_SetDesktopTitle(PACKAGE_STRING);
-
+
window = TXT_NewWindow("Waiting for game start...");
+
+ TXT_AddWidget(window, TXT_NewLabel("\nPlease wait...\n\n"));
+
+ cancel = TXT_NewWindowAction(KEY_ESCAPE, "Cancel");
+ TXT_SignalConnect(cancel, "pressed", EscapePressed, NULL);
+
+ TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel);
+
+ old_max_players = 0;
+}
+
+static void BuildWindow(void)
+{
+ char buf[50];
+ txt_table_t *table;
+ int i;
+
+ TXT_ClearTable(window);
table = TXT_NewTable(3);
TXT_AddWidget(window, table);
@@ -82,8 +96,8 @@
TXT_AddWidget(table, TXT_NewStrut(17, 1));
// Player labels
-
- for (i=0; i<NET_MAXPLAYERS; ++i)
+
+ for (i = 0; i < net_client_wait_data.max_players; ++i)
{
sprintf(buf, " %i. ", i + 1);
TXT_AddWidget(table, TXT_NewLabel(buf));
@@ -96,11 +110,6 @@
drone_label = TXT_NewLabel("");
TXT_AddWidget(window, drone_label);
-
- cancel = TXT_NewWindowAction(KEY_ESCAPE, "Cancel");
- TXT_SignalConnect(cancel, "pressed", EscapePressed, NULL);
-
- TXT_SetWindowAction(window, TXT_HORIZ_LEFT, cancel);
}
static void UpdateGUI(net_gamesettings_t *settings)
@@ -109,8 +118,24 @@
char buf[50];
unsigned int i;
- for (i=0; i<NET_MAXPLAYERS; ++i)
+ // If the value of max_players changes, we must rebuild the
+ // contents of the window. This includes when the first
+ // waiting data packet is received.
+
+ if (net_client_received_wait_data)
{
+ if (net_client_wait_data.max_players != old_max_players)
+ {
+ BuildWindow();
+ }
+ }
+ else
+ {
+ return;
+ }
+
+ for (i = 0; i < net_client_wait_data.max_players; ++i)
+ {
txt_color_t color = TXT_COLOR_BRIGHT_WHITE;
if ((signed) i == net_client_wait_data.consoleplayer)
@@ -277,7 +302,8 @@
I_SetWindowTitle("Waiting for game start");
//I_SetWindowIcon();
- BuildGUI();
+ OpenWaitDialog();
+ had_warning = false;
while (net_waiting_for_start)
{
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -93,6 +93,10 @@
unsigned int acknowledged;
+ // Value of max_players specified by the client on connect.
+
+ int max_players;
+
// Observer: receives data but does not participate in the game.
boolean drone;
@@ -265,6 +269,23 @@
return result;
}
+// Returns the maximum number of players that can play.
+
+static int NET_SV_MaxPlayers(void)
+{
+ int i;
+
+ for (i = 0; i < MAXNETNODES; ++i)
+ {
+ if (ClientConnected(&clients[i]))
+ {
+ return clients[i].max_players;
+ }
+ }
+
+ return NET_MAXPLAYERS;
+}
+
// Returns the number of drones currently connected.
static int NET_SV_NumDrones(void)
@@ -537,6 +558,13 @@
return;
}
+ // Check max_players value. This must be in a sensible range.
+
+ if (data.max_players > NET_MAXPLAYERS)
+ {
+ return;
+ }
+
// read the player's name
player_name = NET_ReadString(packet);
@@ -599,7 +627,7 @@
NET_SV_AssignPlayers();
num_players = NET_SV_NumPlayers();
- if ((!data.drone && num_players >= NET_MAXPLAYERS)
+ if ((!data.drone && num_players >= NET_SV_MaxPlayers())
|| NET_SV_NumClients() >= MAXNETNODES)
{
NET_SV_SendReject(addr, "Server is full!");
@@ -623,6 +651,7 @@
memcpy(client->wad_md5sum, data.wad_md5sum, sizeof(md5_digest_t));
memcpy(client->deh_md5sum, data.deh_md5sum, sizeof(md5_digest_t));
client->is_freedoom = data.is_freedoom;
+ client->max_players = data.max_players;
// Check the connecting client is playing the same game as all
// the other clients
@@ -632,7 +661,7 @@
NET_SV_SendReject(addr, "You are playing the wrong game!");
return;
}
-
+
// Activate, initialize connection
NET_SV_InitNewClient(client, addr, player_name);
@@ -1120,7 +1149,7 @@
// Number of players/maximum players
querydata.num_players = NET_SV_NumPlayers();
- querydata.max_players = NET_MAXPLAYERS;
+ querydata.max_players = NET_SV_MaxPlayers();
// Game mode/mission
@@ -1245,7 +1274,7 @@
wait_data.num_players = NET_SV_NumPlayers();
wait_data.num_drones = NET_SV_NumDrones();
- wait_data.max_players = NET_MAXPLAYERS;
+ wait_data.max_players = NET_SV_MaxPlayers();
wait_data.is_controller = (client == controller);
wait_data.consoleplayer = client->player_number;
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -37,6 +37,7 @@
NET_WriteInt8(packet, data->gamemission);
NET_WriteInt8(packet, data->lowres_turn);
NET_WriteInt8(packet, data->drone);
+ NET_WriteInt8(packet, data->max_players);
NET_WriteInt8(packet, data->is_freedoom);
NET_WriteMD5Sum(packet, data->wad_md5sum);
NET_WriteMD5Sum(packet, data->deh_md5sum);
@@ -49,6 +50,7 @@
&& NET_ReadInt8(packet, (unsigned int *) &data->gamemission)
&& NET_ReadInt8(packet, (unsigned int *) &data->lowres_turn)
&& NET_ReadInt8(packet, (unsigned int *) &data->drone)
+ && NET_ReadInt8(packet, (unsigned int *) &data->max_players)
&& NET_ReadInt8(packet, (unsigned int *) &data->is_freedoom)
&& NET_ReadMD5Sum(packet, data->wad_md5sum)
&& NET_ReadMD5Sum(packet, data->deh_md5sum)
--- a/src/strife/d_net.c
+++ b/src/strife/d_net.c
@@ -179,6 +179,7 @@
&& M_CheckParm("-longtics") == 0;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net