(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.

This commit is contained in:
rubidium 2007-07-10 20:59:41 +00:00
parent 0cd8274658
commit 872e74c028
6 changed files with 12 additions and 6 deletions

View File

@ -429,7 +429,7 @@ Money GetAvailableMoneyForCommand()
/* 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 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
/** 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 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
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 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
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);
}

View File

@ -202,7 +202,7 @@ static const CommandCost CMD_ERROR = CommandCost((StringID)INVALID_STRING_ID);
/* 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

View File

@ -68,6 +68,7 @@ struct CommandPacket {
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 */

View File

@ -628,6 +628,7 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_COMMAND)
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..

View File

@ -62,6 +62,7 @@ void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, Comma
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 @@ void NetworkExecuteCommand(CommandPacket *cp)
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 */

View File

@ -491,6 +491,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_COMMAND)(NetworkTCPSocketHandler *cs
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 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
// 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;