summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-08-31 17:15:46 +0000
committerrubidium <rubidium@openttd.org>2007-08-31 17:15:46 +0000
commit7f21de5ea92bc27492330bb6b06528310123653d (patch)
treeb2f6f8944befade6300c515c9c9ab0260142d919 /src
parent2c8e50f20c84f65b19bc1d983e2715f827ee19d8 (diff)
downloadopenttd-7f21de5ea92bc27492330bb6b06528310123653d.tar.xz
(svn r11018) -Fix [FS#1169]: Disallow buying/selling shares in your own company or a bankrupted/non-existant company.
Diffstat (limited to 'src')
-rw-r--r--src/economy.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index f120feb55..c20a7aca6 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -1802,12 +1802,17 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint32
Player *p;
CommandCost cost;
- /* Check if buying shares is allowed (protection against modified clients */
- if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
+ /* Check if buying shares is allowed (protection against modified clients) */
+ /* Cannot buy own shares */
+ if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
- SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = GetPlayer((PlayerID)p1);
+ /* Cannot buy shares of non-existent nor bankrupted company */
+ if (!p->is_active) return CMD_ERROR;
+
+ SET_EXPENSES_TYPE(EXPENSES_OTHER);
+
/* Protect new companies from hostile takeovers */
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
@@ -1848,12 +1853,17 @@ CommandCost CmdSellShareInCompany(TileIndex tile, uint32 flags, uint32 p1, uint3
Player *p;
Money cost;
- /* Check if buying shares is allowed (protection against modified clients */
- if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares) return CMD_ERROR;
+ /* Check if selling shares is allowed (protection against modified clients) */
+ /* Cannot sell own shares */
+ if (!IsValidPlayer((PlayerID)p1) || !_patches.allow_shares || _current_player == (PlayerID)p1) return CMD_ERROR;
- SET_EXPENSES_TYPE(EXPENSES_OTHER);
p = GetPlayer((PlayerID)p1);
+ /* Cannot sell shares of non-existent nor bankrupted company */
+ if (!p->is_active) return CMD_ERROR;
+
+ SET_EXPENSES_TYPE(EXPENSES_OTHER);
+
/* Those lines are here for network-protection (clients can be slow) */
if (GetAmountOwnedBy(p, _current_player) == 0) return CommandCost();