summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-01-27 21:00:05 +0000
committerbjarni <bjarni@openttd.org>2005-01-27 21:00:05 +0000
commit72b9358291c9717b596c34a9dac34a9a20a57853 (patch)
tree5bdf21fd520f2315aba284830d98f9db10e8e388
parent690027d1abd9c837a9d86a8d1be98879ce51c06c (diff)
downloadopenttd-72b9358291c9717b596c34a9dac34a9a20a57853.tar.xz
(svn r1700) - Fix: Hacked clients can no longer be used to build vehicles that are not available yet (Hackykid)
-rw-r--r--aircraft_cmd.c2
-rw-r--r--engine.c24
-rw-r--r--engine.h1
-rw-r--r--roadveh_cmd.c2
-rw-r--r--ship_cmd.c2
-rw-r--r--train_cmd.c2
6 files changed, 33 insertions, 0 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 46a846d57..7525b6a6c 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -161,6 +161,8 @@ int32 CmdBuildAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
const AircraftVehicleInfo *avi = AircraftVehInfo(p1);
Engine *e;
+ if (!(IsEngineBuildable(p1, VEH_Aircraft))) return CMD_ERROR;
+
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
value = EstimateAircraftCost(p1);
diff --git a/engine.c b/engine.c
index c6cc4bf4c..93cba6351 100644
--- a/engine.c
+++ b/engine.c
@@ -906,5 +906,29 @@ const ChunkHandler _engine_chunk_handlers[] = {
{ '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;
+}
+
+
diff --git a/engine.h b/engine.h
index 9756bdb13..52fa3a583 100644
--- a/engine.h
+++ b/engine.h
@@ -133,6 +133,7 @@ void AcceptEnginePreview(Engine *e, int player);
void LoadCustomEngineNames(void);
void DeleteCustomEngineNames(void);
+bool IsEngineBuildable(int engine, byte type);
enum {
NUM_NORMAL_RAIL_ENGINES = 54,
diff --git a/roadveh_cmd.c b/roadveh_cmd.c
index c78aa79d8..f2a5c88c8 100644
--- a/roadveh_cmd.c
+++ b/roadveh_cmd.c
@@ -115,6 +115,8 @@ int32 CmdBuildRoadVeh(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/ship_cmd.c b/ship_cmd.c
index ea28db771..88519beb8 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -816,6 +816,8 @@ int32 CmdBuildShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
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);
diff --git a/train_cmd.c b/train_cmd.c
index 1ce1631ee..c987b007b 100644
--- a/train_cmd.c
+++ b/train_cmd.c
@@ -525,6 +525,8 @@ int32 CmdBuildRailVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
Engine *e;
uint tile;
+ if (!(IsEngineBuildable(p1, VEH_Train))) return CMD_ERROR;
+
_cmd_build_rail_veh_var1 = 0;
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);