From 546e1220e099a2ba37b9468c4b861eb240c6e4aa Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Wed, 16 Jan 2013 21:07:21 +0100 Subject: [PATCH] edit: Don't permit putting a land unit or plane on two carriers Only one of struct lndstr members lnd_ship, lnd_land may be non-negative. When a deity screws that up, the server oopses. Be nice: when setting one, zap the other. Same for struct plnstr members pln_ship, pln_land. Signed-off-by: Markus Armbruster --- src/lib/commands/edit.c | 8 ++++++++ tests/actofgod/actofgod.xdump | 4 ++-- tests/actofgod/server.log | 2 -- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index c8b494f41..f003514f7 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -852,6 +852,8 @@ edit_land(struct lndstr *land, char op, int arg, char *p) case 'Y': if (arg < -1 || arg >= ef_nelem(EF_LAND)) return RET_SYN; + if (arg >= 0 && arg != land->lnd_land) + land->lnd_ship = -1; land->lnd_land = arg; break; case 'U': @@ -901,6 +903,8 @@ edit_land(struct lndstr *land, char op, int arg, char *p) case 'S': if (arg < -1 || arg >= ef_nelem(EF_SHIP)) return RET_SYN; + if (arg >= 0 && arg != land->lnd_ship) + land->lnd_land = -1; land->lnd_ship = arg; break; case 'Z': @@ -1027,11 +1031,15 @@ edit_plane(struct plnstr *plane, char op, int arg, char *p) case 's': if (arg < -1 || arg >= ef_nelem(EF_SHIP)) return RET_SYN; + if (arg >= 0 && arg != plane->pln_ship) + plane->pln_land = -1; plane->pln_ship = arg; break; case 'y': if (arg < -1 || arg >= ef_nelem(EF_LAND)) return RET_SYN; + if (arg >= 0 && arg != plane->pln_land) + plane->pln_ship = -1; plane->pln_land = arg; break; case 'f': diff --git a/tests/actofgod/actofgod.xdump b/tests/actofgod/actofgod.xdump index df98f2db0..ac03677cb 100644 --- a/tests/actofgod/actofgod.xdump +++ b/tests/actofgod/actofgod.xdump @@ -252,7 +252,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius wing range 1 98 1 -1 0 10 0 0 100 0 0 none 0 "" 9 0 -1 -1 () 0 0.00000 2 2 3 -1 0 10 -127 0 50 0 0 none 0 "" 0 0 -1 -1 (airburst) 0 0.00000 3 3 1 -1 0 10 -127 0 50 0 0 none 0 "a" 0 0 3 -1 () 0 0.00000 -4 3 1 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 4 -1 () 0 0.00000 +4 3 1 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 4 () 0 0.00000 5 3 1 -1 0 100 127 0 32767 0 0 none 0 "" 18 0 -1 -1 () 0 0.00000 6 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 7 0 0 0 0 0 0 0 0 0 0 none 0 "" 0 0 -1 -1 () 0 0.00000 @@ -305,7 +305,7 @@ uid owner xloc yloc type effic mobil off tech opx opy mission radius army ship h 1 98 1 -1 6 10 0 0 100 0 0 none 0 "" -1 0 42 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 2 2 3 -1 6 10 -127 0 50 0 0 none 0 "" -1 0 0 (group) "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 3 3 1 -1 6 10 -127 0 50 0 0 none 0 "a" 3 0 0 (injured) "jj" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 -4 3 1 -1 6 100 127 0 32767 0 0 none 0 "" 4 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 +4 3 1 -1 6 100 127 0 32767 0 0 none 0 "" -1 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 4 0 5 3 1 -1 6 100 127 0 32767 0 0 none 0 "" -1 127 100 () "" 0 25 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 6 0 0 0 0 0 0 0 0 0 0 none 0 "" -1 0 0 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 7 0 0 0 0 0 0 0 0 0 0 none 0 "" -1 0 0 () "" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 healthy 0 -1 0 diff --git a/tests/actofgod/server.log b/tests/actofgod/server.log index ad2aae2fe..299fdaaa4 100644 --- a/tests/actofgod/server.log +++ b/tests/actofgod/server.log @@ -10,8 +10,6 @@ tester@127.0.0.1 logged in as country #0 Oops: id < 0 in ../src/lib/common/file.c:973 Oops: id < 0 in ../src/lib/common/file.c:973 Oops: id < 0 in ../src/lib/common/file.c:973 -Oops: ship >= 0 && land >= 0 in ../src/lib/subs/plane.c:77 -Oops: ship >= 0 && land >= 0 in ../src/lib/subs/land.c:78 tester@127.0.0.1 logged out, country #0 Shutdown commencing (cleaning up threads.) Server shutting down on signal 15 -- 2.43.0