ref: fc969e4981a2365304f88e664d625c3a07d57bee
parent: 65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7
author: Simon Howard <fraggle@gmail.com>
date: Sun Jan 8 21:03:39 EST 2006
Send clients their player number, and indicate on the waiting screen which client we are. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 278
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.c 277 2006-01-09 01:50:51Z fraggle $
+// $Id: net_client.c 278 2006-01-09 02:03:39Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.15 2006/01/09 02:03:39 fraggle
+// Send clients their player number, and indicate on the waiting screen
+// which client we are.
+//
// Revision 1.14 2006/01/09 01:50:51 fraggle
// Deduce a sane player name by examining environment variables. Add
// a "player_name" setting to chocolate-doom.cfg. Transmit the name
@@ -124,6 +128,10 @@
char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME];
char net_player_names[MAXPLAYERS][MAXPLAYERNAME];
+// Player number
+
+int net_player_number;
+
// Waiting for the game to start?
boolean net_waiting_for_start = false;
@@ -152,12 +160,14 @@
{
unsigned int num_players;
unsigned int is_controller;
+ unsigned int player_number;
char *player_names[MAXPLAYERS];
char *player_addr[MAXPLAYERS];
int i;
if (!NET_ReadInt8(packet, &num_players)
- || !NET_ReadInt8(packet, &is_controller))
+ || !NET_ReadInt8(packet, &is_controller)
+ || !NET_ReadInt8(packet, &player_number))
{
// invalid packet
@@ -164,9 +174,10 @@
return;
}
- if (num_players > MAXPLAYERS)
+ if (num_players > MAXPLAYERS
+ || player_number >= num_players)
{
- // Invalid number of players
+ // insane data
return;
}
@@ -186,6 +197,7 @@
net_clients_in_game = num_players;
net_client_controller = is_controller != 0;
+ net_player_number = player_number;
for (i=0; i<num_players; ++i)
{
--- a/src/net_client.h
+++ b/src/net_client.h
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_client.h 277 2006-01-09 01:50:51Z fraggle $
+// $Id: net_client.h 278 2006-01-09 02:03:39Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.9 2006/01/09 02:03:39 fraggle
+// Send clients their player number, and indicate on the waiting screen
+// which client we are.
+//
// Revision 1.8 2006/01/09 01:50:51 fraggle
// Deduce a sane player name by examining environment variables. Add
// a "player_name" setting to chocolate-doom.cfg. Transmit the name
@@ -78,6 +82,7 @@
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;
#endif /* #ifndef NET_CLIENT_H */
--- a/src/net_gui.c
+++ b/src/net_gui.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_gui.c 273 2006-01-08 17:52:45Z fraggle $
+// $Id: net_gui.c 278 2006-01-09 02:03:39Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.6 2006/01/09 02:03:39 fraggle
+// Send clients their player number, and indicate on the waiting screen
+// which client we are.
+//
// Revision 1.5 2006/01/08 17:52:45 fraggle
// Play some random music for the players while waiting for the game to
// start.
@@ -107,7 +111,13 @@
for (i=0; i<net_clients_in_game; ++i)
{
V_DrawPatch(32, y, 0, player_backdrops[i]);
- V_DrawPatch(32, y, 0, player_face);
+
+ // draw the face to indicate which one we are
+
+ if (i == net_player_number)
+ {
+ V_DrawPatch(32, y, 0, player_face);
+ }
M_WriteText(80, y+12, net_player_names[i]);
M_WriteText(200, y+12, net_player_addresses[i]);
y += 32;
--- a/src/net_server.c
+++ b/src/net_server.c
@@ -1,7 +1,7 @@
// Emacs style mode select -*- C++ -*-
//-----------------------------------------------------------------------------
//
-// $Id: net_server.c 277 2006-01-09 01:50:51Z fraggle $
+// $Id: net_server.c 278 2006-01-09 02:03:39Z fraggle $
//
// Copyright(C) 2005 Simon Howard
//
@@ -21,6 +21,10 @@
// 02111-1307, USA.
//
// $Log$
+// Revision 1.18 2006/01/09 02:03:39 fraggle
+// Send clients their player number, and indicate on the waiting screen
+// which client we are.
+//
// Revision 1.17 2006/01/09 01:50:51 fraggle
// Deduce a sane player name by examining environment variables. Add
// a "player_name" setting to chocolate-doom.cfg. Transmit the name
@@ -168,6 +172,31 @@
return count;
}
+// Returns the index of a particular client in the list of connected
+// clients.
+
+static int NET_SV_ClientIndex(net_client_t *client)
+{
+ int count;
+ int i;
+
+ count = 0;
+
+ for (i=0; i<MAXNETNODES; ++i)
+ {
+ if (ClientConnected(&clients[i]))
+ {
+ if (client == &clients[i])
+ {
+ return count;
+ }
+ ++count;
+ }
+ }
+
+ return -1;
+}
+
// returns a pointer to the client which controls the server
static net_client_t *NET_SV_Controller(void)
@@ -428,6 +457,10 @@
// indicate whether the client is the controller
NET_WriteInt8(packet, NET_SV_Controller() == client);
+
+ // send the index of the client
+
+ NET_WriteInt8(packet, NET_SV_ClientIndex(client));
// send the address of all players