Compare git commit when joining netgames in DEVELOP builds

This commit is contained in:
James R 2022-09-29 12:55:07 -07:00
parent aeda564145
commit d176aefd88
4 changed files with 77 additions and 0 deletions

View file

@ -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);

View file

@ -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

View file

@ -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"

View file

@ -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;