(svn r10501) -Fix [FS#1015]: error dialog was sometimes shown on all clients when a command failed instead of only the client that actually did the command.
--- a/src/command.cpp Tue Jul 10 20:58:07 2007 +0000
+++ b/src/command.cpp Tue Jul 10 20:59:41 2007 +0000
@@ -429,7 +429,7 @@
/* toplevel network safe docommand function for the current player. must not be called recursively.
* the callback is called when the command succeeded or failed. */
-bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd)
+bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd)
{
CommandCost res, res2;
CommandProc *proc;
@@ -455,7 +455,7 @@
/** Spectator has no rights except for the (dedicated) server which
* is/can be a spectator but as the server it can do anything */
if (_current_player == PLAYER_SPECTATOR && !_network_server) {
- ShowErrorMessage(_error_message, error_part1, x, y);
+ if (my_cmd) ShowErrorMessage(_error_message, error_part1, x, y);
_cmd_text = NULL;
return false;
}
@@ -572,7 +572,7 @@
if (res2.GetCost() != 0) ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2.GetCost());
if (_additional_cash_required != 0) {
SetDParam(0, _additional_cash_required);
- ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, error_part1, x, y);
+ if (my_cmd) ShowErrorMessage(STR_0003_NOT_ENOUGH_CASH_REQUIRES, error_part1, x, y);
if (res2.GetCost() == 0) goto callb_err;
}
}
@@ -585,7 +585,7 @@
show_error:
/* show error message if the command fails? */
- if (IsLocalPlayer() && error_part1 != 0) {
+ if (IsLocalPlayer() && error_part1 != 0 && my_cmd) {
ShowErrorMessage(_error_message, error_part1, x, y);
}
--- a/src/command.h Tue Jul 10 20:58:07 2007 +0000
+++ b/src/command.h Tue Jul 10 20:59:41 2007 +0000
@@ -202,7 +202,7 @@
/* command.cpp */
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
CommandCost DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
-bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
+bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd, bool my_cmd = true);
#ifdef ENABLE_NETWORK
--- a/src/network/core/tcp.h Tue Jul 10 20:58:07 2007 +0000
+++ b/src/network/core/tcp.h Tue Jul 10 20:59:41 2007 +0000
@@ -68,6 +68,7 @@
char text[80]; ///< possible text sent for name changes etc
uint32 frame; ///< the frame in which this packet is executed
byte callback; ///< any callback function executed upon successful completion of the command
+ bool my_cmd; ///< did the command originate from "me"
};
/** Status of a client */
--- a/src/network/network_client.cpp Tue Jul 10 20:58:07 2007 +0000
+++ b/src/network/network_client.cpp Tue Jul 10 20:59:41 2007 +0000
@@ -628,6 +628,7 @@
p->Recv_string(cp->text, sizeof(cp->text));
cp->callback = p->Recv_uint8();
cp->frame = p->Recv_uint32();
+ cp->my_cmd = p->Recv_bool();
cp->next = NULL;
// The server did send us this command..
--- a/src/network/network_data.cpp Tue Jul 10 20:58:07 2007 +0000
+++ b/src/network/network_data.cpp Tue Jul 10 20:59:41 2007 +0000
@@ -62,6 +62,7 @@
CommandPacket *new_cp = MallocT<CommandPacket>(1);
*new_cp = c;
+ new_cp->my_cmd = true;
if (_local_command_queue == NULL) {
_local_command_queue = new_cp;
} else {
@@ -102,7 +103,7 @@
debug_dump_commands("ddc:cmd:%d;%d;%d;%d;%d;%d;%d;%s\n", _date, _date_fract, (int)cp->player, cp->tile, cp->p1, cp->p2, cp->cmd, cp->text);
#endif /* DUMP_COMMANDS */
- DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND);
+ DoCommandP(cp->tile, cp->p1, cp->p2, _callback_table[cp->callback], cp->cmd | CMD_NETWORK_COMMAND, cp->my_cmd);
}
#endif /* ENABLE_NETWORK */
--- a/src/network/network_server.cpp Tue Jul 10 20:58:07 2007 +0000
+++ b/src/network/network_server.cpp Tue Jul 10 20:59:41 2007 +0000
@@ -491,6 +491,7 @@
p->Send_string(cp->text);
p->Send_uint8 (cp->callback);
p->Send_uint32(cp->frame);
+ p->Send_bool (cp->my_cmd);
cs->Send_Packet(p);
}
@@ -915,11 +916,13 @@
// Callbacks are only send back to the client who sent them in the
// first place. This filters that out.
cp->callback = (new_cs != cs) ? 0 : callback;
+ cp->my_cmd = (new_cs == cs);
NetworkAddCommandQueue(new_cs, cp);
}
}
cp->callback = 0;
+ cp->my_cmd = false;
// Queue the command on the server
if (_local_command_queue == NULL) {
_local_command_queue = cp;