Author: cazfi
Date: Fri May 19 23:27:59 2017
New Revision: 35662

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

See hrm Bug #661533

Modified:
    branches/S2_6/server/scripting/api_server_edit.c

Modified: branches/S2_6/server/scripting/api_server_edit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/server/scripting/api_server_edit.c?rev=35662&r1=35661&r2=35662&view=diff
==============================================================================
--- branches/S2_6/server/scripting/api_server_edit.c    (original)
+++ branches/S2_6/server/scripting/api_server_edit.c    Fri May 19 23:27:59 2017
@@ -93,6 +93,7 @@
                                 Unit *ptransport)
 {
   struct fc_lua *fcl;
+  struct city *pcity;
 
   LUASCRIPT_CHECK_STATE(L, NULL);
   LUASCRIPT_CHECK_ARG_NIL(L, pplayer, 2, Player, NULL);
@@ -129,6 +130,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