diff options
author | rubidium <rubidium@openttd.org> | 2007-06-10 21:34:45 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2007-06-10 21:34:45 +0000 |
commit | a2b505e4ca5973cbf087ea856431fe8922687e1b (patch) | |
tree | 17008f25bdbdfca605678108e741ba3e4e7a346d /src | |
parent | c33e651393c8dbab8582ce7f844b5838691e02c4 (diff) | |
download | openttd-a2b505e4ca5973cbf087ea856431fe8922687e1b.tar.xz |
(svn r10087) -Fix [FS#834]: multiple subsequent "give money" actions could result in duplicate messages that money has been transfered when it only happened once.
Diffstat (limited to 'src')
-rw-r--r-- | src/callback_table.cpp | 4 | ||||
-rw-r--r-- | src/main_gui.cpp | 28 |
2 files changed, 19 insertions, 13 deletions
diff --git a/src/callback_table.cpp b/src/callback_table.cpp index 30dca7cac..21bd39a4c 100644 --- a/src/callback_table.cpp +++ b/src/callback_table.cpp @@ -33,6 +33,7 @@ CommandCallback CcPlaySound10; CommandCallback CcPlaceSign; CommandCallback CcTerraform; CommandCallback CcBuildTown; +CommandCallback CcGiveMoney; /* rail_gui.cpp */ CommandCallback CcPlaySound1E; @@ -87,7 +88,8 @@ CommandCallback *_callback_table[] = { /* 0x17 */ CcCloneShip, /* 0x18 */ CcCloneTrain, /* 0x19 */ CcAI, - /* 0x1A */ CcCloneVehicle + /* 0x1A */ CcCloneVehicle, + /* 0x1B */ CcGiveMoney, }; const int _callback_table_count = lengthof(_callback_table); diff --git a/src/main_gui.cpp b/src/main_gui.cpp index ddf394318..45c8bef49 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -58,6 +58,21 @@ extern void GenerateIndustries(); extern bool GenerateTowns(); +void CcGiveMoney(bool success, TileIndex tile, uint32 p1, uint32 p2) +{ + if (!success) return; + + char msg[20]; + /* Inform the player of this action */ + snprintf(msg, sizeof(msg), "%d", p1); + + if (!_network_server) { + SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg); + } else { + NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, p2, msg, NETWORK_SERVER_INDEX); + } +} + void HandleOnEditText(const char *str) { int id = _rename_id; @@ -75,22 +90,11 @@ void HandleOnEditText(const char *str) case 3: { // Give money, you can only give money in excess of loan const Player *p = GetPlayer(_current_player); int32 money = min(p->money64 - p->current_loan, atoi(str) / _currency->rate); - char msg[20]; money = clamp(money, 0, 20000000); // Clamp between 20 million and 0 /* Give 'id' the money, and substract it from ourself */ - int32 ret = DoCommandP(0, money, id, NULL, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS)); - if (CmdFailed(ret) || ret == 0) break; // We either did something wrong, or we don't have any money anymore - - /* Inform the player of this action */ - snprintf(msg, sizeof(msg), "%d", money); - - if (!_network_server) { - SEND_COMMAND(PACKET_CLIENT_CHAT)(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg); - } else { - NetworkServer_HandleChat(NETWORK_ACTION_GIVE_MONEY, DESTTYPE_TEAM, id, msg, NETWORK_SERVER_INDEX); - } + DoCommandP(0, money, id, CcGiveMoney, CMD_GIVE_MONEY | CMD_MSG(STR_INSUFFICIENT_FUNDS)); } break; #endif /* ENABLE_NETWORK */ default: NOT_REACHED(); |