]> git.pond.sub.org Git - empserver/commitdiff
Fix generation numbers for order command
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 26 Jan 2010 21:20:16 +0000 (22:20 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 26 Jan 2010 21:20:16 +0000 (22:20 +0100)
orde() uses a "clever" trick to get away with just one
check_ship_ok(): it makes a copy of the ship in the beginning, and
checks it at the end.  Generation numbers (commit 2fa5f652) break this
trick.  It could be fixed by manually marking the ship fresh.
Instead, check the ship the stupid, straightforward way, without a
copy.

src/lib/commands/orde.c

index a310e6c1a588cf25583308d27fe38409ea8edf5f..5151a474b62be014d9a50509b3e54376bd09d03d 100644 (file)
@@ -63,7 +63,6 @@ orde(void)
     int scuttling = 0;
     struct nstr_item nb;
     struct shpstr ship;
     int scuttling = 0;
     struct nstr_item nb;
     struct shpstr ship;
-    struct shpstr start;       /* Used for checking database */
     struct ichrstr *i1;
     coord p0x, p0y, p1x, p1y;
     int i;
     struct ichrstr *i1;
     coord p0x, p0y, p1x, p1y;
     int i;
@@ -83,13 +82,14 @@ orde(void)
                continue;
            }
        }
                continue;
            }
        }
-       memcpy(&start, &ship, sizeof(struct shpstr));
        sprintf(prompt,
                "Ship #%d, declare, cancel, suspend, resume, level? ",
                ship.shp_uid);
        p = getstarg(player->argp[2], prompt, buf);
        if (player->aborted || !p || !*p)
            return RET_FAIL;
        sprintf(prompt,
                "Ship #%d, declare, cancel, suspend, resume, level? ",
                ship.shp_uid);
        p = getstarg(player->argp[2], prompt, buf);
        if (player->aborted || !p || !*p)
            return RET_FAIL;
+       if (!check_ship_ok(&ship))
+           return RET_FAIL;
        switch (*p) {
        default:
            pr("Bad order type!\n");
        switch (*p) {
        default:
            pr("Bad order type!\n");
@@ -126,6 +126,8 @@ orde(void)
            p = getstarg(player->argp[4], "Second dest? ", buf);
            if (!p)
                return RET_FAIL;
            p = getstarg(player->argp[4], "Second dest? ", buf);
            if (!p)
                return RET_FAIL;
+           if (!check_ship_ok(&ship))
+               return RET_FAIL;
            if (!*p || !strcmp(p, "-")) {
                pr("A one-way order has been accepted.\n");
            } else if (!strncmp(p, "s", 1)) {
            if (!*p || !strcmp(p, "-")) {
                pr("A one-way order has been accepted.\n");
            } else if (!strncmp(p, "s", 1)) {
@@ -169,6 +171,8 @@ orde(void)
            sprintf(buf1, "Field (1-%d) ", TMAX);
            if (!getstarg(player->argp[3], buf1, buf))
                return RET_SYN;
            sprintf(buf1, "Field (1-%d) ", TMAX);
            if (!getstarg(player->argp[3], buf1, buf))
                return RET_SYN;
+           if (!check_ship_ok(&ship))
+               return RET_FAIL;
            sub = atoi(buf);
            /* check to make sure value in within range. */
            if (sub > TMAX || sub < 1) {
            sub = atoi(buf);
            /* check to make sure value in within range. */
            if (sub > TMAX || sub < 1) {
@@ -198,6 +202,8 @@ orde(void)
                                  buf);
                    if (!p1)
                        return RET_SYN;
                                  buf);
                    if (!p1)
                        return RET_SYN;
+                   if (!check_ship_ok(&ship))
+                       return RET_FAIL;
                    level = atoi(p1);
                    if (level < 0) {
                        level = 0;      /* prevent negatives. */
                    level = atoi(p1);
                    if (level < 0) {
                        level = 0;      /* prevent negatives. */
@@ -216,6 +222,8 @@ orde(void)
                                  buf);
                    if (!p1)
                        return RET_SYN;
                                  buf);
                    if (!p1)
                        return RET_SYN;
+                   if (!check_ship_ok(&ship))
+                       return RET_FAIL;
                    level = atoi(p1);
                    if (level < 0) {
                        level = 0;
                    level = atoi(p1);
                    if (level < 0) {
                        level = 0;
@@ -273,15 +281,6 @@ orde(void)
                ship.shp_tend[i] = tcomm;
            }
        }
                ship.shp_tend[i] = tcomm;
            }
        }
-       /*
-          **  Write ship back to database, then give it
-          **  a kick down the autonav route if necessary.
-        */
-
-
-       /* Now do a sanity check. */
-       if (!check_ship_ok(&start))
-           return RET_SYN;
 
        putship(ship.shp_uid, &ship);
     }
 
        putship(ship.shp_uid, &ship);
     }