Merge branch 'addfile-vararg' into 'next'

Give the addfile command variable argument support.

See merge request STJr/SRB2!1176
This commit is contained in:
James R 2020-10-12 18:32:20 -04:00
commit 58464771a8

View file

@ -3240,20 +3240,49 @@ static void Got_RunSOCcmd(UINT8 **cp, INT32 playernum)
* Searches for sounds, maps, music, new images. * Searches for sounds, maps, music, new images.
*/ */
static void Command_Addfile(void) static void Command_Addfile(void)
{
size_t argc = COM_Argc(); // amount of arguments total
size_t curarg; // current argument index
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 <filename.pk3/wad/lua/soc> [filename2...] [...]: Load add-ons\n"));
return;
}
// start at one to skip command name
for (curarg = 1; curarg < argc; curarg++)
{ {
const char *fn, *p; const char *fn, *p;
char buf[256]; char buf[256];
char *buf_p = buf; char *buf_p = buf;
INT32 i; INT32 i;
size_t ii;
int musiconly; // W_VerifyNMUSlumps isn't boolean int musiconly; // W_VerifyNMUSlumps isn't boolean
boolean fileadded = false;
if (COM_Argc() != 2) fn = COM_Argv(curarg);
// For the amount of filenames previously processed...
for (ii = 0; ii < numfilesadded; ii++)
{ {
CONS_Printf(M_GetText("addfile <wadfile.wad>: load wad file\n")); // If this is one of them, don't try to add it.
return; if (!strcmp(fn, addedfiles[ii]))
{
fileadded = true;
break;
}
}
// 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;
} }
else
fn = COM_Argv(1);
// Disallow non-printing characters and semicolons. // Disallow non-printing characters and semicolons.
for (i = 0; fn[i] != '\0'; i++) for (i = 0; fn[i] != '\0'; i++)
@ -3268,7 +3297,7 @@ static void Command_Addfile(void)
if (netgame && !(server || IsPlayerAdmin(consoleplayer))) if (netgame && !(server || IsPlayerAdmin(consoleplayer)))
{ {
CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n"));
return; continue;
} }
G_SetGameModified(multiplayer); G_SetGameModified(multiplayer);
} }
@ -3277,7 +3306,8 @@ static void Command_Addfile(void)
if (!(netgame || multiplayer) || musiconly) if (!(netgame || multiplayer) || musiconly)
{ {
P_AddWadFile(fn); P_AddWadFile(fn);
return; addedfiles[numfilesadded++] = fn;
continue;
} }
p = fn+strlen(fn); p = fn+strlen(fn);
@ -3314,25 +3344,28 @@ static void Command_Addfile(void)
fclose(fhandle); fclose(fhandle);
} }
else // file not found else // file not found
return; continue;
for (i = 0; i < numwadfiles; i++) for (i = 0; i < numwadfiles; i++)
{ {
if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) if (!memcmp(wadfiles[i]->md5sum, md5sum, 16))
{ {
CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn); CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), fn);
return; continue;
} }
} }
#endif #endif
WRITEMEM(buf_p, md5sum, 16); WRITEMEM(buf_p, md5sum, 16);
} }
addedfiles[numfilesadded++] = fn;
if (IsPlayerAdmin(consoleplayer) && (!server)) // Request to add file if (IsPlayerAdmin(consoleplayer) && (!server)) // Request to add file
SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf); SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf);
else else
SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); SendNetXCmd(XD_ADDFILE, buf, buf_p - buf);
} }
}
static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum)
{ {