From: Markus Armbruster Date: Tue, 15 Jul 2008 11:55:42 +0000 (-0400) Subject: Fix command abortion after getting player input X-Git-Tag: v4.3.16~71 X-Git-Url: http://git.pond.sub.org/?p=empserver;a=commitdiff_plain;h=9eda5f87b8a3ddb67c972b0545d97992328c379f Fix command abortion after getting player input 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 --- diff --git a/src/lib/commands/arm.c b/src/lib/commands/arm.c index 7194fd6cd..e689e87be 100644 --- a/src/lib/commands/arm.c +++ b/src/lib/commands/arm.c @@ -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; diff --git a/src/lib/commands/deli.c b/src/lib/commands/deli.c index bb7cbd627..a52e5f0f8 100644 --- a/src/lib/commands/deli.c +++ b/src/lib/commands/deli.c @@ -55,7 +55,7 @@ deli(void) if (!snxtsct(&nstr, player->argp[2])) return RET_SYN; - while (!player->aborted && nxtsct(&nstr, §) > 0) { + while (nxtsct(&nstr, §) > 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) { diff --git a/src/lib/commands/mfir.c b/src/lib/commands/mfir.c index 787aee04b..398b3b7f1 100644 --- a/src/lib/commands/mfir.c +++ b/src/lib/commands/mfir.c @@ -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) || diff --git a/src/lib/commands/mine.c b/src/lib/commands/mine.c index 4ff3d1b73..74f441137 100644 --- a/src/lib/commands/mine.c +++ b/src/lib/commands/mine.c @@ -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; diff --git a/src/lib/commands/orde.c b/src/lib/commands/orde.c index 716460485..4bda521dd 100644 --- a/src/lib/commands/orde.c +++ b/src/lib/commands/orde.c @@ -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)) { diff --git a/src/lib/commands/powe.c b/src/lib/commands/powe.c index d97335326..55046a5c0 100644 --- a/src/lib/commands/powe.c +++ b/src/lib/commands/powe.c @@ -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; diff --git a/src/lib/commands/rang.c b/src/lib/commands/rang.c index 9b1f43fac..96ff29a69 100644 --- a/src/lib/commands/rang.c +++ b/src/lib/commands/rang.c @@ -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); diff --git a/src/lib/commands/sail.c b/src/lib/commands/sail.c index 0e3fdf055..0f1fa0f89 100644 --- a/src/lib/commands/sail.c +++ b/src/lib/commands/sail.c @@ -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; } diff --git a/src/lib/commands/shut.c b/src/lib/commands/shut.c index 24801e21d..8a69db57c 100644 --- a/src/lib/commands/shut.c +++ b/src/lib/commands/shut.c @@ -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) diff --git a/src/lib/commands/tend.c b/src/lib/commands/tend.c index 8c6f026d6..de0c2652d 100644 --- a/src/lib/commands/tend.c +++ b/src/lib/commands/tend.c @@ -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; diff --git a/src/lib/subs/plnsub.c b/src/lib/subs/plnsub.c index cd3801374..73f2d7973 100644 --- a/src/lib/subs/plnsub.c +++ b/src/lib/subs/plnsub.c @@ -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