]> git.pond.sub.org Git - empserver/commitdiff
edit: Fix and unify handling of invalid country numbers
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 15 Jan 2013 19:30:36 +0000 (20:30 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Thu, 6 Jun 2013 17:52:26 +0000 (19:52 +0200)
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>
src/lib/commands/edit.c
tests/actofgod/actofgod.xdump
tests/actofgod/journal.log

index 1dd1e1eb34a78c75d4b87b0fb7e18808bf61d61f..c3e04b68d730ccea8a3b3196000e4eb9654b4566 100644 (file)
@@ -430,40 +430,37 @@ warn_deprecated(char key)
 static int
 edit_sect(struct sctstr *sect, char op, int arg, char *p)
 {
-    natid newown, oldown;
     coord newx, newy;
     int new, old;
     int des;
     switch (op) {
     case 'o':
-       if (arg < 0)
+       if (arg < 0 || arg >= MAXNOC)
            return RET_SYN;
-       newown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
        pr("Owner of %s changed from %s to %s.\n",
           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) {
            wu(player->cnum, sect->sct_own,
               "Sector %s lost to deity intervention\n",
               xyas(sect->sct_x, sect->sct_y, sect->sct_own));
        }
        benefit(sect->sct_own, 0);
-       sect->sct_own = newown;
-       if (newown) {
-           wu(player->cnum, newown,
+       sect->sct_own = arg;
+       if (arg) {
+           wu(player->cnum, arg,
               "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;
     case 'O':
-       if (arg < 0)
+       if (arg < 0 || arg >= MAXNOC)
            return RET_SYN;
-       oldown = (natid)LIMIT_TO(arg, 0, MAXNOC - 1);
        pr("Old owner of %s changed from %s to %s.\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
-          prnatid(sect->sct_oldown), prnatid(oldown));
-       sect->sct_oldown = oldown;
+          prnatid(sect->sct_oldown), prnatid(arg));
+       sect->sct_oldown = arg;
        break;
     case 'e':
        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;
        break;
     case 'X':
-       old = sect->sct_che_target;
-       new = LIMIT_TO(arg, 0, MAXNOC - 1);
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        pr("Che target of %s changed from %s to %s.\n",
           xyas(sect->sct_x, sect->sct_y, player->cnum),
-          prnatid(old), prnatid(new));
-       sect->sct_che_target = new;
-       if (new == 0)
+          prnatid(sect->sct_che_target), prnatid(arg));
+       sect->sct_che_target = arg;
+       if (arg == 0)
            sect->sct_che = 0;
        break;
     case 'p':
@@ -739,14 +736,16 @@ edit_ship(struct shpstr *ship, char op, int arg, char *p)
        ef_set_uid(EF_SHIP, ship, arg);
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (ship->shp_own)
            wu(player->cnum, ship->shp_own,
               "%s taken from you by deity intervention!\n", prship(ship));
-       if (arg && arg < MAXNOC) {
+       if (arg) {
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prship(ship));
            ship->shp_own = (natid)arg;
-       } else if (!arg)
+       } else
            ship->shp_effic = 0;
        break;
     case 'L':
@@ -835,15 +834,16 @@ edit_land(struct lndstr *land, char op, int arg, char *p)
        ef_set_uid(EF_LAND, land, arg);
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (land->lnd_own)
            wu(player->cnum, land->lnd_own,
               "%s taken from you by deity intervention!\n", prland(land));
-
-       if (arg && arg < MAXNOC) {
+       if (arg) {
            wu(player->cnum, (natid)arg,
               "%s given to you by deity intervention!\n", prland(land));
            land->lnd_own = (natid)arg;
-       } else if (!arg)
+       } else
            land->lnd_effic = 0;
        break;
     case 'L':
@@ -949,15 +949,17 @@ edit_plane(struct plnstr *plane, char op, int arg, char *p)
        plane->pln_y = newy;
        break;
     case 'O':
+       if (arg < 0 || arg >= MAXNOC)
+           return RET_SYN;
        if (plane->pln_own)
            wu(player->cnum, plane->pln_own,
               "%s taken from you by deity intervention!\n",
               prplane(plane));
-       if (arg && arg < MAXNOC) {
+       if (arg) {
            plane->pln_own = (natid)arg;
            wu(player->cnum, plane->pln_own,
               "%s given to you by deity intervention!\n", prplane(plane));
-       } else if (!arg)
+       } else
            plane->pln_effic = 0;
        break;
     case 'e':
index 51cb9152808bab183eb63a2ea35f9114d348925b..b01245ced52a91b90b72e8fc509b44c0f405fab4 100644 (file)
@@ -361,8 +361,7 @@ actor action victim times duration time
 0 42 2 38 0 0
 0 42 1 39 0 0
 0 44 1 58 0 0
-0 43 98 2 0 0
-0 44 98 1 0 0
+0 43 98 1 0 0
 0 43 2 1 0 0
 0 43 1 54 0 0
 1 45 0 3 0 0
index e33d7b84a0ae76192ca3f284522e1f68b4beba57..29091e1abba695a7778d07d3a66dbf5cca94ed96 100644 (file)
@@ -51,7 +51,7 @@
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 3,7 o 99
     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 input edit l 1,7 O 0
     Play#0 command edit
@@ -67,7 +67,7 @@
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 3,7 O 99
     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 input edit l 1,7 X 0
     Play#0 command edit
@@ -75,7 +75,7 @@
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 1,7 X -1
     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 input edit l 3,7 X 98
     Play#0 command edit
@@ -83,7 +83,7 @@
     Play#0 output Play#0 6 0 640
     Play#0 input edit l 3,7 X 99
     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 input edit l 5,7 o 2
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit s 0 O -1
     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 input edit s 1 O 98
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit s 1 O 99
     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 input edit s 2 O 2
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit p 0 O -1
     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 input edit p 1 O 98
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit p 1 O 99
     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 input edit p 2 O 2
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit u 0 O -1
     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 input edit u 1 O 98
     Play#0 command edit
     Play#0 output Play#0 6 0 640
     Play#0 input edit u 1 O 99
     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 input edit u 2 O 2
     Play#0 command edit
     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 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 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 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 taken from you by deity intervention!
     Play#0 output Play#0 6 0 640
     Play#0 input ctld
     Play#0 output Play#0 1 Bye-bye