From b25acfa7827773b9d0cdf6a6c5b45b0169065ee9 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 13 Apr 2020 17:30:42 -0700 Subject: [PATCH 1/6] Reorder join process so password is authenticated before attempting to download --- src/d_clisrv.c | 58 ++++++++++++++++---------------------------------- src/d_clisrv.h | 6 ++++++ 2 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 836023f5..27397245 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1995,40 +1995,7 @@ static boolean CL_FinishedFileList(void) else if (i == 1) cl_mode = CL_ASKJOIN; else - { - // must download something - // can we, though? -#ifdef HAVE_CURL - if (http_source[0] == '\0' || curl_failedwebdownload) -#endif - { - if (!CL_CheckDownloadable()) // nope! - { - D_QuitNetGame(); - CL_Reset(); - D_StartTitle(); - M_StartMessage(M_GetText( - "You cannot connect to this server\n" - "because you cannot download the files\n" - "that you are missing from the server.\n\n" - "See the console or log file for\n" - "more details.\n\n" - "Press ESC\n" - ), NULL, MM_NOTHING); - return false; - } - - cl_mode = CL_ASKDOWNLOADFILES; - return true; - } -#ifdef HAVE_CURL - else - { - cl_mode = CL_PREPAREHTTPFILES; - return true; - } -#endif - } + cl_mode = CL_ASKDOWNLOADFILES; return true; } @@ -2163,10 +2130,9 @@ static boolean CL_ServerConnectionTicker(boolean viams, const char *tmpsave, tic #ifdef HAVE_CURL case CL_PREPAREHTTPFILES: - if (http_source[0]) { for (i = 0; i < fileneedednum; i++) - if (fileneeded[i].status == FS_NOTFOUND) + if (fileneeded[i].status == FS_NOTFOUND || fileneeded[i].status == FS_MD5SUMBAD) curl_transfers++; cl_mode = CL_DOWNLOADHTTPFILES; @@ -2176,7 +2142,7 @@ static boolean CL_ServerConnectionTicker(boolean viams, const char *tmpsave, tic case CL_DOWNLOADHTTPFILES: waitmore = false; for (i = 0; i < fileneedednum; i++) - if (fileneeded[i].status == FS_NOTFOUND) + if (fileneeded[i].status == FS_NOTFOUND || fileneeded[i].status == FS_MD5SUMBAD) { if (!curl_running) CURLPrepareFile(http_source, i); @@ -3912,7 +3878,9 @@ static void HandleConnect(SINT8 node) if (netbuffer->u.clientcfg.needsdownload) { netbuffer->packettype = PT_DOWNLOADFILESOKAY; - HSendPacket(node, true, 0, 0); + strncpy(netbuffer->u.filecfg.http_source, cv_httpsource.string, + MAX_MIRROR_LENGTH); + HSendPacket(node, true, 0, sizeof netbuffer->u.filecfg); return; } @@ -4193,7 +4161,17 @@ static void HandlePacketFromAwayNode(SINT8 node) SERVERONLY - // This should've already been checked, but just to be safe... +#ifdef HAVE_CURL + if (! curl_failedwebdownload && + netbuffer->u.filecfg.http_source[0] != '\0' + ){ + strlcpy(http_source, netbuffer->u.filecfg.http_source, + MAX_MIRROR_LENGTH); + + cl_mode = CL_PREPAREHTTPFILES; + } + else +#endif if (!CL_CheckDownloadable()) { D_QuitNetGame(); @@ -4215,7 +4193,7 @@ static void HandlePacketFromAwayNode(SINT8 node) cl_challengeattempted = 2; CONS_Printf("trying to download\n"); - if (CL_SendRequestFile()) + if (cl_mode == CL_WAITDOWNLOADFILESRESPONSE && CL_SendRequestFile()) cl_mode = CL_DOWNLOADFILES; break; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index c4e54b48..d1d99d7d 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -443,6 +443,11 @@ typedef struct UINT8 files[MAXFILENEEDED]; // is filled with writexxx (byteptr.h) } ATTRPACK filesneededconfig_pak; +typedef struct +{ + char http_source[MAX_MIRROR_LENGTH];/* first byte 0? no die! */ +} ATTRPACK fileconfig; + // // Network packet data // @@ -477,6 +482,7 @@ typedef struct plrconfig playerconfig[MAXPLAYERS]; // (up to) 528 bytes(?) INT32 filesneedednum; // 4 bytes filesneededconfig_pak filesneededcfg; // ??? bytes + fileconfig filecfg; UINT32 pingtable[MAXPLAYERS+1]; // 68 bytes } u; // This is needed to pack diff packet types data together } ATTRPACK doomdata_t; From abd15288b4a6d977b0e0b7542d614e5241f5e7c3 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 13 Apr 2020 17:40:48 -0700 Subject: [PATCH 2/6] Don't send httpsource in SERVERINFO if join password is set --- src/d_clisrv.c | 93 ++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 27397245..7f242e79 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1471,15 +1471,18 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->u.serverinfo.actnum = 0; //mapheaderinfo[gamemap-1]->actnum #ifdef HAVE_CURL - mirror_length = strlen(httpurl); - if (mirror_length > MAX_MIRROR_LENGTH) - mirror_length = MAX_MIRROR_LENGTH; + if (D_IsJoinPasswordOn()) + { + mirror_length = strlen(httpurl); + if (mirror_length > MAX_MIRROR_LENGTH) + mirror_length = MAX_MIRROR_LENGTH; - if (snprintf(netbuffer->u.serverinfo.httpsource, mirror_length+1, "%s", httpurl) < 0) - // If there's an encoding error, send nothing, we accept that the above may be truncated - strncpy(netbuffer->u.serverinfo.httpsource, "", mirror_length); + if (snprintf(netbuffer->u.serverinfo.httpsource, mirror_length+1, "%s", httpurl) < 0) + // If there's an encoding error, send nothing, we accept that the above may be truncated + strncpy(netbuffer->u.serverinfo.httpsource, "", mirror_length); - netbuffer->u.serverinfo.httpsource[MAX_MIRROR_LENGTH-1] = '\0'; + netbuffer->u.serverinfo.httpsource[MAX_MIRROR_LENGTH-1] = '\0'; + } #endif p = PutFileNeeded(0); @@ -2042,16 +2045,6 @@ static boolean CL_ServerConnectionSearchTicker(boolean viams, tic_t *asksent) if (client) { -#ifdef HAVE_CURL - if (serverlist[i].info.httpsource[0]) - strncpy(http_source, serverlist[i].info.httpsource, MAX_MIRROR_LENGTH); - else - http_source[0] = '\0'; -#else - if (serverlist[i].info.httpsource[0]) - CONS_Printf("We received a http url from the server, however it will not be used as this build lacks curl support (%s)\n", serverlist[i].info.httpsource); -#endif - D_ParseFileneeded(serverlist[i].info.fileneedednum, serverlist[i].info.fileneeded, 0); if (serverlist[i].info.kartvars & SV_LOTSOFADDONS) { @@ -4161,40 +4154,52 @@ static void HandlePacketFromAwayNode(SINT8 node) SERVERONLY -#ifdef HAVE_CURL - if (! curl_failedwebdownload && - netbuffer->u.filecfg.http_source[0] != '\0' - ){ - strlcpy(http_source, netbuffer->u.filecfg.http_source, - MAX_MIRROR_LENGTH); - - cl_mode = CL_PREPAREHTTPFILES; - } - else -#endif - if (!CL_CheckDownloadable()) + if (netbuffer->u.filecfg.http_source[0] != '\0') { - D_QuitNetGame(); - CL_Reset(); - D_StartTitle(); - M_StartMessage(M_GetText( - "You cannot connect to this server\n" - "because you cannot download the files\n" - "that you are missing from the server.\n\n" - "See the console or log file for\n" - "more details.\n\n" - "Press ESC\n" - ), NULL, MM_NOTHING); - break; + netbuffer->u.filecfg.http_source[MAX_MIRROR_LENGTH-1] = '\0'; + +#ifdef HAVE_CURL + if (! curl_failedwebdownload) + { + strncpy(http_source, netbuffer->u.filecfg.http_source, + sizeof http_source); + + cl_mode = CL_PREPAREHTTPFILES; + } +#else + CONS_Printf("We received a http url from the server, however it will not be used as this build lacks curl support (%s)\n", netbuffer->u.filecfg.http_source); +#endif + } + + if (cl_mode == CL_WAITDOWNLOADFILESRESPONSE) + { + if (CL_CheckDownloadable()) + { + CONS_Printf("trying to download\n"); + if (CL_SendRequestFile()) + cl_mode = CL_DOWNLOADFILES; + } + else + { + D_QuitNetGame(); + CL_Reset(); + D_StartTitle(); + M_StartMessage(M_GetText( + "You cannot connect to this server\n" + "because you cannot download the files\n" + "that you are missing from the server.\n\n" + "See the console or log file for\n" + "more details.\n\n" + "Press ESC\n" + ), NULL, MM_NOTHING); + break; + } } if (cl_challengeattempted == 1) // Successful password noise. S_StartSound(NULL, sfx_s221); cl_challengeattempted = 2; - CONS_Printf("trying to download\n"); - if (cl_mode == CL_WAITDOWNLOADFILESRESPONSE && CL_SendRequestFile()) - cl_mode = CL_DOWNLOADFILES; break; case PT_SERVERCFG: // Positive response of client join request From 8c9e5fc64487ce1a7f3cd3fd81ee87a2af387839 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 13 Apr 2020 17:45:02 -0700 Subject: [PATCH 3/6] Whoops I fucked that up --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7f242e79..0aec685c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1471,7 +1471,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->u.serverinfo.actnum = 0; //mapheaderinfo[gamemap-1]->actnum #ifdef HAVE_CURL - if (D_IsJoinPasswordOn()) + if (! D_IsJoinPasswordOn()) { mirror_length = strlen(httpurl); if (mirror_length > MAX_MIRROR_LENGTH) From 312fb87937dd56c2cb4f0e95d030c34a5e5827cc Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 13 Apr 2020 17:48:10 -0700 Subject: [PATCH 4/6] b25acfa7 also fixed the http downloader not considering checksum mismatched files From d5ca4d3f420431a5fc5364b17189fff7a6d5501a Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 18 Apr 2020 18:45:50 -0700 Subject: [PATCH 5/6] Request a download after completing the join challenge --- src/d_clisrv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0aec685c..a2a31d1c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4101,7 +4101,10 @@ static void HandlePacketFromAwayNode(SINT8 node) if (I_NetMakeNodewPort) servernode = I_NetMakeNode(cl_challengeaddress); #endif - cl_mode = CL_ASKJOIN; + if (cl_needsdownload) + cl_mode = CL_ASKDOWNLOADFILES; + else + cl_mode = CL_ASKJOIN; break; case 1: From b341b87a92afb12a26e5ed931c488c8364e90b58 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 18 Apr 2020 18:47:57 -0700 Subject: [PATCH 6/6] Fuck acks!!!! --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a2a31d1c..17d207c3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1376,7 +1376,7 @@ static boolean CL_SendJoin(void) netbuffer->u.clientcfg.challengenum = cl_challengenum; memcpy(netbuffer->u.clientcfg.challengeanswer, cl_challengeanswer, MD5_LEN); - return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak)); + return HSendPacket(servernode, false, 0, sizeof (clientconfig_pak)); } static void SV_SendServerInfo(INT32 node, tic_t servertime)