(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.
authorDarkvater
Fri, 13 May 2005 17:09:05 +0000
changeset 1799 05d56d2d0fea
parent 1798 406c46c6354f
child 1800 39966454c434
(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.
lang/english.txt
main_gui.c
misc_cmd.c
--- a/lang/english.txt	Fri May 13 17:05:03 2005 +0000
+++ b/lang/english.txt	Fri May 13 17:09:05 2005 +0000
@@ -1806,8 +1806,8 @@
 STR_4839_PRODUCTION_DOWN_BY_50                                  :{BLACK}{BIGFONT}{TOWN} {STRING} production down by 50%
 STR_483A_INSECT_INFESTATION_CAUSES                              :{BLACK}{BIGFONT}Insect infestation causes havoc at {TOWN} {STRING}!{}Production down by 50%
 STR_483B_CAN_ONLY_BE_POSITIONED                                 :{WHITE}...can only be positioned near edges of map
-STR_INDUSTRY_PROD_GOUP                                          :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} goes up by {COMMA16}%!
-STR_INDUSTRY_PROD_GODOWN                                        :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} goes down by {COMMA16}%!
+STR_INDUSTRY_PROD_GOUP                                          :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} increases {COMMA16}%!
+STR_INDUSTRY_PROD_GODOWN                                        :{BLACK}{BIGFONT}{STRING} production at {TOWN} {STRING} decreases {COMMA16}%!
 
 ##id 0x5000
 STR_5000_TRAIN_IN_TUNNEL                                        :{WHITE}Train in tunnel
@@ -2034,6 +2034,7 @@
 STR_702D_LOAN_ALREADY_REPAYED                                   :{WHITE}...no loan to repay
 STR_702E_REQUIRED                                               :{WHITE}...{CURRENCY} required
 STR_702F_CAN_T_REPAY_LOAN                                       :{WHITE}Can't repay loan...
+STR_INSUFFICIENT_FUNDS                                         	:{WHITE}Can't give away money that is loaned from the bank...
 STR_7030_SELECT_NEW_FACE_FOR_PRESIDENT                          :{BLACK}Select new face for manager
 STR_7031_CHANGE_THE_COMPANY_VEHICLE                             :{BLACK}Change the company vehicle livery
 STR_7032_CHANGE_THE_PRESIDENT_S                                 :{BLACK}Change the manager's name
--- a/main_gui.c	Fri May 13 17:05:03 2005 +0000
+++ b/main_gui.c	Fri May 13 17:09:05 2005 +0000
@@ -59,43 +59,41 @@
 	}
 }
 
-void HandleOnEditText(WindowEvent *e) {
+void HandleOnEditText(WindowEvent *e)
+{
 	const char *b = e->edittext.str;
 	int id;
 	memcpy(_decode_parameters, b, 32);
 
 	id = _rename_id;
 
-	switch(_rename_what) {
-	case 0:
-		// for empty string send "remove sign" parameter
+	switch (_rename_what) {
+	case 0: /* Rename a s sign, if string is empty, delete sign */
 		DoCommandP(0, id, 0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
 		break;
-	case 1:
-		if(*b == 0)
-			return;
+	case 1: /* Rename a waypoint */
+		if (*b == 0) return;
 		DoCommandP(0, id, 0, NULL, CMD_RENAME_WAYPOINT | CMD_MSG(STR_CANT_CHANGE_WAYPOINT_NAME));
 		break;
 #ifdef ENABLE_NETWORK
-	case 2:
-		// Speak to..
+	case 2: /* Speak to.. */
 		if (!_network_server)
 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str);
 		else
 			NetworkServer_HandleChat(NETWORK_ACTION_CHAT + (id & 0xFF), id & 0xFF, (id >> 8) & 0xFF, e->edittext.str, NETWORK_SERVER_INDEX);
 		break;
-	case 3: {
-		// Give money
-		int32 money = atoi(e->edittext.str) / GetCurrentCurrencyRate();
-		char msg[100];
-
-		money = clamp(money, 0, 0xFFFFFF); // Clamp between 16 million and 0
+	case 3: { /* Give money, you can only give money in excess of loan */
+		const Player *p = DEREF_PLAYER(_current_player);
+		int32 money = min(p->money64 - p->current_loan, atoi(e->edittext.str) / GetCurrentCurrencyRate());
+		char msg[20];
+
+		money = clamp(money, 0, 20000000); // Clamp between 20 million and 0
 
 		// Give 'id' the money, and substract it from ourself
-		if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY)) break;
+		if (!DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS))) break;
 
 		// Inform the player of this action
-		snprintf(msg, 100, "%d", money);
+		snprintf(msg, sizeof(msg), "%d", money);
 
 		if (!_network_server)
 			SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg);
@@ -103,10 +101,9 @@
 			NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_PLAYER, id + 1, msg, NETWORK_SERVER_INDEX);
 		break;
 	}
-	case 4: {// Game-Password and Company-Password
+	case 4: /* Game-Password and Company-Password */
 		SEND_COMMAND(PACKET_CLIENT_PASSWORD)(id, e->edittext.str);
 		break;
-	}
 #endif /* ENABLE_NETWORK */
 	}
 }
--- a/misc_cmd.c	Fri May 13 17:05:03 2005 +0000
+++ b/misc_cmd.c	Fri May 13 17:09:05 2005 +0000
@@ -208,26 +208,34 @@
 }
 
 /** 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).