From 4ed99c60bb967bd19c9815707e5d456a5c3fbd64 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 25 Dec 2019 20:44:25 -0800 Subject: [PATCH 1/4] More fine tuned versioning You get a PACKETVERSION, for when some packets change format. You get SRB2APPLICATION, for when you have big fucking mod. (cherry picked from commit 6bd383621eee92b215f86c9c4b483934d7e60daa) --- src/d_clisrv.c | 25 +++++++++++++++++++++++++ src/d_clisrv.h | 23 +++++++++++++++++++++++ src/doomdef.h | 3 +++ 3 files changed, 51 insertions(+) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 17d207c3..3bc30830 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1370,8 +1370,12 @@ static boolean CL_SendJoin(void) localplayers++; netbuffer->u.clientcfg.localplayers = localplayers; + netbuffer->u.clientcfg._255 = 255; + netbuffer->u.clientcfg.packetversion = PACKETVERSION; netbuffer->u.clientcfg.version = VERSION; netbuffer->u.clientcfg.subversion = SUBVERSION; + strncpy(netbuffer->u.clientcfg.application, SRB2APPLICATION, + sizeof netbuffer->u.clientcfg.application); netbuffer->u.clientcfg.needsdownload = cl_needsdownload; netbuffer->u.clientcfg.challengenum = cl_challengenum; memcpy(netbuffer->u.clientcfg.challengeanswer, cl_challengeanswer, MD5_LEN); @@ -1388,8 +1392,12 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) #endif netbuffer->packettype = PT_SERVERINFO; + netbuffer->u.serverinfo._255 = 255; + netbuffer->u.serverinfo.packetversion = PACKETVERSION; netbuffer->u.serverinfo.version = VERSION; netbuffer->u.serverinfo.subversion = SUBVERSION; + strncpy(netbuffer->u.serverinfo.application, SRB2APPLICATION, + sizeof netbuffer->u.serverinfo.application); // return back the time value so client can compute their ping netbuffer->u.serverinfo.time = (tic_t)LONG(servertime); netbuffer->u.serverinfo.leveltime = (tic_t)LONG(leveltime); @@ -1875,12 +1883,21 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) if (serverlistcount >= MAXSERVERLIST) return; // list full + if (info->_255 != 255) + return;/* old packet format */ + + if (info->packetversion != PACKETVERSION) + return;/* old new packet format */ + if (info->version != VERSION) return; // Not same version. if (info->subversion != SUBVERSION) return; // Close, but no cigar. + if (strcmp(info->application, SRB2APPLICATION)) + return;/* that's a different mod */ + i = serverlistcount++; } @@ -3829,6 +3846,12 @@ static void HandleConnect(SINT8 node) if (bannednode && bannednode[node]) SV_SendRefuse(node, M_GetText("You have been banned\nfrom the server")); + else if (netbuffer->u.clientcfg._255 != 255 || + netbuffer->u.clientcfg.packetversion != PACKETVERSION) + SV_SendRefuse(node, "Incompatible packet formats."); + else if (strncmp(netbuffer->u.clientcfg.application, SRB2APPLICATION, + sizeof netbuffer->u.clientcfg.application)) + SV_SendRefuse(node, "Different SRB2 modifications\nare not compatible."); else if (netbuffer->u.clientcfg.version != VERSION || netbuffer->u.clientcfg.subversion != SUBVERSION) SV_SendRefuse(node, va(M_GetText("Different SRB2Kart versions cannot\nplay a netgame!\n(server version %d.%d)"), VERSION, SUBVERSION)); @@ -3975,6 +3998,8 @@ static void HandleServerInfo(SINT8 node) const tic_t ticdiff = (ticnow - ticthen)*1000/NEWTICRATE; netbuffer->u.serverinfo.time = (tic_t)LONG(ticdiff); netbuffer->u.serverinfo.servername[MAXSERVERNAME-1] = 0; + netbuffer->u.serverinfo.application + [sizeof netbuffer->u.serverinfo.application - 1] = '\0'; netbuffer->u.serverinfo.gametype = (UINT8)((netbuffer->u.serverinfo.gametype == VANILLA_GT_MATCH) ? GT_MATCH : GT_RACE); SL_InsertServer(&netbuffer->u.serverinfo, node); diff --git a/src/d_clisrv.h b/src/d_clisrv.h index d1d99d7d..84dae6d3 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -21,6 +21,16 @@ #include "md5.h" +/* +The 'packet version' may be used with packets whose +format is expected to change between versions. + +This version is independent of the mod name, and standard +version and subversion. It should only account for the +basic fields of the packet, and change infrequently. +*/ +#define PACKETVERSION 0 + // Network play related stuff. // There is a data struct that stores network // communication related stuff, and another @@ -345,8 +355,13 @@ typedef struct { #pragma warning(default : 4200) #endif +#define MAXAPPLICATION 16 + typedef struct { + UINT8 _255;/* see serverinfo_pak */ + UINT8 packetversion; + char application[MAXAPPLICATION]; UINT8 version; // Different versions don't work UINT8 subversion; // Contains build version UINT8 localplayers; @@ -372,6 +387,14 @@ typedef struct // This packet is too large typedef struct { + /* + In the old packet, 'version' is the first field. Now that field is set + to 255 always, so older versions won't be confused with the new + versions or vice-versa. + */ + UINT8 _255; + UINT8 packetversion; + char application[MAXAPPLICATION]; UINT8 version; UINT8 subversion; UINT8 numberofplayer; diff --git a/src/doomdef.h b/src/doomdef.h index 13d6a643..ef0f8b7f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -141,6 +141,9 @@ extern FILE *logstream; extern char logfilename[1024]; #endif +/* A mod name to further distinguish versions. */ +#define SRB2APPLICATION "SRB2" + //#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3 #ifdef DEVELOP #define VERSION 0 // Game version From f13f0e3e118259e6057fe6a08fd68eb8215a5f8e Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 12 Jan 2020 20:21:35 -0800 Subject: [PATCH 2/4] Remove adminplayer from SERVERINFO (PACKETVERSION 2) (cherry picked from commit 339ceafdf03a54cb562d70079f15587acd639619) --- src/d_clisrv.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 84dae6d3..2433fee2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -404,7 +404,6 @@ typedef struct UINT8 cheatsenabled; UINT8 kartvars; // Previously isdedicated, now appropriated for our own nefarious purposes UINT8 fileneedednum; - SINT8 adminplayer; tic_t time; tic_t leveltime; char servername[MAXSERVERNAME]; From bb6bdac111c76bddfd6bf2d63726c173b7932edc Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 12 Apr 2020 17:05:18 -0700 Subject: [PATCH 3/4] Make the PACKETVERSION rule easier (cherry picked from commit 4214397679c70a7910c82126783b434f0d10343e) --- src/d_clisrv.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 2433fee2..0f4ca379 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -22,12 +22,9 @@ #include "md5.h" /* -The 'packet version' may be used with packets whose -format is expected to change between versions. - -This version is independent of the mod name, and standard -version and subversion. It should only account for the -basic fields of the packet, and change infrequently. +The 'packet version' is used to distinguish packet formats. +This version is independent of VERSION and SUBVERSION. Different +applications may follow different packet versions. */ #define PACKETVERSION 0 From 820d4a5f8b21f6b59e2cda3e8c3e534197b05f6f Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 20 Apr 2020 20:22:17 -0700 Subject: [PATCH 4/4] SRB2APPLICATION: this is jart! --- src/doomdef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doomdef.h b/src/doomdef.h index ef0f8b7f..ed41e346 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -142,7 +142,7 @@ extern char logfilename[1024]; #endif /* A mod name to further distinguish versions. */ -#define SRB2APPLICATION "SRB2" +#define SRB2APPLICATION "SRB2Kart" //#define DEVELOP // Disable this for release builds to remove excessive cheat commands and enable MD5 checking and stuff, all in one go. :3 #ifdef DEVELOP