ref: 65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7
parent: 2d20dee9798613951023bc570104a6f80f0ef628
author: Simon Howard <[email protected]>
date: Sun Jan 8 20:50:51 EST 2006
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
--- 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 @@
#include "wi_stuff.h"
#include "st_stuff.h"
#include "am_map.h"
+#include "net_client.h"
#include "net_gui.h"
#include "p_setup.h"
@@ -1566,6 +1572,9 @@
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 ();
--- 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 <stdio.h>
#include <stdlib.h>
@@ -112,6 +117,7 @@
#include "m_swap.h"
#include "m_argv.h"
+#include "net_client.h"
#include "w_wad.h"
@@ -382,6 +388,7 @@
{"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 =
--- 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 <stdlib.h>
+
#include "doomdef.h"
#include "doomstat.h"
#include "i_system.h"
@@ -112,7 +119,7 @@
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 @@
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 @@
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);
}
@@ -400,5 +412,23 @@
// Finished sending disconnect packets, etc.
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();
}
--- 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 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 */
--- 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 <stdlib.h>
+#include <string.h>
+
#include "doomdef.h"
#include "doomstat.h"
#include "i_system.h"
@@ -113,6 +121,7 @@
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 @@
{
unsigned int magic;
unsigned int cl_gamemode, cl_gamemission;
+ char *player_name;
int i;
// read the magic number
@@ -242,6 +252,15 @@
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 @@
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 @@
// name
- NET_WriteString(packet, "Player");
+ NET_WriteString(packet, clients[i].name);
// address
@@ -447,6 +467,7 @@
// deactivate and free back
client->active = false;
+ free(client->name);
NET_FreeAddress(client->addr);
}