Author: sveinung
Date: Thu Aug 20 15:42:11 2015
New Revision: 29612

URL: http://svn.gna.org/viewcvs/freeciv?rev=29612&view=rev
Log:
Check actor and target of new actions

Check that the actor unit and, where it applies, the target city, still
exists when performing the actions Join City, Bombard and Explode Nuclear.
Ruleset specific Lua code using the action_started_* callback may have
removed them. Adding checks for this was forgotten when the actions became
action enabler controlled.

See bug #23805

Modified:
    trunk/server/unithand.c

Modified: trunk/server/unithand.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unithand.c?rev=29612&r1=29611&r2=29612&view=diff
==============================================================================
--- trunk/server/unithand.c     (original)
+++ trunk/server/unithand.c     Thu Aug 20 15:42:11 2015
@@ -2002,7 +2002,12 @@
                           struct city *pcity)
 {
   /* Sanity check: The actor is still alive. */
-  if (!unit_alive(punit->id)) {
+  if (!punit || !unit_alive(punit->id)) {
+    return FALSE;
+  }
+
+  if (!pcity || !city_exist(pcity->id)) {
+    /* City was destroyed during pre action Lua. */
     return FALSE;
   }
 
@@ -2289,6 +2294,11 @@
   struct player *pplayer = unit_owner(punit);
   struct city *pcity = tile_city(ptile);
 
+  if (!punit || !unit_alive(punit->id)) {
+    /* Actor unit was destroyed during pre action Lua. */
+    return FALSE;
+  }
+
   log_debug("Start bombard: %s %s to %d, %d.",
             nation_rule_name(nation_of_player(pplayer)),
             unit_rule_name(punit), TILE_XY(ptile));
@@ -2379,6 +2389,11 @@
 {
   struct city *pcity;
 
+  if (!punit || !unit_alive(punit->id)) {
+    /* Actor unit was destroyed during pre action Lua. */
+    return FALSE;
+  }
+
   log_debug("Start nuclear attack: %s %s against (%d, %d).",
             nation_rule_name(nation_of_player(pplayer)),
             unit_rule_name(punit),
@@ -2445,7 +2460,7 @@
     return FALSE;
   }
 
-  if (!tgt_city) {
+  if (!tgt_city || !city_exist(tgt_city->id)) {
     /* City was destroyed during pre action Lua. */
     return FALSE;
   }


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to