]> git.pond.sub.org Git - empserver/commitdiff
Fix command abortion after getting player input
authorMarkus Armbruster <armbru@pond.sub.org>
Tue, 15 Jul 2008 11:55:42 +0000 (07:55 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 21 Jul 2008 11:19:18 +0000 (07:19 -0400)
The old code didn't honor command abortion at the following prompts:

* arm third argument

* deliver fourth argument (also simplify)

* fire third argument

* fly and recon prompt for carrier to land on: pln_onewaymission()
  treated abort like empty input, which made planes attempt landing in
  the sector.

* lmine second argument

* order d fourth argument

* power c nat(s) argument

* range second argument

* sail second argument

* shutdown both arguments (first one was broken in commit 84cfd670,
  v4.3.10, second one never worked).

* tend third argument

src/lib/commands/arm.c
src/lib/commands/deli.c
src/lib/commands/mfir.c
src/lib/commands/mine.c
src/lib/commands/orde.c
src/lib/commands/powe.c
src/lib/commands/rang.c
src/lib/commands/sail.c
src/lib/commands/shut.c
src/lib/commands/tend.c
src/lib/subs/plnsub.c

index 7194fd6cdf159e6205cfc91954d1fda3217dc801..e689e87be866675bd919112fbfac62d0eb2aeea0 100644 (file)
@@ -96,6 +96,8 @@ arm(void)
            return RET_FAIL;
        }
        p = getstarg(player->argp[3], "Airburst [n]? ", buf);
+       if (!p)
+           return RET_SYN;
 
        if (!check_plane_ok(&pl) || !check_nuke_ok(&nuke))
            return RET_FAIL;
@@ -106,7 +108,7 @@ arm(void)
            return RET_FAIL;
        }
 
-       if (p && (*p == 'y' || *p == 'Y'))
+       if (*p == 'y' || *p == 'Y')
            pl.pln_flags |= PLN_AIRBURST;
        else
            pl.pln_flags &= ~PLN_AIRBURST;
index bb7cbd6273965e0035ac6f83f1372047c7a023d0..a52e5f0f82eda00fb9608e4710327fd6b9c31f5c 100644 (file)
@@ -55,7 +55,7 @@ deli(void)
     if (!snxtsct(&nstr, player->argp[2]))
        return RET_SYN;
 
