summaryrefslogtreecommitdiff
path: root/misc_cmd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-05-13 17:09:05 +0000
committerDarkvater <darkvater@openttd.org>2005-05-13 17:09:05 +0000
commit0ff942f5606d4b7abf56a2ea34e46fa64dd9feea (patch)
treedb988a0ff0ed5bb42edaf64228bc0746dfa743a7 /misc_cmd.c
parentd19438f858419226a60d3979152c8cf518506a41 (diff)
downloadopenttd-0ff942f5606d4b7abf56a2ea34e46fa64dd9feea.tar.xz
(svn r2303) - CodeChange (fix): when giving money to other players only allow transferring money that is above your loan. Eg you can't give away your loan.
- Langfix: 'goes down by' 'increases', vv for down in english.txt.
Diffstat (limited to 'misc_cmd.c')
-rw-r--r--misc_cmd.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/misc_cmd.c b/misc_cmd.c
index 469f9d862..576e2e8bf 100644
--- a/misc_cmd.c
+++ b/misc_cmd.c
@@ -208,26 +208,34 @@ int32 CmdMoneyCheat(int x, int y, uint32 flags, uint32 p1, uint32 p2)
}
/** Transfer funds (money) from one player to another.
+ * To prevent abuse in multiplayer games you can only send money to other
+ * players if you have paid off your loan (either explicitely, or implicitely
+ * given the fact that you have more money than loan).
* @param x,y unused
- * @param p1 the amount of money to transfer; max 16.000.000
+ * @param p1 the amount of money to transfer; max 20.000.000
* @param p2 the player to transfer the money to
*/
int32 CmdGiveMoney(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
+ const Player *p = DEREF_PLAYER(_current_player);
+ int32 amount = min((int32)p1, 20000000);
+
SET_EXPENSES_TYPE(EXPENSES_OTHER);
- if (!_networking || (int32)p1 <= 0 || p2 >= MAX_PLAYERS) return CMD_ERROR;
+ /* You can only transfer funds that is in excess of your loan */
+ if (p->money64 - p->current_loan < amount || amount <= 0) return CMD_ERROR;
+ if (!_networking || p2 >= MAX_PLAYERS) return CMD_ERROR;
if (flags & DC_EXEC) {
- /* Add money to player (cast to signed to prevent 'stealing' money) */
+ /* Add money to player */
PlayerID old_cp = _current_player;
_current_player = p2;
- SubtractMoneyFromPlayer(-(int32)p1);
+ SubtractMoneyFromPlayer(-amount);
_current_player = old_cp;
}
- /* Subtract money from local-player (cast to signed to prevent 'stealing' money) */
- return (int32)p1;
+ /* Subtract money from local-player */
+ return amount;
}
/** Change difficulty level/settings (server-only).