From d576453b569855cc84ce5e5cdb5354e080ec01f2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 18 Dec 2017 21:17:37 +0000 Subject: [PATCH] Command_Addfile: add "too many files" and already-loaded checks and respective error messages No more shall the server be kicked from their own servers for re-adding a wad by accident! --- src/d_netcmd.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 83bbc7aa..2ca48180 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3012,8 +3012,31 @@ static void Command_Addfile(void) if (*p == '\\' || *p == '/' || *p == ':') break; ++p; + // check total packet size and no of files currently loaded + { + size_t packetsize = 0; + serverinfo_pak *dummycheck = NULL; + + // Shut the compiler up. + (void)dummycheck; + + // See W_LoadWadFile in w_wad.c + for (i = 0; i < numwadfiles; i++) + packetsize += nameonlylength(wadfiles[i]->filename) + 22; + + packetsize += nameonlylength(fn) + 22; + + if ((numwadfiles >= MAX_WADFILES) + || (packetsize > sizeof(dummycheck->fileneeded))) + { + 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 @@ -3031,6 +3054,15 @@ static void Command_Addfile(void) } else // file not found return; + + 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); + return; + } + } #endif WRITEMEM(buf_p, md5sum, 16); }