From d176aefd88166457b2409931d3d637e27bc3af60 Mon Sep 17 00:00:00 2001 From: James R Date: Thu, 29 Sep 2022 12:55:07 -0700 Subject: [PATCH 1/2] Compare git commit when joining netgames in DEVELOP builds --- src/d_clisrv.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/d_clisrv.h | 4 ++++ src/d_main.c | 22 ++++++++++++++++++++++ src/doomdef.h | 11 +++++++++++ 4 files changed, 77 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0613ba13d..a5a8e126b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -895,8 +895,15 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->packettype = PT_SERVERINFO; netbuffer->u.serverinfo._255 = 255; netbuffer->u.serverinfo.packetversion = PACKETVERSION; + +#ifdef DEVELOP + memcpy(netbuffer->u.serverinfo.commit, + comprevision_abbrev_bin, GIT_SHA_ABBREV); +#else netbuffer->u.serverinfo.version = VERSION; netbuffer->u.serverinfo.subversion = SUBVERSION; +#endif + strncpy(netbuffer->u.serverinfo.application, SRB2APPLICATION, sizeof netbuffer->u.serverinfo.application); // return back the time value so client can compute their ping @@ -1404,11 +1411,13 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) if (info->packetversion != PACKETVERSION) return;/* old new packet format */ +#ifndef DEVELOP if (info->version != VERSION) return; // Not same version. if (info->subversion != SUBVERSION) return; // Close, but no cigar. +#endif if (strcmp(info->application, SRB2APPLICATION)) return;/* that's a different mod */ @@ -1681,6 +1690,35 @@ static boolean CL_ServerConnectionSearchTicker(tic_t *asksent) if (client) { +#ifdef DEVELOP + // Commits do not match? Do not connect! + if (memcmp(serverlist[i].info.commit, + comprevision_abbrev_bin, + GIT_SHA_ABBREV)) + { + char theirs[GIT_SHA_ABBREV * 2 + 1]; + UINT8 n; + + for (n = 0; n < GIT_SHA_ABBREV; ++n) + { + sprintf(&theirs[n * 2], "%02hhx", + serverlist[i].info.commit[n]); + } + + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + + M_StartMessage(va( + "Your EXE differs from the server.\n" + " Yours: %.*s\n" + "Theirs: %s\n\n" + "Press ESC\n", + GIT_SHA_ABBREV * 2, comprevision, theirs), NULL, MM_NOTHING); + return false; + } +#endif + #ifdef HAVE_CURL if (serverlist[i].info.httpsource[0]) strncpy(http_source, serverlist[i].info.httpsource, MAX_MIRROR_LENGTH); @@ -2014,8 +2052,10 @@ static void CL_ConnectToServer(void) gametypestr[sizeof serverlist[i].info.gametypename - 1] = '\0'; CON_LogMessage(va(M_GetText("Gametype: %s\n"), gametypestr)); +#ifndef DEVELOP CON_LogMessage(va(M_GetText("Version: %d.%d\n"), serverlist[i].info.version, serverlist[i].info.subversion)); +#endif } SL_ClearServerList(servernode); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index fabbd01f5..a7f56b78f 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -266,8 +266,12 @@ typedef struct UINT8 _255; UINT8 packetversion; char application[MAXAPPLICATION]; +#ifdef DEVELOP + UINT8 commit[GIT_SHA_ABBREV]; +#else UINT8 version; UINT8 subversion; +#endif UINT8 numberofplayer; UINT8 maxplayer; UINT8 refusereason; // 0: joinable, 1: joins disabled, 2: full diff --git a/src/d_main.c b/src/d_main.c index 82cf8fd5a..1586e96fa 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -96,6 +96,10 @@ int VERSION; int SUBVERSION; +#ifdef DEVELOP +UINT8 comprevision_abbrev_bin[GIT_SHA_ABBREV]; +#endif + #ifdef HAVE_DISCORDRPC #include "discord.h" #endif @@ -1170,6 +1174,20 @@ static void IdentifyVersion(void) #endif } +#ifdef DEVELOP +static void +D_AbbrevCommit (void) +{ + UINT8 i; + + for (i = 0; i < GIT_SHA_ABBREV; ++i) + { + sscanf(&comprevision[i * 2], "%2hhx", + &comprevision_abbrev_bin[i]); + } +} +#endif + static void D_ConvertVersionNumbers (void) { @@ -1194,6 +1212,10 @@ void D_SRB2Main(void) /* break the version string into version numbers, for netplay */ D_ConvertVersionNumbers(); +#ifdef DEVELOP + D_AbbrevCommit(); +#endif + // Print GPL notice for our console users (Linux) CONS_Printf( "\n\nDr. Robotnik's Ring Racers\n" diff --git a/src/doomdef.h b/src/doomdef.h index 6997d7951..9cd7bb1d9 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -516,6 +516,17 @@ char *sizeu5(size_t num); // d_main.c extern int VERSION; extern int SUBVERSION; + +#ifdef DEVELOP +// 4 bytes handles 8 characters of a git object SHA. At +// around 20k commits, we only need 6 characters for a unique +// abbreviation. Maybe in another 20k commits, more than 8 +// characters will be required! =P +// P.S. 8 is also what comptime generates +#define GIT_SHA_ABBREV (4) +extern UINT8 comprevision_abbrev_bin[GIT_SHA_ABBREV]; +#endif + extern boolean devparm; // development mode (-debug) // d_netcmd.c extern INT32 cv_debug; From bc0fc9b05a23c6cf6e82778c003115caa2d5ed53 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 30 Sep 2022 05:49:26 -0700 Subject: [PATCH 2/2] Readd version and subversion to serverinfo Add commit field after those two so packet is identical up to that point and DEVELOP builds mismatch version online. blame d176aefd8 --- src/d_clisrv.c | 10 +++------- src/d_clisrv.h | 5 ++--- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a5a8e126b..a6f18b1ab 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -896,12 +896,12 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->u.serverinfo._255 = 255; netbuffer->u.serverinfo.packetversion = PACKETVERSION; + netbuffer->u.serverinfo.version = VERSION; + netbuffer->u.serverinfo.subversion = SUBVERSION; + #ifdef DEVELOP memcpy(netbuffer->u.serverinfo.commit, comprevision_abbrev_bin, GIT_SHA_ABBREV); -#else - netbuffer->u.serverinfo.version = VERSION; - netbuffer->u.serverinfo.subversion = SUBVERSION; #endif strncpy(netbuffer->u.serverinfo.application, SRB2APPLICATION, @@ -1411,13 +1411,11 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) if (info->packetversion != PACKETVERSION) return;/* old new packet format */ -#ifndef DEVELOP if (info->version != VERSION) return; // Not same version. if (info->subversion != SUBVERSION) return; // Close, but no cigar. -#endif if (strcmp(info->application, SRB2APPLICATION)) return;/* that's a different mod */ @@ -2052,10 +2050,8 @@ static void CL_ConnectToServer(void) gametypestr[sizeof serverlist[i].info.gametypename - 1] = '\0'; CON_LogMessage(va(M_GetText("Gametype: %s\n"), gametypestr)); -#ifndef DEVELOP CON_LogMessage(va(M_GetText("Version: %d.%d\n"), serverlist[i].info.version, serverlist[i].info.subversion)); -#endif } SL_ClearServerList(servernode); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index a7f56b78f..354e62486 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -266,11 +266,10 @@ typedef struct UINT8 _255; UINT8 packetversion; char application[MAXAPPLICATION]; -#ifdef DEVELOP - UINT8 commit[GIT_SHA_ABBREV]; -#else UINT8 version; UINT8 subversion; +#ifdef DEVELOP + UINT8 commit[GIT_SHA_ABBREV]; #endif UINT8 numberofplayer; UINT8 maxplayer;