From 27055f4b7a9cbb63c5b7e4b77e556c8d13781bdb Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 21 Jan 2006 14:16:49 +0000 Subject: Add first game data sending code. Check the client version when connecting. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 312 --- src/net_client.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- src/net_defs.h | 9 ++++++- src/net_server.c | 21 ++++++++++++++- 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/src/net_client.c b/src/net_client.c index 6d69ea46..ed24c239 100644 --- a/src/net_client.c +++ b/src/net_client.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_client.c 295 2006-01-14 02:06:48Z fraggle $ +// $Id: net_client.c 312 2006-01-21 14:16:49Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.22 2006/01/21 14:16:49 fraggle +// Add first game data sending code. Check the client version when connecting. +// // Revision 1.21 2006/01/14 02:06:48 fraggle // Include the game version in the settings structure. // @@ -101,6 +104,7 @@ #include +#include "config.h" #include "doomdef.h" #include "doomstat.h" #include "i_system.h" @@ -159,6 +163,14 @@ boolean net_waiting_for_start = false; char *net_player_name = NULL; +// The last ticcmd constructed + +static ticcmd_t last_ticcmd; + +// Buffer of ticcmd diffs being sent to the server + +static net_ticdiff_t ticcmd_send_queue[NET_TICCMD_QUEUE_SIZE]; + // Shut down the client code, etc. Invoked after a disconnect. static void NET_CL_Shutdown(void) @@ -189,6 +201,10 @@ void NET_CL_StartGame(void) settings.skill = startskill; settings.gameversion = gameversion; + // Start from a ticcmd of all zeros + + memset(&last_ticcmd, 0, sizeof(ticcmd_t)); + // Send packet packet = NET_Conn_NewReliable(&client_connection, @@ -197,6 +213,66 @@ void NET_CL_StartGame(void) NET_WriteSettings(packet, &settings); } +// Add a new ticcmd to the send queue + +void NET_CL_SendTiccmd(ticcmd_t *ticcmd, int maketic) +{ + net_ticdiff_t diff; + net_packet_t *packet; + int start, end; + int i; + + // Calculate the difference to the last ticcmd + + NET_TiccmdDiff(&last_ticcmd, ticcmd, &diff); + + // Store in the send queue + + ticcmd_send_queue[maketic % NET_TICCMD_QUEUE_SIZE] = diff; + + last_ticcmd = *ticcmd; + + // We need to generate a new packet containing the new ticcmd to send + // to the server. Work out which ticcmds we are sending. + +// start = maketic - extratics; + + if (start < 0) + start = 0; + + end = maketic; + + // Build a new packet to send to the server + + packet = NET_NewPacket(512); + NET_WriteInt16(packet, NET_PACKET_TYPE_GAMEDATA); + + // Write the start tic and number of tics. Send only the low byte + // of start - it can be inferred by the server. + + NET_WriteInt8(packet, start & 0xff); + NET_WriteInt8(packet, end - start + 1); + + // TODO: Include ticcmd construction time for sync. + + // Add the tics. + + for (i=start; i<=end; ++i) + { + NET_WriteTiccmdDiff(packet, + &ticcmd_send_queue[i % NET_TICCMD_QUEUE_SIZE], + false); + } + + // Send the packet + + NET_Conn_SendPacket(&client_connection, packet); + + // All done! + + NET_FreePacket(packet); +} + // data received while we are waiting for the game to start static void NET_CL_ParseWaitingData(net_packet_t *packet) @@ -388,6 +464,7 @@ static void NET_CL_SendSYN(void) NET_WriteInt16(packet, gamemode); NET_WriteInt16(packet, gamemission); NET_WriteString(packet, net_player_name); + NET_WriteString(packet, PACKAGE_STRING); NET_Conn_SendPacket(&client_connection, packet); NET_FreePacket(packet); } diff --git a/src/net_defs.h b/src/net_defs.h index be4ad0df..310bb4ec 100644 --- a/src/net_defs.h +++ b/src/net_defs.h @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_defs.h 295 2006-01-14 02:06:48Z fraggle $ +// $Id: net_defs.h 312 2006-01-21 14:16:49Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.10 2006/01/21 14:16:49 fraggle +// Add first game data sending code. Check the client version when connecting. +// // Revision 1.9 2006/01/14 02:06:48 fraggle // Include the game version in the settings structure. // @@ -119,6 +122,10 @@ struct _net_addr_s void *handle; }; +// number of ticcmds to store in send queues + +#define NET_TICCMD_QUEUE_SIZE 64 + // magic number sent when connecting to check this is a valid client #define NET_MAGIC_NUMBER 3436803284U diff --git a/src/net_server.c b/src/net_server.c index 31ea03ea..a84c53a2 100644 --- a/src/net_server.c +++ b/src/net_server.c @@ -1,7 +1,7 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- // -// $Id: net_server.c 285 2006-01-12 02:18:59Z fraggle $ +// $Id: net_server.c 312 2006-01-21 14:16:49Z fraggle $ // // Copyright(C) 2005 Simon Howard // @@ -21,6 +21,9 @@ // 02111-1307, USA. // // $Log$ +// Revision 1.22 2006/01/21 14:16:49 fraggle +// Add first game data sending code. Check the client version when connecting. +// // Revision 1.21 2006/01/12 02:18:59 fraggle // Only start new games when in the waiting-for-start state. // @@ -105,6 +108,8 @@ #include #include +#include "config.h" + #include "doomdef.h" #include "doomstat.h" #include "i_system.h" @@ -268,6 +273,7 @@ static void NET_SV_ParseSYN(net_packet_t *packet, unsigned int magic; unsigned int cl_gamemode, cl_gamemission; char *player_name; + char *client_version; int i; // read the magic number @@ -300,6 +306,13 @@ static void NET_SV_ParseSYN(net_packet_t *packet, { return; } + + client_version = NET_ReadString(packet); + + if (client_version == NULL) + { + return; + } // received a valid SYN @@ -358,6 +371,12 @@ static void NET_SV_ParseSYN(net_packet_t *packet, return; } + if (strcmp(client_version, PACKAGE_STRING) != 0) + { + NET_SV_SendReject(addr, "Different versions cannot play a network game!"); + return; + } + // Adopt the game mode and mission of the first connecting client if (num_clients == 0) -- cgit v1.2.3