From 6ca5497cfbd7edfaf1c2e9af5eadda0a5ef606ba Mon Sep 17 00:00:00 2001 From: Daniel Aquino Date: Sun, 2 Oct 2022 20:21:10 -0400 Subject: [PATCH 1/2] update version.h to support easy build flags --- main_sdl.c | 2 +- net_tracker.c | 5 +-- networking.c | 8 ++--- version.h | 87 ++++++++++++++++++++++++++++++++++----------------- 4 files changed, 66 insertions(+), 36 deletions(-) diff --git a/main_sdl.c b/main_sdl.c index 2fa32929..f4d5c44f 100644 --- a/main_sdl.c +++ b/main_sdl.c @@ -294,7 +294,7 @@ static void set_window_title( void ) // this is now done in CreateWindow #if !SDL_VERSION_ATLEAST(2,0,0) // window title, icon title (taskbar and other places) - SDL_WM_SetCaption(PXVersion,"ProjectX"); + SDL_WM_SetCaption(PX_VERSION_STR,"ProjectX"); #endif } diff --git a/net_tracker.c b/net_tracker.c index 8fe7a7cd..78824d93 100644 --- a/net_tracker.c +++ b/net_tracker.c @@ -42,13 +42,14 @@ static void send_tracker_message( char* host, int port, char* message ); // 13 = hosting + white space + null byte // +1 = comma for separating names #define MAX_PORT 5 -#define MAX_HOSTING_MSG (MAX_PORT + (MAXSHORTNAME+1) * MAX_PLAYERS + MAX_PXVersion + MAX_SHORT_LEVEL_NAME + 13) +#define MAX_PX_VERSION_STR 100 +#define MAX_HOSTING_MSG (MAX_PORT + (MAXSHORTNAME+1) * MAX_PLAYERS + MAX_PX_VERSION_STR + MAX_SHORT_LEVEL_NAME + 13) void send_tracker_update( char* host, int port ) { int i; char message[ MAX_HOSTING_MSG ]; - sprintf(message,"hosting %d %s %s",my_local_port,PXVersion,my_player_name); + sprintf(message,"hosting %d %s %s",my_local_port,PX_VERSION_STR,my_player_name); for(i=0; iMsgCode = msg; lpHereIAm->WhoIAm = WhoIAm; - lpHereIAm->MPVersion = PXMPVINT; + lpHereIAm->MPVersion = PX_VERSION_NETWORK_COMPAT_INT; nBytes = sizeof( HEREIAMMSG ); flags |= NETWORK_RELIABLE; break; @@ -3575,7 +3575,7 @@ void SendGameMessage( BYTE msg, network_player_t * to, BYTE ShipNum, BYTE Type, // Check player has right version to join the game // - if( PXMPVINT != mask ) + if( PX_VERSION_NETWORK_COMPAT_INT != mask ) { lpInit->YouAre = MAX_PLAYERS+3; // bad version goto send; diff --git a/version.h b/version.h index ba098480..7a70c39f 100644 --- a/version.h +++ b/version.h @@ -1,49 +1,78 @@ #ifndef VERSION_HEADER #define VERSION_HEADER -// major version -#define PXV "1" +// +// These are some helpers that make us able to concat values as desired +// -// multiplayer version (increase if you break multiplayer compatibility) -#define PXMPV "18" +// you need 2 levels of indirection to make things work right +// https://stackoverflow.com/questions/1489932/how-can-i-concatenate-twice-with-the-c-preprocessor-and-expand-a-macro-as-in-ar -// multiplayer compatibility flag - // TODO: use this format in future for now hard coded to existing format - //#define PXMPVINT PXV.PXMPV -#define PXMPVINT 118 +// combine two raw snippets into one +#define CONCAT2(a,b) a ## b +#define CONCAT(a,b) CONCAT2(a,b) -// revision (should be provided at build time for official builds) -// make PXRV=$(svn info | grep Revision | awk '{print $NF}') -#ifndef PXRV - #define PXRV "0" +// wraps a value as a string +#define STR2(x) #x +#define STR(x) STR2(x) + + + +// +// Version information +// +// +// The basic versioning premis is: +// +// major.network.build-platform-arch +// +// major = major version +// network = network compatability (bump on breaking changes) +// build = incremental build version +// platform = windows/linux/mac/etc. +// arch = 32/64bit +// + +#ifndef VERSION_MAJOR + #define VERSION_MAJOR 1 +#endif + +#ifndef VERSION_NETWORK + #define VERSION_NETWORK 18 +#endif + +#ifndef VERSION_BUILD + #define VERSION_BUILD 0 #endif -// tag name so we know what type of build this is -#ifndef PXBV - #ifdef WIN32 - #ifdef D3D - #define PXBV "D3D9" - #else - #define PXBV "OPEN" - #endif +#ifndef VERSION_PLATFORM + #if defined(WIN32) + #define VERSION_PLATFORM "WINDOWS" #elif defined(MACOSX) - #define PXBV "MACOSX" + #define VERSION_PLATFORM "MACOSX" #else - #define PXBV "LINUX" + #define VERSION_PLATFORM "LINUX" #endif #endif -// architecture #ifdef __i386__ - #define ARCH "32" + #define ARCH "32" #else - #define ARCH "64" + #define ARCH "64" #endif -// the full version name (must contain no spaces for net_tracker) -#define PXVersion "ProjectX-" PXV "." PXMPV "." PXRV "-" PXBV "-" ARCH +// the full stringified version name +// must contain no spaces for net_tracker +#define PX_VERSION_STR \ + "ProjectX-" \ + STR(VERSION_MAJOR) "." \ + STR(VERSION_NETWORK) "." \ + STR(VERSION_BUILD) "-" \ + VERSION_PLATFORM \ + "-" \ + ARCH -// this should be plenty if not please increase this -#define MAX_PXVersion 45 +// the multiplayer version as an integer used for network packets +#define PX_VERSION_NETWORK_COMPAT_INT CONCAT(VERSION_MAJOR, VERSION_NETWORK) #endif From 7db2b158fcd3a25ca2b8549fcf38358ea840b71a Mon Sep 17 00:00:00 2001 From: Daniel Aquino Date: Mon, 3 Oct 2022 03:41:44 -0400 Subject: [PATCH 2/2] sonarqube: fix warning to use snprintf --- net_tracker.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net_tracker.c b/net_tracker.c index 78824d93..3abe5742 100644 --- a/net_tracker.c +++ b/net_tracker.c @@ -49,7 +49,7 @@ void send_tracker_update( char* host, int port ) { int i; char message[ MAX_HOSTING_MSG ]; - sprintf(message,"hosting %d %s %s",my_local_port,PX_VERSION_STR,my_player_name); + snprintf(message,MAX_HOSTING_MSG,"hosting %d %s %s",my_local_port,PX_VERSION_STR,my_player_name); for(i=0; i