-    while (!player->aborted && nxtsct(&nstr, &sect) > 0) {
+    while (nxtsct(&nstr, &sect) > 0) {
        if (!player->owner)
            continue;
 
@@ -69,15 +69,17 @@ deli(void)
        if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
            return RET_SYN;
        if (*p != 'q') {
-           sprintf(prompt, "%s %s %s direction? ",
-                   xyas(nstr.x, nstr.y, player->cnum),
-                   dchr[sect.sct_type].d_name, ich->i_name);
            if (((*p >= '0') && (*p <= '9')) || *p == '+') {
                thresh = atoi(p) & ~0x7;
                if (*p == '+')
                    p = NULL;
                else {
+                   sprintf(prompt, "%s %s %s direction? ",
+                           xyas(nstr.x, nstr.y, player->cnum),
+                           dchr[sect.sct_type].d_name, ich->i_name);
                    p = getstarg(player->argp[4], prompt, buf);
+                   if (!p)
+                       return RET_SYN;
                }
            }
            if (p && *p) {
index 787aee04b04ff3323d970e1f7e165e125b759477..398b3b7f19b4f6e8fd5a90ee98cb9c4a387b977a 100644 (file)
@@ -118,10 +118,6 @@ multifire(void)
     if (!snxtitem(&nbst, type, ptr))
        return RET_SYN;
 
-    if (player->aborted) {
-       pr("Fire aborted.\n");
-       return RET_OK;
-    }
     while (nxtitem(&nbst, &item)) {
        if (type == EF_LAND) {
            if (!getland(item.land.lnd_uid, &fland))
@@ -220,13 +216,11 @@ multifire(void)
            fy = fsect.sct_y;
        }
 
-       if ((ptr = getstarg(player->argp[3], "Firing at? ", buf)) == 0
-           || *ptr == '\0')
-           continue;
-       if (player->aborted) {
-           pr("Fire aborted.\n");
+       ptr = getstarg(player->argp[3], "Firing at? ", buf);
+       if (!ptr)
+           return RET_SYN;
+       if (!*ptr)
            continue;
-       }
        if (!issector(ptr)) {
            vshipno = atoi(ptr);
            if (vshipno < 0 || !getship(vshipno, &vship) ||
index 4ff3d1b73a8f6d04944e1798872d658d77a38812..74f441137c6f980ab9a70a9682d32ca491533568 100644 (file)
@@ -128,9 +128,11 @@ landmine(void)
               sect.sct_mines, xyas(sect.sct_x, sect.sct_y, player->cnum));
        sprintf(prompt, "Drop how many mines from %s? ", prland(&land));
        mines_wanted = onearg(player->argp[2], prompt);
-       if (!check_land_ok(&land))
+       if (mines_wanted < 0)
+           return RET_SYN;
+       if (mines_wanted == 0)
            continue;
-       if (mines_wanted <= 0)
+       if (!check_land_ok(&land))
            continue;
        land.lnd_mission = 0;
        total_mines_laid = 0;
index 716460485d408294610ce382425779b29a27be39..4bda521ddb865262ac4b3fd3e6337943ef7398f7 100644 (file)
@@ -136,7 +136,9 @@ orde(void)
 
            if (!orders) {
                p = getstarg(player->argp[4], "Second dest? ", buf);
-               if (!p || !*p || !strcmp(p, "-")) {
+               if (!p)
+                   return RET_SYN;
+               if (!*p || !strcmp(p, "-")) {
                    orders = 1;
                    pr("A one-way order has been accepted.\n");
                } else if (!strncmp(p, "s", 1)) {
index d97335326792238f2a20ac0c7e3140c812069189..55046a5c095dea8438f33ffb6e43874d93860cd0 100644 (file)
@@ -94,7 +94,8 @@ powe(void)
 
     if (player->argp[i]) {
        if (player->argp[i][0] == 'c') {
-           snxtitem(&ni, EF_NATION, player->argp[i + 1]);
+           if (!snxtitem(&ni, EF_NATION, player->argp[i + 1]))
+               return RET_SYN;
            while (nxtitem(&ni, &nat)) {
                if (nat.nat_stat == STAT_UNUSED)
                    continue;
index 9b1f43facebbea009bc829f20ac4d5dfae9baad3..96ff29a69e32f8f69b94afbe1b4a32e3e6439adc 100644 (file)
@@ -52,9 +52,11 @@ range(void)
        if (!player->owner || plane.pln_own == 0)
            continue;
        p = getstarg(player->argp[2], "New range? ", buf);
+       if (!p)
+           return RET_SYN;
        if (!check_plane_ok(&plane))
            return RET_SYN;
-       if (!p || (i = atoi(p)) < 0)
+       if ((i = atoi(p)) < 0)
            continue;
        rmax = pln_range_max(&plane);
        plane.pln_range = MIN(rmax, i);
index 0e3fdf05544d1b46960981519fb38a68ffdc4163..0f1fa0f8911fb0ee9c636f7fc4940a96c9c683f9 100644 (file)
@@ -110,7 +110,7 @@ cmd_sail_ship(struct nstr_item *nstr)
     struct shpstr ship;
     char navpath[MAX_PATH_LEN];
 
-    while (!player->aborted && nxtitem(nstr, &ship)) {
+    while (nxtitem(nstr, &ship)) {
        if (!player->owner || ship.shp_own == 0)
            continue;
        if ((ship.shp_autonav & AN_AUTONAV) &&
@@ -123,13 +123,13 @@ cmd_sail_ship(struct nstr_item *nstr)
           xyas(ship.shp_x, ship.shp_y, ship.shp_own));
        cp = getpath(navpath, player->argp[2],
                     ship.shp_x, ship.shp_y, 0, 0, P_SAILING);
+       if (!cp)
+           return RET_SYN;
        if (!check_ship_ok(&ship))
            continue;
-       if (!player->aborted) {
-           strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2);
-           ship.shp_mission = 0;
-           putship(ship.shp_uid, &ship);
-       }
+       strncpy(ship.shp_path, cp, sizeof(ship.shp_path) - 2);
+       ship.shp_mission = 0;
+       putship(ship.shp_uid, &ship);
     }
     return RET_OK;
 }
index 24801e21d829c9d1511af938fcecd97c5d10ba7b..8a69db57c750e784542ab350bf4664157907d952 100644 (file)
@@ -50,10 +50,15 @@ shut(void)
     shutdown_minutes =
        onearg(player->argp[1],
               "Time until shutdown in minutes (-1 to abort shutdown sequence)? ");
-    if (!updates_disabled())
-       if (!(p = getstarg(player->argp[2], "Disable update [y]? ", buf))
-           || *p != 'n')
+    if (player->aborted)
+       return RET_SYN;
+    if (!updates_disabled()) {
+       p = getstarg(player->argp[2], "Disable update [y]? ", buf);
+       if (!p)
+           return RET_SYN;
+       if (*p != 'n')
            disa();
+    }
 
     shutdown_was_pending = shutdown_initiate(shutdown_minutes);
     if (shutdown_was_pending < 0)
index 8c6f026d65f26e6bc5dfda9dfd38f7eac4598922..de0c2652dc543c3918041bc6f4b58726dd8d2ab2 100644 (file)
@@ -90,7 +90,10 @@ tend(void)
        if (type == EF_LAND) {
            sprintf(prompt, "Land unit(s) to tend from %s? ",
                    prship(&tender));
-           if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+           p = getstarg(player->argp[3], prompt, buf);
+           if (!p)
+               return RET_SYN;
+           if (!*p)
                continue;
            if (!check_ship_ok(&tender))
                return RET_SYN;
@@ -100,7 +103,10 @@ tend(void)
        }
        sprintf(prompt, "Number of %s to tend from %s? ",
                ip->i_name, prship(&tender));
-       if (!(p = getstarg(player->argp[3], prompt, buf)) || !*p)
+       p = getstarg(player->argp[3], prompt, buf);
+       if (!p)
+           return RET_SYN;
+       if (!*p)
            continue;
        if (!check_ship_ok(&tender))
            return RET_SYN;
index cd38013741c9261ba674a283cc5fe063d8c565d3..73f2d7973fc7c88c38e4404005e42b64b581780e 100644 (file)
@@ -114,7 +114,10 @@ pln_onewaymission(struct sctstr *target, int *shipno, int *flagp)
     nships = carriersatxy(target->sct_x, target->sct_y, player->cnum);
     if (nships) {
        for (;;) {
-           if (!(p = getstarg(0, "Carrier #? ", buf)) || !*p)
+           p = getstring("Carrier #? ", buf);
+           if (!p)
+               return -1;
+           if (!*p)
                break;
            cno = atoi(p);
            if (cno < 0