summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2011-10-19 18:48:53 +0000
committerSimon Howard2011-10-19 18:48:53 +0000
commit845a5d31b27c15f5b61f15e1cfc5f5d305b4878c (patch)
tree852113ac1932e2d51ddd3a2fb16829a6bf50180d
parenta4567e04c7f90f12ae7e2bedf840d80e14409283 (diff)
downloadchocolate-doom-845a5d31b27c15f5b61f15e1cfc5f5d305b4878c.tar.gz
chocolate-doom-845a5d31b27c15f5b61f15e1cfc5f5d305b4878c.tar.bz2
chocolate-doom-845a5d31b27c15f5b61f15e1cfc5f5d305b4878c.zip
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
-rw-r--r--src/doom/d_net.c1
-rw-r--r--src/heretic/d_net.c2
-rw-r--r--src/hexen/d_net.c2
-rw-r--r--src/net_defs.h1
-rw-r--r--src/net_gui.c58
-rw-r--r--src/net_server.c37
-rw-r--r--src/net_structrw.c2
-rw-r--r--src/strife/d_net.c1
8 files changed, 82 insertions, 22 deletions
diff --git a/src/doom/d_net.c b/src/doom/d_net.c
index 923d4fcd..137aaf1c 100644
--- a/src/doom/d_net.c
+++ b/src/doom/d_net.c
@@ -174,6 +174,7 @@ static void SaveGameSettings(net_gamesettings_t *settings,
&& M_CheckParm("-longtics") == 0;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net
diff --git a/src/heretic/d_net.c b/src/heretic/d_net.c
index 1eb88b67..6a6a8abb 100644
--- a/src/heretic/d_net.c
+++ b/src/heretic/d_net.c
@@ -159,10 +159,10 @@ static void SaveGameSettings(net_gamesettings_t *settings,
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
diff --git a/src/hexen/d_net.c b/src/hexen/d_net.c
index 94b06fc6..9b26af31 100644
--- a/src/hexen/d_net.c
+++ b/src/hexen/d_net.c
@@ -167,7 +167,6 @@ static void SaveGameSettings(net_gamesettings_t *settings,
settings->nomonsters = nomonsters;
settings->respawn_monsters = respawnparm;
settings->timelimit = 0;
-
settings->lowres_turn = false;
//
@@ -181,6 +180,7 @@ static void SaveGameSettings(net_gamesettings_t *settings,
connect_data->lowres_turn = false;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net
diff --git a/src/net_defs.h b/src/net_defs.h
index 84e82d28..aa7b6f6e 100644
--- a/src/net_defs.h
+++ b/src/net_defs.h
@@ -151,6 +151,7 @@ typedef struct
int gamemission;
int lowres_turn;
int drone;
+ int max_players;
int is_freedoom;
md5_digest_t wad_md5sum;
md5_digest_t deh_md5sum;
diff --git a/src/net_gui.c b/src/net_gui.c
index 781d27c6..7fff33f6 100644
--- 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 @@ static void StartGame(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(settings))
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 @@ static void BuildGUI(void)
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 @@ static void BuildGUI(void)
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,7 +118,23 @@ static void UpdateGUI(net_gamesettings_t *settings)
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;
@@ -277,7 +302,8 @@ void NET_WaitForStart(net_gamesettings_t *settings)
I_SetWindowTitle("Waiting for game start");
//I_SetWindowIcon();
- BuildGUI();
+ OpenWaitDialog();
+ had_warning = false;
while (net_waiting_for_start)
{
diff --git a/src/net_server.c b/src/net_server.c
index 5fec5de1..b837bd70 100644
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -93,6 +93,10 @@ typedef struct
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 @@ static int NET_SV_NumPlayers(void)
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 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
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 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
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 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
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 @@ static void NET_SV_ParseSYN(net_packet_t *packet,
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 @@ void NET_SV_SendQueryResponse(net_addr_t *addr)
// 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 @@ static void NET_SV_SendWaitingData(net_client_t *client)
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;
diff --git a/src/net_structrw.c b/src/net_structrw.c
index 9e7593f4..84c115fa 100644
--- a/src/net_structrw.c
+++ b/src/net_structrw.c
@@ -37,6 +37,7 @@ void NET_WriteConnectData(net_packet_t *packet, net_connect_data_t *data)
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 @@ boolean NET_ReadConnectData(net_packet_t *packet, net_connect_data_t *data)
&& 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)
diff --git a/src/strife/d_net.c b/src/strife/d_net.c
index 15a48873..a8d91136 100644
--- a/src/strife/d_net.c
+++ b/src/strife/d_net.c
@@ -179,6 +179,7 @@ static void SaveGameSettings(net_gamesettings_t *settings,
&& M_CheckParm("-longtics") == 0;
connect_data->drone = false;
+ connect_data->max_players = MAXPLAYERS;
//!
// @category net