From 0ff942f5606d4b7abf56a2ea34e46fa64dd9feea Mon Sep 17 00:00:00 2001 From: Darkvater Date: Fri, 13 May 2005 17:09:05 +0000 Subject: (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. --- misc_cmd.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'misc_cmd.c') 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). -- cgit v1.2.3-54-g00ecf