add support for downloadable zip mod packages

getmod modname
  Try to download mods/modname.zip from all configured package servers.
  Does not automatically activate the mod. The zip files are limited to
  one megabyte total.

DOCREF getmod
This commit is contained in:
ac-stef
2015-09-07 14:53:56 +02:00
parent f603031018
commit 026dad73cd
5 changed files with 22 additions and 3 deletions
+14 -2
View File
@@ -221,6 +221,11 @@ bool requirepackage(int type, const char *name, const char *host)
pck->exts = mapexts;
break;
case PCK_MOD:
prefix = "mods/";
forceext = ".zip";
break;
default:
conoutf("\f3requirepackage: illegal package type %d (\"%s\")", type, name); // should probably be fatal()
delete pck;
@@ -230,7 +235,7 @@ bool requirepackage(int type, const char *name, const char *host)
copystring(upath, name);
unixpath(upath);
filtertext(pck->name, name, FTXT__MEDIAFILEPATH); // also changes backslashes to slashes
if(strlen(upath) > 100 || strcmp(upath, pck->name) || (checkprefix && strncmp(pck->name, checkprefix, strlen(checkprefix))))
if(strlen(upath) > 100 || strcmp(upath, pck->name) || (checkprefix && strncmp(pck->name, checkprefix, strlen(checkprefix))) || (type == PCK_MOD && !validzipmodname(upath)))
{
conoutf("\f3requirepackage: illegal media path \"%s\" (type: %d)", name, type);
delete pck;
@@ -305,7 +310,7 @@ void processdownload(package *pck, stream *f) // write downloaded data to file(s
stream *d = openfile(path(pck->fullpath, true), "wb");
if(d)
{
streamcopy(d, f, MAXMEDIADOWNLOADFILESIZE);
streamcopy(d, f, pck->type == PCK_MOD ? MAXMODDOWNLOADSIZE : MAXMEDIADOWNLOADFILESIZE);
delete d;
}
delete f;
@@ -493,3 +498,10 @@ void writepcksourcecfg()
delete f;
}
}
void getmod(char *name)
{
if(requirepackage(PCK_MOD, name) && downloadpackages()) conoutf("mod package %s successfully downloaded", name);
else conoutf("failed to download mod package %s", name);
}
COMMAND(getmod, "s");