(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
--- a/aircraft_cmd.c Thu Jan 27 20:38:19 2005 +0000
+++ b/aircraft_cmd.c Thu Jan 27 21:00:05 2005 +0000
@@ -161,6 +161,8 @@
const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
Engine *e;
+ if (!(IsEngineBuildable(p1, VEH_Aircraft))) return CMD_ERROR;
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
value = EstimateAircraftCost(p1);
--- a/engine.c Thu Jan 27 20:38:19 2005 +0000
+++ b/engine.c Thu Jan 27 21:00:05 2005 +0000
@@ -906,5 +906,29 @@
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF | CH_LAST},
};
+/*
+ * returns true if an engine is valid, and it is of the specified type, and buildable by the current player, false otherwise
+ *
+ * engine = index of the engine to check
+ * type = the type the engine should be of (VEH_xxx)
+ */
+bool IsEngineBuildable(int engine, byte type) {
+ Engine *e;
+
+ // check if it's an engine that is in the engine array
+ if (0 > engine || engine >= TOTAL_NUM_ENGINES ) return false;
+
+ e = DEREF_ENGINE(engine);
+
+ // check if it's an engine of specified type
+ if (e->type != type) return false;
+
+ // check if it's available
+ if (!HASBIT(e->player_avail, _current_player)) return false;
+
+ return true;
+}
+
+
--- a/engine.h Thu Jan 27 20:38:19 2005 +0000
+++ b/engine.h Thu Jan 27 21:00:05 2005 +0000
@@ -133,6 +133,7 @@
void LoadCustomEngineNames(void);
void DeleteCustomEngineNames(void);
+bool IsEngineBuildable(int engine, byte type);
enum {
NUM_NORMAL_RAIL_ENGINES = 54,
--- a/roadveh_cmd.c Thu Jan 27 20:38:19 2005 +0000
+++ b/roadveh_cmd.c Thu Jan 27 21:00:05 2005 +0000
@@ -115,6 +115,8 @@
uint tile = TILE_FROM_XY(x,y);
Engine *e;
+ if (!(IsEngineBuildable(p1, VEH_Road))) return CMD_ERROR;
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
cost = EstimateRoadVehCost(p1);
--- a/ship_cmd.c Thu Jan 27 20:38:19 2005 +0000
+++ b/ship_cmd.c Thu Jan 27 21:00:05 2005 +0000
@@ -816,6 +816,8 @@
uint tile = TILE_FROM_XY(x,y);
Engine *e;
+ if (!(IsEngineBuildable(p1, VEH_Ship))) return CMD_ERROR;
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
value = EstimateShipCost(p1);
--- a/train_cmd.c Thu Jan 27 20:38:19 2005 +0000
+++ b/train_cmd.c Thu Jan 27 21:00:05 2005 +0000
@@ -525,6 +525,8 @@
Engine *e;
uint tile;
+ if (!(IsEngineBuildable(p1, VEH_Train))) return CMD_ERROR;
+
_cmd_build_rail_veh_var1 = 0;
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);