retreat: Reject invalid retreat paths

Undocumented misfeature: retreat and lretreat accept anything as
retreat path.  The paths' actual consumers retreat_ship1() and
retread_land1() silently ignore invalid direction characters.

The retreat paths are in xdump, and invalid ones could conceivably
confuse smart clients.

Change the commands to reject invalid paths, and the consumers to oops
on invalid direction characters.

Note that invalid paths get rejected even when they're not actually
used because the conditions argument contains a "c" for "cancel".
Requiring the user give a new path so he can cancel the old one is
comically bad design.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2014-01-22 19:26:24 +01:00
parent 1e3b7773d4
commit 40ec33b099
5 changed files with 40 additions and 22 deletions

View file

@ -38,6 +38,7 @@
#include "commands.h"
#include "empobj.h"
#include "land.h"
#include "path.h"
#include "retreat.h"
#include "ship.h"
@ -84,9 +85,16 @@ retreat(int type)
if (!snxtitem(&ni, type, player->argp[1], NULL))
return RET_SYN;
nunits = 0;
if (player->argp[2] != NULL)
if (player->argp[2] != NULL) {
pq = getstarg(player->argp[2], "Retreat path? ", buf1);
else
for (i = 0; i < RET_LEN - 1 && pq[i]; i++) {
if (chkdir(pq[i], DIR_STOP, DIR_LAST) < 0) {
pr("'%c' is not a valid direction...\n", pq[i]);
direrr(NULL, NULL, NULL);
return RET_SYN;
}
}
} else
pq = NULL;
rflags = 0;