From 0b74818771acd338302c39dabedc3b329d6b0c35 Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 4 Oct 2020 21:02:20 -0500 Subject: [PATCH 1/4] Give the addfile command variable argument support. --- src/d_netcmd.c | 187 ++++++++++++++++++++++++++++--------------------- 1 file changed, 108 insertions(+), 79 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4208e4c4f..a61bf0651 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3248,97 +3248,126 @@ static void Got_RunSOCcmd(UINT8 **cp, INT32 playernum) */ static void Command_Addfile(void) { - const char *fn, *p; - char buf[256]; - char *buf_p = buf; - INT32 i; - int musiconly; // W_VerifyNMUSlumps isn't boolean + size_t argc = COM_Argc(); // amount of arguments total + size_t curarg; // current argument index - if (COM_Argc() != 2) + const char *addedfiles[argc]; // list of filenames already processed + size_t numfilesadded = 0; // the amount of filenames processed + + if (argc < 2) { CONS_Printf(M_GetText("addfile : load wad file\n")); return; } - else - fn = COM_Argv(1); - // Disallow non-printing characters and semicolons. - for (i = 0; fn[i] != '\0'; i++) - if (!isprint(fn[i]) || fn[i] == ';') - return; - - musiconly = W_VerifyNMUSlumps(fn); - - if (!musiconly) + // start at one to skip command name + for (curarg = 1; curarg < argc; curarg++) { - // ... But only so long as they contain nothing more then music and sprites. - if (netgame && !(server || IsPlayerAdmin(consoleplayer))) + const char *fn, *p; + char buf[256]; + char *buf_p = buf; + INT32 i; + int musiconly; // W_VerifyNMUSlumps isn't boolean + boolean fileadded = false; + + fn = COM_Argv(curarg); + + // For the amount of filenames previously processed... + for (size_t ii = 0; ii < numfilesadded; ii++) { - CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); - return; - } - G_SetGameModified(multiplayer); - } - - // Add file on your client directly if it is trivial, or you aren't in a netgame. - if (!(netgame || multiplayer) || musiconly) - { - P_AddWadFile(fn); - return; - } - - p = fn+strlen(fn); - while(--p >= fn) - if (*p == '\\' || *p == '/' || *p == ':') - break; - ++p; - - // check total packet size and no of files currently loaded - // See W_LoadWadFile in w_wad.c - if ((numwadfiles >= MAX_WADFILES) - || ((packetsizetally + nameonlylength(fn) + 22) > MAXFILENEEDED*sizeof(UINT8))) - { - CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn); - return; - } - - WRITESTRINGN(buf_p,p,240); - - // calculate and check md5 - { - UINT8 md5sum[16]; -#ifdef NOMD5 - memset(md5sum,0,16); -#else - FILE *fhandle; - - if ((fhandle = W_OpenWadFile(&fn, true)) != NULL) - { - tic_t t = I_GetTime(); - CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn); - md5_stream(fhandle, md5sum); - CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f second\n", fn, (float)(I_GetTime() - t)/TICRATE); - fclose(fhandle); - } - else // file not found - return; - - for (i = 0; i < numwadfiles; i++) - { - if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) + // If this is one of them, don't try to add it. + if (!strcmp(fn, addedfiles[ii])) { - CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); - return; + fileadded = true; + break; } } -#endif - WRITEMEM(buf_p, md5sum, 16); - } - if (IsPlayerAdmin(consoleplayer) && (!server)) // Request to add file - SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf); - else - SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); + // If we've added this one, skip to the next one. + if (fileadded) + continue; + + // Disallow non-printing characters and semicolons. + for (i = 0; fn[i] != '\0'; i++) + if (!isprint(fn[i]) || fn[i] == ';') + return; + + musiconly = W_VerifyNMUSlumps(fn); + + if (!musiconly) + { + // ... But only so long as they contain nothing more then music and sprites. + if (netgame && !(server || IsPlayerAdmin(consoleplayer))) + { + CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); + continue; + } + G_SetGameModified(multiplayer); + } + + // Add file on your client directly if it is trivial, or you aren't in a netgame. + if (!(netgame || multiplayer) || musiconly) + { + P_AddWadFile(fn); + addedfiles[numfilesadded++] = fn; + continue; + } + + p = fn+strlen(fn); + while(--p >= fn) + if (*p == '\\' || *p == '/' || *p == ':') + break; + ++p; + + // check total packet size and no of files currently loaded + // See W_LoadWadFile in w_wad.c + if ((numwadfiles >= MAX_WADFILES) + || ((packetsizetally + nameonlylength(fn) + 22) > MAXFILENEEDED*sizeof(UINT8))) + { + CONS_Alert(CONS_ERROR, M_GetText("Too many files loaded to add %s\n"), fn); + return; + } + + WRITESTRINGN(buf_p,p,240); + + // calculate and check md5 + { + UINT8 md5sum[16]; +#ifdef NOMD5 + memset(md5sum,0,16); +#else + FILE *fhandle; + + if ((fhandle = W_OpenWadFile(&fn, true)) != NULL) + { + tic_t t = I_GetTime(); + CONS_Debug(DBG_SETUP, "Making MD5 for %s\n",fn); + md5_stream(fhandle, md5sum); + CONS_Debug(DBG_SETUP, "MD5 calc for %s took %f second\n", fn, (float)(I_GetTime() - t)/TICRATE); + fclose(fhandle); + } + else // file not found + continue; + + for (i = 0; i < numwadfiles; i++) + { + if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); + continue; + } + } +#endif + WRITEMEM(buf_p, md5sum, 16); + } + + addedfiles[numfilesadded++] = fn; + + if (IsPlayerAdmin(consoleplayer) && (!server)) // Request to add file + SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf); + else + SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); + } } static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) From 2d3a58916717fa45b98c7e7f694b3fd619e7ec6f Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Sun, 4 Oct 2020 21:03:29 -0500 Subject: [PATCH 2/4] Add warning when files are skipped due to being previously processed. --- src/d_netcmd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a61bf0651..9de6b2844 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3285,7 +3285,10 @@ static void Command_Addfile(void) // If we've added this one, skip to the next one. if (fileadded) + { + CONS_Alert(CONS_WARNING, M_GetText("Already processed %s, skipping\n"), fn); continue; + } // Disallow non-printing characters and semicolons. for (i = 0; fn[i] != '\0'; i++) From d5848e78fc640cff8f98b21cc989a86521acf41c Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Tue, 6 Oct 2020 03:37:23 -0500 Subject: [PATCH 3/4] Update help message to mention supported file extensions, and change the description to "Load add-ons" --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 9de6b2844..a96ea1a90 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3256,7 +3256,7 @@ static void Command_Addfile(void) if (argc < 2) { - CONS_Printf(M_GetText("addfile : load wad file\n")); + CONS_Printf(M_GetText("addfile [filename2...] [...]: Load add-ons\n")); return; } From 87a5e1d30c6e5113afbc2fe6dd8cd4f59fd9dcfc Mon Sep 17 00:00:00 2001 From: GoldenTails Date: Mon, 12 Oct 2020 17:14:32 -0500 Subject: [PATCH 4/4] Futureproof against strict buildbots. --- src/d_netcmd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a96ea1a90..22eaeb0d2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3267,13 +3267,14 @@ static void Command_Addfile(void) char buf[256]; char *buf_p = buf; INT32 i; + size_t ii; int musiconly; // W_VerifyNMUSlumps isn't boolean boolean fileadded = false; fn = COM_Argv(curarg); // For the amount of filenames previously processed... - for (size_t ii = 0; ii < numfilesadded; ii++) + for (ii = 0; ii < numfilesadded; ii++) { // If this is one of them, don't try to add it. if (!strcmp(fn, addedfiles[ii]))