<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40604 >
Attached patch cleans up the file path and extenstion checking code in the load_command() function. Also, the extensions ".gz", ".bz2", and ".sav.bz2", are added to the searching code since it is a common enough occurrence that save files end up with these extensions. ----------------------------------------------------------------------- どんなに圧縮しても、俺はあなたを見つけます。
diff --git a/server/stdinhand.c b/server/stdinhand.c index 018f511..af02e70 100644 --- a/server/stdinhand.c +++ b/server/stdinhand.c @@ -3386,28 +3386,33 @@ bool load_command(struct connection *caller, const char *filename, bool check) filename); return FALSE; } + { /* it is a normal savegame or maybe a scenario */ - char tmp[MAX_LEN_PATH]; - - my_snprintf(tmp, sizeof(tmp), "%s.sav", filename); - if (!datafilename(tmp)) { - my_snprintf(tmp, sizeof(tmp), "%s.sav.gz", filename); - if (!datafilename(tmp)) { - my_snprintf(tmp, sizeof(tmp), "scenario/%s.sav", filename); - if (!datafilename(tmp)) { - my_snprintf(tmp, sizeof(tmp), "scenario/%s.sav.gz", filename); - if (is_restricted(caller) && !datafilename(tmp)) { - cmd_reply(CMD_LOAD, caller, C_FAIL, _("Cannot find savegame or " - "scenario with the name \"%s\"."), filename); - return FALSE; - } + char testfile[MAX_LEN_PATH]; + const char *paths[] = { "", "scenario/", NULL }; + const char *exts[] = { + "sav", "gz", "bz2", "sav.gz", "sav.bz2", NULL + }; + const char **path, **ext, *found = NULL; + + for (path = paths; !found && *path; path++) { + for (ext = exts; !found && *ext; ext++) { + my_snprintf(testfile, sizeof(testfile), "%s%s.%s", + *path, filename, *ext); + if ((found = datafilename(testfile))) { + sz_strlcpy(arg, found); } } } - if (datafilename(tmp)) { - sz_strlcpy(arg, datafilename(tmp)); - } else { + + if (is_restricted(caller) && !found) { + cmd_reply(CMD_LOAD, caller, C_FAIL, _("Cannot find savegame or " + "scenario with the name \"%s\"."), filename); + return FALSE; + } + + if (!found) { sz_strlcpy(arg, filename); } }
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev