summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2006-01-09 01:50:51 +0000
committerSimon Howard2006-01-09 01:50:51 +0000
commit65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7 (patch)
treec4d0036a2808708d2a7c4da7aa5584c0b49f784c
parent2d20dee9798613951023bc570104a6f80f0ef628 (diff)
downloadchocolate-doom-65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7.tar.gz
chocolate-doom-65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7.tar.bz2
chocolate-doom-65c8df250f0a138e22ad70c6ac1c6bf53cfa3ad7.zip
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
-rw-r--r--src/d_main.c13
-rw-r--r--src/m_misc.c11
-rw-r--r--src/net_client.c34
-rw-r--r--src/net_client.h10
-rw-r--r--src/net_server.c25
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 <stdio.h>
#include <stdlib.h>
@@ -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 <stdlib.h>
+
#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 <stdlib.h>
+#include <string.h>
+
#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);
}