Author: cazfi
Date: Fri May 19 23:27:46 2017
New Revision: 35660

URL: http://svn.gna.org/viewcvs/freeciv?rev=35660&view=rev
Log:
Prevent scripting API unit creation from creating stack conflicts

See hrm Bug #661533

Modified:
    trunk/server/scripting/api_server_edit.c

Modified: trunk/server/scripting/api_server_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/scripting/api_server_edit.c?rev=35660&r1=35659&r2=35660&view=diff
==============================================================================
--- trunk/server/scripting/api_server_edit.c    (original)
+++ trunk/server/scripting/api_server_edit.c    Fri May 19 23:27:46 2017
@@ -94,6 +94,7 @@
                                 Unit *ptransport)
 {
   struct fc_lua *fcl;
+  struct city *pcity;
 
   LUASCRIPT_CHECK_STATE(L, NULL);
   LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
@@ -130,6 +131,19 @@
     return NULL;
   }
 
+  if (is_non_allied_unit_tile(ptile, pplayer)) {
+    luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
+                                  "enemy unit");
+    return NULL;
+  }
+
+  pcity = tile_city(ptile);
+  if (pcity != NULL && !pplayers_allied(pplayer, city_owner(pcity))) {
+    luascript_log(fcl, LOG_ERROR, "create_unit_full: tile is occupied by "
+                                  "enemy city");
+    return NULL;
+  }
+
   return create_unit_full(pplayer, ptile, ptype, veteran_level,
                           homecity ? homecity->id : 0, moves_left,
                           hp_left, ptransport);


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

Reply via email to