edit: Fix and unify handling of invalid country numbers

Negative numbers and numbers greater or equal than MAXNOC are invalid.
edit handles such arguments inconsistently:

    cmd  key  struct member   arg < 0     arg >= MAXNOC
    ---------------------------------------------------
    edit l o  sct_own         reject      MAXNOC - 1
           O  sct_oldown      reject      MAXNOC - 1
           X  sct_che_target  0           MAXNOC - 1
    edit s O  shp_own         cast        skip
    edit u O  lnd_own         cast        skip
    edit p O  pln_own         cast        skip

Legend:

    0           replace arg by 0
    MAXNOC - 1  replace arg by MAXNOC - 1
    reject      command fails
    cast        replace arg by (natid)arg
                bug: can be >= MAXNOC!
    skip        ignore this key and arg
                bug: telexes the owner he lost the unit, which is a lie

Unify to reject.  Matches setsector.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
This commit is contained in:
Markus Armbruster 2013-01-15 20:30:36 +01:00
parent aa07f3393a
commit 381c479ff8
3 changed files with 38 additions and 36 deletions

View file

@ -430,40 +430,37 @@ warn_deprecated(char key)
static int static int
edit_sect(struct sctstr *sect, char op, int arg, char *p) edit_sect(struct sctstr *sect, char op, int arg, char *p)
{ {
natid newown, oldown;
coord newx, newy; coord newx, newy;
int new, old; int new, old;
int des; int des;
switch (op) { switch (op) {
case 'o': case 'o':
if (arg < 0) if (arg < 0 || arg >= MAXNOC)
return RET_SYN; return RET_SYN;
newown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
pr("Owner of %s changed from %s to %s.\n", pr("Owner of %s changed from %s to %s.\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
prnatid(sect->sct_own), prnatid(newown)); prnatid(sect->sct_own), prnatid(arg));
if (sect->sct_own) { if (sect->sct_own) {
wu(player->cnum, sect->sct_own, wu(player->cnum, sect->sct_own,
"Sector %s lost to deity intervention\n", "Sector %s lost to deity intervention\n",
xyas(sect->sct_x, sect->sct_y, sect->sct_own)); xyas(sect->sct_x, sect->sct_y, sect->sct_own));
} }
benefit(sect->sct_own, 0); benefit(sect->sct_own, 0);
sect->sct_own = newown; sect->sct_own = arg;
if (newown) { if (arg) {
wu(player->cnum, newown, wu(player->cnum, arg,
"Sector %s gained from deity intervention\n", "Sector %s gained from deity intervention\n",
xyas(sect->sct_x, sect->sct_y, newown)); xyas(sect->sct_x, sect->sct_y, arg));
} }
benefit(newown, 1); benefit(arg, 1);
break; break;
case 'O': case 'O':
if (arg < 0) if (arg < 0 || arg >= MAXNOC)
return RET_SYN; return RET_SYN;
oldown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
pr("Old owner of %s changed from %s to %s.\n", pr("Old owner of %s changed from %s to %s.\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
prnatid(sect->sct_oldown), prnatid(oldown)); prnatid(sect->sct_oldown), prnatid(arg));
sect->sct_oldown = oldown; sect->sct_oldown = arg;
break; break;
case 'e': case 'e':
new = LIMIT_TO(arg, 0, 100); new = LIMIT_TO(arg, 0, 100);
@ -520,13 +517,13 @@ edit_sect(struct sctstr *sect, char op, int arg, char *p)
sect->sct_che = new; sect->sct_che = new;
break; break;
case 'X': case 'X':
old = sect->sct_che_target; if (arg < 0 || arg >= MAXNOC)
new = LIMIT_TO(arg, 0, MAXNOC - 1); return RET_SYN;
pr("Che target of %s changed from %s to %s.\n", pr("Che target of %s changed from %s to %s.\n",
xyas(sect->sct_x, sect->sct_y, player->cnum), xyas(sect->sct_x, sect->sct_y, player->cnum),
prnatid(old), prnatid(new)); prnatid(sect->sct_che_target), prnatid(arg));
sect->sct_che_target = new; sect->sct_che_target = arg;
if (new == 0) if (arg == 0)
sect->sct_che = 0; sect->sct_che = 0;
break; break;
case 'p': case 'p':
@ -739,14 +736,16 @@ edit_ship(struct shpstr *ship, char op, int arg, char *p)
ef_set_uid(EF_SHIP, ship, arg); ef_set_uid(EF_SHIP, ship, arg);
break; break;
case 'O': case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
if (ship->shp_own) if (ship->shp_own)
wu(player->cnum, ship->shp_own, wu(player->cnum, ship->shp_own,
"%s taken from you by deity intervention!\n", prship(ship)); "%s taken from you by deity intervention!\n", prship(ship));
if (arg && arg < MAXNOC) { if (arg) {
wu(player->cnum, (natid)arg, wu(player->cnum, (natid)arg,
"%s given to you by deity intervention!\n", prship(ship)); "%s given to you by deity intervention!\n", prship(ship));
ship->shp_own = (natid)arg; ship->shp_own = (natid)arg;
} else if (!arg) } else
ship->shp_effic = 0; ship->shp_effic = 0;
break; break;
case 'L': case 'L':
@ -835,15 +834,16 @@ edit_land(struct lndstr *land, char op, int arg, char *p)
ef_set_uid(EF_LAND, land, arg); ef_set_uid(EF_LAND, land, arg);
break; break;
case 'O': case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
if (land->lnd_own) if (land->lnd_own)
wu(player->cnum, land->lnd_own, wu(player->cnum, land->lnd_own,
"%s taken from you by deity intervention!\n", prland(land)); "%s taken from you by deity intervention!\n", prland(land));
if (arg) {
if (arg && arg < MAXNOC) {
wu(player->cnum, (natid)arg, wu(player->cnum, (natid)arg,
"%s given to you by deity intervention!\n", prland(land)); "%s given to you by deity intervention!\n", prland(land));
land->lnd_own = (natid)arg; land->lnd_own = (natid)arg;
} else if (!arg) } else
land->lnd_effic = 0; land->lnd_effic = 0;
break; break;
case 'L': case 'L':
@ -949,15 +949,17 @@ edit_plane(struct plnstr *plane, char op, int arg, char *p)
plane->pln_y = newy; plane->pln_y = newy;
break; break;
case 'O': case 'O':
if (arg < 0 || arg >= MAXNOC)
return RET_SYN;
if (plane->pln_own) if (plane->pln_own)
wu(player->cnum, plane->pln_own, wu(player->cnum, plane->pln_own,
"%s taken from you by deity intervention!\n", "%s taken from you by deity intervention!\n",
prplane(plane)); prplane(plane));
if (arg && arg < MAXNOC) { if (arg) {
plane->pln_own = (natid)arg; plane->pln_own = (natid)arg;
wu(player->cnum, plane->pln_own, wu(player->cnum, plane->pln_own,
"%s given to you by deity intervention!\n", prplane(plane)); "%s given to you by deity intervention!\n", prplane(plane));
} else if (!arg) } else
plane->pln_effic = 0; plane->pln_effic = 0;
break; break;
case 'e': case 'e':

View file

@ -361,8 +361,7 @@ actor action victim times duration time
0 42 2 38 0 0 0 42 2 38 0 0
0 42 1 39 0 0 0 42 1 39 0 0
0 44 1 58 0 0 0 44 1 58 0 0
0 43 98 2 0 0 0 43 98 1 0 0
0 44 98 1 0 0
0 43 2 1 0 0 0 43 2 1 0 0
0 43 1 54 0 0 0 43 1 54 0 0
1 45 0 3 0 0 1 45 0 3 0 0

View file

@ -51,7 +51,7 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 3,7 o 99 Play#0 input edit l 3,7 o 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Owner of 3,7 changed from 98 (#98) to 98 (#98). Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 1,7 O 0 Play#0 input edit l 1,7 O 0
Play#0 command edit Play#0 command edit
@ -67,7 +67,7 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 3,7 O 99 Play#0 input edit l 3,7 O 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Old owner of 3,7 changed from 98 (#98) to 98 (#98). Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 1,7 X 0 Play#0 input edit l 1,7 X 0
Play#0 command edit Play#0 command edit
@ -75,7 +75,7 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 1,7 X -1 Play#0 input edit l 1,7 X -1
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Che target of 1,7 changed from POGO (#0) to POGO (#0). Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 3,7 X 98 Play#0 input edit l 3,7 X 98
Play#0 command edit Play#0 command edit
@ -83,7 +83,7 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 3,7 X 99 Play#0 input edit l 3,7 X 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Che target of 3,7 changed from 98 (#98) to 98 (#98). Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit l 5,7 o 2 Play#0 input edit l 5,7 o 2
Play#0 command edit Play#0 command edit
@ -788,12 +788,14 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit s 0 O -1 Play#0 input edit s 0 O -1
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit s 1 O 98 Play#0 input edit s 1 O 98
Play#0 command edit Play#0 command edit
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit s 1 O 99 Play#0 input edit s 1 O 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit s 2 O 2 Play#0 input edit s 2 O 2
Play#0 command edit Play#0 command edit
@ -821,12 +823,14 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 0 O -1 Play#0 input edit p 0 O -1
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 1 O 98 Play#0 input edit p 1 O 98
Play#0 command edit Play#0 command edit
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 1 O 99 Play#0 input edit p 1 O 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit p 2 O 2 Play#0 input edit p 2 O 2
Play#0 command edit Play#0 command edit
@ -854,12 +858,14 @@
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit u 0 O -1 Play#0 input edit u 0 O -1
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit u 1 O 98 Play#0 input edit u 1 O 98
Play#0 command edit Play#0 command edit
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit u 1 O 99 Play#0 input edit u 1 O 99
Play#0 command edit Play#0 command edit
Play#0 output Play#0 1 Usage: edit <country|land|ship|plane|unit> <NAT|SECT|SHIP|PLANE|LAND> [<KEY> <VALUE>]...
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input edit u 2 O 2 Play#0 input edit u 2 O 2
Play#0 command edit Play#0 command edit
@ -1577,15 +1583,10 @@
Play#0 output Play#0 1 Play#0 output Play#0 1
Play#0 output Play#0 1 > BULLETIN from POGO, (#0) dated Thu Jan 1 00:00:00 1970 Play#0 output Play#0 1 > BULLETIN from POGO, (#0) dated Thu Jan 1 00:00:00 1970
Play#0 output Play#0 1 Sector 3,7 gained from deity intervention Play#0 output Play#0 1 Sector 3,7 gained from deity intervention
Play#0 output Play#0 1 Sector 3,7 lost to deity intervention
Play#0 output Play#0 1 Sector 3,7 gained from deity intervention
Play#0 output Play#0 1 Sector 9,7 gained from deity intervention Play#0 output Play#0 1 Sector 9,7 gained from deity intervention
Play#0 output Play#0 1 cs cargo ship (#1) given to you by deity intervention! Play#0 output Play#0 1 cs cargo ship (#1) given to you by deity intervention!
Play#0 output Play#0 1 cs cargo ship (#1) taken from you by deity intervention!
Play#0 output Play#0 1 f1 Sopwith Camel #1 given to you by deity intervention! Play#0 output Play#0 1 f1 Sopwith Camel #1 given to you by deity intervention!
Play#0 output Play#0 1 f1 Sopwith Camel #1 taken from you by deity intervention!
Play#0 output Play#0 1 sup supply #1 given to you by deity intervention! Play#0 output Play#0 1 sup supply #1 given to you by deity intervention!
Play#0 output Play#0 1 sup supply #1 taken from you by deity intervention!
Play#0 output Play#0 6 0 640 Play#0 output Play#0 6 0 640
Play#0 input ctld Play#0 input ctld
Play#0 output Play#0 1 Bye-bye Play#0 output Play#0 1 Bye-bye