From 65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 9 Jan 2006 01:50:51 +0000 Subject: Deduce a sane player name by examining environment variables. Add a "player_name" setting to chocolate-doom.cfg. Transmit the name to the server and use the names players send in the waiting data list. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 277 --- src/d_main.c | 13 +++++++++++-- src/m_misc.c | 11 +++++++++-- src/net_client.c | 34 ++++++++++++++++++++++++++++++++-- src/net_client.h | 10 +++++++++- src/net_server.c | 25 +++++++++++++++++++++++-- 5 files changed, 84 insertions(+), 9 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index c6044bdf..d5a89c47 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: d_main.c 253 2006-01-02 21:52:06Z fraggle $ +// $Id: d_main.c 277 2006-01-09 01:50:51Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -22,6 +22,11 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.36 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 +// to the server and use the names players send in the waiting data list. +// // Revision 1.35 2006/01/02 21:52:06 fraggle // Move I_InitGraphics call to be invoked earlier in D_DoomMain. Call the // NET_WaitForStart function to wait for a start signal in network games. @@ -158,7 +163,7 @@ //----------------------------------------------------------------------------- -static const char rcsid[] = "$Id: d_main.c 253 2006-01-02 21:52:06Z fraggle $"; +static const char rcsid[] = "$Id: d_main.c 277 2006-01-09 01:50:51Z fraggle $"; #define BGCOLOR 7 #define FGCOLOR 8 @@ -211,6 +216,7 @@ static const char rcsid[] = "$Id: d_main.c 253 2006-01-02 21:52:06Z fraggle $"; #include "wi_stuff.h" #include "st_stuff.h" #include "am_map.h" +#include "net_client.h" #include "net_gui.h" #include "p_setup.h" @@ -1567,6 +1573,9 @@ void D_DoomMain (void) printf ("I_Init: Setting up machine state.\n"); I_Init (); + printf ("NET_Init: Initialise network subsystem.\n"); + NET_Init (); + printf ("D_CheckNetGame: Checking network game status.\n"); D_CheckNetGame (); diff --git a/src/m_misc.c b/src/m_misc.c index 8fc01932..8439fdf5 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: m_misc.c 276 2006-01-08 18:22:39Z fraggle $ +// $Id: m_misc.c 277 2006-01-09 01:50:51Z fraggle $ // // Copyright(C) 1993-1996 Id Software, Inc. // Copyright(C) 2005 Simon Howard @@ -23,6 +23,11 @@ // // // $Log$ +// Revision 1.16 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 +// to the server and use the names players send in the waiting data list. +// // Revision 1.15 2006/01/08 18:22:39 fraggle // Strip carriage returns from the end of lines when reading configuration // files. @@ -90,7 +95,7 @@ //----------------------------------------------------------------------------- static const char -rcsid[] = "$Id: m_misc.c 276 2006-01-08 18:22:39Z fraggle $"; +rcsid[] = "$Id: m_misc.c 277 2006-01-09 01:50:51Z fraggle $"; #include #include @@ -112,6 +117,7 @@ rcsid[] = "$Id: m_misc.c 276 2006-01-08 18:22:39Z fraggle $"; #include "m_swap.h" #include "m_argv.h" +#include "net_client.h" #include "w_wad.h" @@ -382,6 +388,7 @@ static default_t extra_defaults_list[] = {"novert", &novert}, {"mouse_acceleration", &mouse_acceleration, DEFAULT_FLOAT}, {"show_endoom", &show_endoom}, + {"player_name", &net_player_name, DEFAULT_STRING}, }; static default_collection_t extra_defaults = diff --git a/src/net_client.c b/src/net_client.c index bb2a60f9..da29d86f 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_client.c 268 2006-01-08 04:52:26Z fraggle $ +// $Id: net_client.c 277 2006-01-09 01:50:51Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,11 @@ // 02111-1307, USA. // // $Log$ +// 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 +// to the server and use the names players send in the waiting data list. +// // Revision 1.13 2006/01/08 04:52:26 fraggle // Allow the server to reject clients // @@ -72,6 +77,8 @@ // Network client code // +#include + #include "doomdef.h" #include "doomstat.h" #include "i_system.h" @@ -112,7 +119,7 @@ boolean net_client_controller = false; int net_clients_in_game; -// Nmaes of all players +// Names of all players char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME]; char net_player_names[MAXPLAYERS][MAXPLAYERNAME]; @@ -121,6 +128,10 @@ char net_player_names[MAXPLAYERS][MAXPLAYERNAME]; boolean net_waiting_for_start = false; +// Name that we send to the server + +char *net_player_name = NULL; + // Shut down the client code, etc. Invoked after a disconnect. static void NET_CL_Shutdown(void) @@ -274,6 +285,7 @@ static void NET_CL_SendSYN(void) NET_WriteInt32(packet, NET_MAGIC_NUMBER); NET_WriteInt16(packet, gamemode); NET_WriteInt16(packet, gamemission); + NET_WriteString(packet, net_player_name); NET_Conn_SendPacket(&client_connection, packet); NET_FreePacket(packet); } @@ -402,3 +414,21 @@ void NET_CL_Disconnect(void) NET_CL_Shutdown(); } +void NET_CL_Init(void) +{ + // Try to set from the USER and USERNAME environment variables + // Otherwise, fallback to "Player" + + if (net_player_name == NULL) + net_player_name = getenv("USER"); + if (net_player_name == NULL) + net_player_name = getenv("USERNAME"); + if (net_player_name == NULL) + net_player_name = "Player"; +} + +void NET_Init(void) +{ + NET_CL_Init(); +} + diff --git a/src/net_client.h b/src/net_client.h index 9200e167..573eae3b 100644 --- a/src/net_client.h +++ b/src/net_client.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_client.h 262 2006-01-07 20:08:11Z fraggle $ +// $Id: net_client.h 277 2006-01-09 01:50:51Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,11 @@ // 02111-1307, USA. // // $Log$ +// 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 +// to the server and use the names players send in the waiting data list. +// // Revision 1.7 2006/01/07 20:08:11 fraggle // Send player name and address in the waiting data packets. Display these // on the waiting screen, and improve the waiting screen appearance. @@ -64,6 +69,8 @@ boolean NET_CL_Connect(net_addr_t *addr); void NET_CL_Disconnect(void); void NET_CL_Run(void); +void NET_CL_Init(void); +void NET_Init(void); extern boolean net_client_connected; extern boolean net_client_controller; @@ -71,6 +78,7 @@ extern int net_clients_in_game; extern boolean net_waiting_for_start; extern char net_player_names[MAXPLAYERS][MAXPLAYERNAME]; extern char net_player_addresses[MAXPLAYERS][MAXPLAYERNAME]; +extern char *net_player_name; #endif /* #ifndef NET_CLIENT_H */ diff --git a/src/net_server.c b/src/net_server.c index 26085f68..070d6b6b 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_server.c 270 2006-01-08 05:06:06Z fraggle $ +// $Id: net_server.c 277 2006-01-09 01:50:51Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,11 @@ // 02111-1307, USA. // // $Log$ +// 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 +// to the server and use the names players send in the waiting data list. +// // Revision 1.16 2006/01/08 05:06:06 fraggle // Reject new connections if the server is not in the waiting state. // @@ -84,6 +89,9 @@ // Network server code // +#include +#include + #include "doomdef.h" #include "doomstat.h" #include "i_system.h" @@ -113,6 +121,7 @@ typedef struct net_addr_t *addr; net_connection_t connection; int last_send_time; + char *name; } net_client_t; static net_server_state_t server_state; @@ -218,6 +227,7 @@ static void NET_SV_ParseSYN(net_packet_t *packet, { unsigned int magic; unsigned int cl_gamemode, cl_gamemission; + char *player_name; int i; // read the magic number @@ -242,6 +252,15 @@ static void NET_SV_ParseSYN(net_packet_t *packet, return; } + // read the player's name + + player_name = NET_ReadString(packet); + + if (player_name == NULL) + { + return; + } + // received a valid SYN // not accepting new connections? @@ -322,6 +341,7 @@ static void NET_SV_ParseSYN(net_packet_t *packet, NET_Conn_InitServer(&client->connection, addr); client->addr = addr; client->last_send_time = -1; + client->name = strdup(player_name); } if (client->connection.state == NET_CONN_STATE_WAITING_ACK) @@ -417,7 +437,7 @@ static void NET_SV_SendWaitingData(net_client_t *client) // name - NET_WriteString(packet, "Player"); + NET_WriteString(packet, clients[i].name); // address @@ -447,6 +467,7 @@ static void NET_SV_RunClient(net_client_t *client) // deactivate and free back client->active = false; + free(client->name); NET_FreeAddress(client->addr); } -- cgit v1.2.3