From af6bdd73396e166417484c2efe4a0eb48aac780e Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 12 Jan 2006 02:11:52 +0000 Subject: Game start packets Subversion-branch: /trunk/chocolate-doom Subversion-revision: 284 --- src/net_client.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/net_client.h | 6 +++++- src/net_gui.c | 11 ++++++++++- src/net_server.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 124 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/net_client.c b/src/net_client.c index 6ff437cb..f70a7c0a 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_client.c 279 2006-01-10 19:59:26Z fraggle $ +// $Id: net_client.c 284 2006-01-12 02:11:52Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.17 2006/01/12 02:11:52 fraggle +// Game start packets +// // Revision 1.16 2006/01/10 19:59:25 fraggle // Reliable packet transport mechanism // @@ -96,6 +99,7 @@ #include "net_io.h" #include "net_packet.h" #include "net_server.h" +#include "net_structrw.h" typedef enum { @@ -157,6 +161,29 @@ static void NET_CL_Shutdown(void) } } +void NET_CL_StartGame(void) +{ + net_packet_t *packet; + net_gamesettings_t settings; + + // Fill in game settings structure with appropriate parameters + // for the new game + + settings.ticdup = 1; + settings.extratics = 0; + settings.deathmatch = deathmatch; + settings.episode = startepisode; + settings.map = startmap; + settings.skill = startskill; + + // Send packet + + packet = NET_Conn_NewReliable(&client_connection, + NET_PACKET_TYPE_GAMESTART); + + NET_WriteSettings(packet, &settings); +} + // data received while we are waiting for the game to start static void NET_CL_ParseWaitingData(net_packet_t *packet) @@ -211,6 +238,36 @@ static void NET_CL_ParseWaitingData(net_packet_t *packet) } } +static void NET_CL_ParseGameStart(net_packet_t *packet) +{ + net_gamesettings_t settings; + unsigned int player_number, num_players; + int i; + + if (!NET_ReadInt8(packet, &player_number) + || !NET_ReadInt8(packet, &num_players) + || !NET_ReadSettings(packet, &settings)) + { + return; + } + + consoleplayer = player_number; + + for (i=0; itype == ev_keydown && ev->data1 == ' ') + { + // Start game + + NET_CL_StartGame(); + } } } diff --git a/src/net_server.c b/src/net_server.c index 0fb058a0..89912028 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_server.c 279 2006-01-10 19:59:26Z fraggle $ +// $Id: net_server.c 284 2006-01-12 02:11:52Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.20 2006/01/12 02:11:52 fraggle +// Game start packets +// // Revision 1.19 2006/01/10 19:59:26 fraggle // Reliable packet transport mechanism // @@ -110,6 +113,7 @@ #include "net_packet.h" #include "net_server.h" #include "net_sdl.h" +#include "net_structrw.h" typedef enum { @@ -137,6 +141,7 @@ static net_client_t clients[MAXNETNODES]; static net_context_t *server_context; static int sv_gamemode; static int sv_gamemission; +static net_gamesettings_t sv_settings; static void NET_SV_DisconnectClient(net_client_t *client) { @@ -383,6 +388,49 @@ static void NET_SV_ParseSYN(net_packet_t *packet, } } +// Parse a game start packet + +static void NET_SV_ParseGameStart(net_packet_t *packet, net_client_t *client) +{ + net_gamesettings_t settings; + net_packet_t *startpacket; + int i; + + if (client != NET_SV_Controller()) + { + // Only the controller can start a new game + + return; + } + + if (!NET_ReadSettings(packet, &settings)) + { + // Malformed packet + + return; + } + + // Change server state + + server_state = SERVER_IN_GAME; + sv_settings = settings; + + // Send start packets to each connected node + + for (i=0; i