From 6c5ac8e9427813fb1e301cfb64c92c447aac0347 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Wed, 17 Apr 2019 23:29:27 -0500 Subject: [PATCH] Paginate PutFileNeeded --- src/d_clisrv.c | 6 +----- src/d_clisrv.h | 2 ++ src/d_netfil.c | 33 ++++++++++++++++++++++++++++----- src/d_netfil.h | 3 ++- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e227ce2e..86ebb345 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1433,7 +1433,7 @@ static void SV_SendServerInfo(INT32 node, tic_t servertime) netbuffer->u.serverinfo.actnum = 0; //mapheaderinfo[gamemap-1]->actnum - p = PutFileNeeded(); + p = PutFileNeeded(0); HSendPacket(node, false, 0, p - ((UINT8 *)&netbuffer->u)); } @@ -2022,10 +2022,6 @@ static boolean CL_ServerConnectionSearchTicker(boolean viams, tic_t *asksent) } cl_mode = CL_ASKDOWNLOADFILES; - - // no problem if can't send packet, we will retry later - //if (CL_SendRequestFile()) - // cl_mode = CL_DOWNLOADFILES; } } else diff --git a/src/d_clisrv.h b/src/d_clisrv.h index f3a9011e..a4324d69 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -376,6 +376,8 @@ typedef struct #define MAXSERVERNAME 32 #define MAXFILENEEDED 915 +#define MAXFILENEEDEDPAGES MAX_WADFILES +#define FILENEEDED_MORE 0x80 // This packet is too large typedef struct { diff --git a/src/d_netfil.c b/src/d_netfil.c index 4e6e76a1..efb0fb81 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -101,25 +101,49 @@ char downloaddir[512] = "DOWNLOAD"; INT32 lastfilenum = -1; #endif +UINT16 fileneededpages = 0; +static size_t fileneededpagestart[MAXFILENEEDEDPAGES]; + /** Fills a serverinfo packet with information about wad files loaded. * * \todo Give this function a better name since it is in global scope. * Used to have size limiting built in - now handed via W_LoadWadFile in w_wad.c * */ -UINT8 *PutFileNeeded(void) +UINT8 *PutFileNeeded(UINT16 page) { - size_t i, count = 0; + size_t i; + UINT8 count = 0; UINT8 *p = netbuffer->u.serverinfo.fileneeded; char wadfilename[MAX_WADPATH] = ""; UINT8 filestatus; - for (i = 0; i < numwadfiles; i++) + if (page > fileneededpages) + I_Error("Fileneeded page %d accessed before a prior page", page); + else if (page == 0) + { + fileneededpages = 0; + memset(fileneededpagestart, 0, sizeof(fileneededpagestart)); // ??? I guess. + fileneededpagestart[0] = mainwads; + } + + for (i = fileneededpagestart[page]; i < (fileneededpagestart[page+1] ?: numwadfiles); i++) { // If it has only music/sound lumps, don't put it in the list if (!wadfiles[i]->important) continue; + nameonly(strcpy(wadfilename, wadfiles[i]->filename)); + + if (p + 1 + 4 + strlen(wadfilename) + 16 > netbuffer->u.serverinfo.fileneeded + MAXFILENEEDED) + { + // Too many files for this page, so mark the next page to start here and finish up. + fileneededpagestart[page+1] = i; + fileneededpages = page+1; + count |= FILENEEDED_MORE; + break; + } + filestatus = 1; // Importance - not really used any more, holds 1 by default for backwards compat with MS // Store in the upper four bits @@ -134,11 +158,10 @@ UINT8 *PutFileNeeded(void) count++; WRITEUINT32(p, wadfiles[i]->filesize); - nameonly(strcpy(wadfilename, wadfiles[i]->filename)); WRITESTRINGN(p, wadfilename, MAX_WADPATH); WRITEMEM(p, wadfiles[i]->md5sum, 16); } - netbuffer->u.serverinfo.fileneedednum = (UINT8)count; + netbuffer->u.serverinfo.fileneedednum = count; return p; } diff --git a/src/d_netfil.h b/src/d_netfil.h index 3d7c2ed5..3a40c13a 100644 --- a/src/d_netfil.h +++ b/src/d_netfil.h @@ -53,7 +53,8 @@ extern char downloaddir[512]; extern INT32 lastfilenum; #endif -UINT8 *PutFileNeeded(void); +extern UINT16 fileneededpages; +UINT8 *PutFileNeeded(UINT16 page); void D_ParseFileneeded(INT32 fileneedednum_parm, UINT8 *fileneededstr); void CL_PrepareDownloadSaveGame(const char *tmpsave);