From f4a9748a6dcacb7526a68734b150d73827b9595e Mon Sep 17 00:00:00 2001 From: RickyRister Date: Sun, 17 May 2026 02:37:18 -0700 Subject: [PATCH] genericize the proto --- .../src/game/player/player_event_handler.cpp | 17 +++++++++++----- .../src/game/player/player_event_handler.h | 4 ++-- .../server/remote/game/server_player.cpp | 5 +++-- .../libcockatrice/protocol/pb/CMakeLists.txt | 2 +- .../protocol/pb/event_game_log_notice.proto | 20 +++++++++++++++++++ .../protocol/pb/event_undo_draw_failed.proto | 9 --------- .../protocol/pb/game_event.proto | 2 +- 7 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 libcockatrice_protocol/libcockatrice/protocol/pb/event_game_log_notice.proto delete mode 100644 libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto diff --git a/cockatrice/src/game/player/player_event_handler.cpp b/cockatrice/src/game/player/player_event_handler.cpp index d7e9cbc6b..15c40c638 100644 --- a/cockatrice/src/game/player/player_event_handler.cpp +++ b/cockatrice/src/game/player/player_event_handler.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include PlayerEventHandler::PlayerEventHandler(PlayerLogic *_player) : QObject(_player), player(_player) @@ -582,9 +582,16 @@ void PlayerEventHandler::eventChangeZoneProperties(const Event_ChangeZonePropert } } -void PlayerEventHandler::eventUndoDrawFailed(const Event_UndoDrawFailed &) +void PlayerEventHandler::eventGameLogNotice(const Event_GameLogNotice &event) { - emit logUndoDrawFailed(player); + Event_GameLogNotice::NoticeType type = event.notice_type(); + switch (type) { + case Event_GameLogNotice::UNDO_DRAW_FAILED: + emit logUndoDrawFailed(player); + break; + default: + qWarning() << "Received Event_GameLogNotice with unknown noticeType: " << type; + } } void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type, @@ -650,8 +657,8 @@ 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)); + case GameEvent::GAME_LOG_NOTICE: + eventGameLogNotice(event.GetExtension(Event_GameLogNotice::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 3bae05fd1..c9bdb98ae 100644 --- a/cockatrice/src/game/player/player_event_handler.h +++ b/cockatrice/src/game/player/player_event_handler.h @@ -35,7 +35,7 @@ class Event_SetCardAttr; class Event_SetCardCounter; class Event_SetCounter; class Event_Shuffle; -class Event_UndoDrawFailed; +class Event_GameLogNotice; class PlayerEventHandler : public QObject { @@ -111,7 +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); + void eventGameLogNotice(const Event_GameLogNotice &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 8fb5890e4..a1a0a3b3a 100644 --- a/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp +++ b/libcockatrice_network/libcockatrice/network/server/remote/game/server_player.cpp @@ -36,10 +36,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -410,7 +410,8 @@ Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer & } if (lastDrawList.isEmpty()) { - Event_UndoDrawFailed event; + Event_GameLogNotice event; + event.set_notice_type(Event_GameLogNotice::UNDO_DRAW_FAILED); 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 fcc58e59c..b4c7b6ac8 100644 --- a/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/CMakeLists.txt @@ -76,6 +76,7 @@ set(PROTO_FILES event_game_closed.proto event_game_host_changed.proto event_game_joined.proto + event_game_log_notice.proto event_game_say.proto event_game_state_changed.proto event_game_state_changed.proto @@ -106,7 +107,6 @@ 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_game_log_notice.proto b/libcockatrice_protocol/libcockatrice/protocol/pb/event_game_log_notice.proto new file mode 100644 index 000000000..ef0dcc102 --- /dev/null +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/event_game_log_notice.proto @@ -0,0 +1,20 @@ +syntax = "proto2"; +import "game_event.proto"; + +// Notifies clients of an event that happened, and which could safely be dropped without affect the game state. +// This mostly just means events that should cause a message to be logged to chat. +message Event_GameLogNotice { + + // The type of the notice. + // Clients who do not recognize the type should drop the event. + enum NoticeType { + // Player's "undo draw" command failed due to losing track of recent draw + UNDO_DRAW_FAILED = 1; + } + + extend GameEvent { + optional Event_GameLogNotice ext = 2022; + } + + optional NoticeType notice_type = 1; +} diff --git a/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto b/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto deleted file mode 100644 index 3c0429ca4..000000000 --- a/libcockatrice_protocol/libcockatrice/protocol/pb/event_undo_draw_failed.proto +++ /dev/null @@ -1,9 +0,0 @@ -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 a973c32bd..7d3147701 100644 --- a/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto +++ b/libcockatrice_protocol/libcockatrice/protocol/pb/game_event.proto @@ -33,7 +33,7 @@ message GameEvent { // STOP_DUMP_ZONE = 2019; // obsolete CHANGE_ZONE_PROPERTIES = 2020; REVERSE_TURN = 2021; - UNDO_DRAW_FAILED = 2022; + GAME_LOG_NOTICE = 2022; } optional sint32 player_id = 1 [default = -1]; extensions 100 to max;