diff --git a/cockatrice/src/game/log/message_log_widget.cpp b/cockatrice/src/game/log/message_log_widget.cpp index 53f671256..fe564b531 100644 --- a/cockatrice/src/game/log/message_log_widget.cpp +++ b/cockatrice/src/game/log/message_log_widget.cpp @@ -806,6 +806,12 @@ void MessageLogWidget::logUndoDraw(PlayerLogic *player, QString cardName) } } +void MessageLogWidget::logUndoDrawFailed(PlayerLogic *player) +{ + appendHtmlServerMessage( + tr("%1 failed to undo their last draw.").arg(sanitizeHtml(player->getPlayerInfo()->getName()))); +} + void MessageLogWidget::setContextJudgeName(QString name) { messagePrefix = QString(""); @@ -839,6 +845,7 @@ void MessageLogWidget::connectToPlayerEventHandler(PlayerEventHandler *playerEve connect(playerEventHandler, &PlayerEventHandler::logDumpZone, this, &MessageLogWidget::logDumpZone); connect(playerEventHandler, &PlayerEventHandler::logDrawCards, this, &MessageLogWidget::logDrawCards); connect(playerEventHandler, &PlayerEventHandler::logUndoDraw, this, &MessageLogWidget::logUndoDraw); + connect(playerEventHandler, &PlayerEventHandler::logUndoDrawFailed, this, &MessageLogWidget::logUndoDrawFailed); connect(playerEventHandler, &PlayerEventHandler::logRevealCards, this, &MessageLogWidget::logRevealCards); connect(playerEventHandler, &PlayerEventHandler::logAlwaysRevealTopCard, this, &MessageLogWidget::logAlwaysRevealTopCard); diff --git a/cockatrice/src/game/log/message_log_widget.h b/cockatrice/src/game/log/message_log_widget.h index 25db21864..f8d70a52e 100644 --- a/cockatrice/src/game/log/message_log_widget.h +++ b/cockatrice/src/game/log/message_log_widget.h @@ -99,6 +99,7 @@ public slots: void logSpectatorSay(const ServerInfo_User &spectator, QString message); void logUnattachCard(PlayerLogic *player, QString cardName); void logUndoDraw(PlayerLogic *player, QString cardName); + void logUndoDrawFailed(PlayerLogic *player); void setContextJudgeName(QString player); void appendHtmlServerMessage(const QString &html, bool optionalIsBold = false, diff --git a/cockatrice/src/game/player/player_event_handler.cpp b/cockatrice/src/game/player/player_event_handler.cpp index 244929338..d7e9cbc6b 100644 --- a/cockatrice/src/game/player/player_event_handler.cpp +++ b/cockatrice/src/game/player/player_event_handler.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include PlayerEventHandler::PlayerEventHandler(PlayerLogic *_player) : QObject(_player), player(_player) @@ -581,6 +582,11 @@ void PlayerEventHandler::eventChangeZoneProperties(const Event_ChangeZonePropert } } +void PlayerEventHandler::eventUndoDrawFailed(const Event_UndoDrawFailed &) +{ + emit logUndoDrawFailed(player); +} + void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type, const GameEvent &event, const GameEventContext &context, @@ -644,6 +650,9 @@ void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type, case GameEvent::CHANGE_ZONE_PROPERTIES: eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext)); break; + case GameEvent::UNDO_DRAW_FAILED: + eventUndoDrawFailed(event.GetExtension(Event_UndoDrawFailed::ext)); + break; default: { qWarning() << "unhandled game event" << type; } diff --git a/cockatrice/src/game/player/player_event_handler.h b/cockatrice/src/game/player/player_event_handler.h index ae3d9aaae..3bae05fd1 100644 --- a/cockatrice/src/game/player/player_event_handler.h +++ b/cockatrice/src/game/player/player_event_handler.h @@ -35,6 +35,8 @@ class Event_SetCardAttr; class Event_SetCardCounter; class Event_SetCounter; class Event_Shuffle; +class Event_UndoDrawFailed; + class PlayerEventHandler : public QObject { @@ -52,6 +54,7 @@ signals: void logCreateToken(PlayerLogic *player, QString cardName, QString pt, bool faceDown); void logDrawCards(PlayerLogic *player, int number, bool deckIsEmpty); void logUndoDraw(PlayerLogic *player, QString cardName); + void logUndoDrawFailed(PlayerLogic *player); void logMoveCard(PlayerLogic *player, CardItem *card, CardZoneLogic *startZone, @@ -108,6 +111,7 @@ public: void eventDrawCards(const Event_DrawCards &event); void eventRevealCards(const Event_RevealCards &event, EventProcessingOptions options); void eventChangeZoneProperties(const Event_ChangeZoneProperties &event); + void eventUndoDrawFailed(const Event_UndoDrawFailed &event); private: PlayerLogic *player; diff --git a/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp b/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp index 1175e4b57..8fb5890e4 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp +++ b/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -409,6 +410,8 @@ Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer & } if (lastDrawList.isEmpty()) { + Event_UndoDrawFailed event; + ges.enqueueGameEvent(event, playerId); return Response::RespContextError; } diff --git a/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt b/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt index 212ab69dd..fcc58e59c 100644 --- a/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt @@ -106,6 +106,7 @@ set(PROTO_FILES event_set_card_counter.proto event_set_counter.proto event_shuffle.proto + event_undo_draw_failed.proto event_user_joined.proto event_user_left.proto event_user_message.proto diff --git a/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto b/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto new file mode 100644 index 000000000..3c0429ca4 --- /dev/null +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto @@ -0,0 +1,9 @@ +syntax = "proto2"; +import "game_event.proto"; + +message Event_UndoDrawFailed { + extend GameEvent { + optional Event_UndoDrawFailed ext = 2022; + } + optional sint32 phase = 1; +} diff --git a/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto b/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto index 8682128af..a973c32bd 100644 --- a/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto @@ -33,6 +33,7 @@ message GameEvent { // STOP_DUMP_ZONE = 2019; // obsolete CHANGE_ZONE_PROPERTIES = 2020; REVERSE_TURN = 2021; + UNDO_DRAW_FAILED = 2022; } optional sint32 player_id = 1 [default = -1]; extensions 100 to max;