servatrice/common
Basile Clement 9a7b15d19b
Allow revealing specific cards from hand and library (#4743)
Currently Cockatrice allows revealing the whole hand, or one card at
random from the hand. Sometimes, a player needs to reveal a specific
card from their hand instead, which is not supported. To achieve a
similar effect, players usually move the corresponding card (or cards)
to a public zone, then back to their hand. While this works, it is
unsatisfactory (compared to a regular reveal, you can't keep the
"revealed" window around, for one) and somewhat unintuitive.

This patch adds a "Reveal to..." menu to cards and card selections in
the player's hand or in custom zones (this includes looking at the
player's library). This menu allows revealing a card or set of cards to
any given player, or to all players.

To implement this functionality at the protocol level, the existing
RevealCards command is extended to support revealing multiple specific
cards. This is done by making `card_id` a non-packed repeated field in
the `Command_RevealCards` and `Event_RevealCards` protobufs.  Using a
non-packed repeated fields allows maintaining backwards compatibility:
an empty optional field is encoded the same way as an empty non-packed
list, an optional field with a value is encoded the same way as a
one-element non-packed list, and when decoding a multi-elements
non-packed list as an optional, only the last item in the list is read.

Since the RevealCards command already exists, and due to the compatible
encodings, a new client connecting to an old server can reveal a single
specific card from their hand. When trying to reveal multiple cards at
once, the old server will only see the request for one of the cards to
be revealed, and the player will have to reveal each card separately.

On the other hand, `Event_RevealedCards` already has an explicit list of
cards revealed by the server, and the `card_id` field is only used when
exactly one card has been revealed: thus, old and new clients will
behave identically when receiving a new `Event_RevealedCards`. In
particular, if a player using a new client reveals multiple cards from
their hand on a new server, another player using an old client will
correctly see all the revealed cards.

The approach used to build the "Reveal to..." menu is slightly different
from the approach used to build other player selection menus. Because
the "Reveal to..." menu is specific to each card, but must also be
updated whenever a player is added to or removed from the game, I chose
to re-create it on the fly whenever a card is clicked, as that seemed
the safest way to avoid both memory leaks and inconsistent state given
my understanding of the code.
2023-02-07 17:12:04 -05:00
..
lib Counter expressions (#3534) 2019-02-02 13:56:49 -05:00
pb Allow revealing specific cards from hand and library (#4743) 2023-02-07 17:12:04 -05:00
sfmt update sfmt to version 1.5.1 from 1.4.1 (#4124) 2020-10-02 12:13:12 -04:00
CMakeLists.txt Add cmake format (#4618) 2022-05-08 21:22:43 +02:00
color.h Tabs to spaces. 2014-07-08 22:53:02 -04:00
debug_pb_message.cpp implement custom protobuf debug string creation (#4532) 2022-02-23 23:46:23 +01:00
debug_pb_message.h implement custom protobuf debug string creation (#4532) 2022-02-23 23:46:23 +01:00
decklist.cpp Fix #4706: don't replace ampersands when loading from plain text (#4734) 2023-01-30 00:37:28 +01:00
decklist.h Fix #4706: don't replace ampersands when loading from plain text (#4734) 2023-01-30 00:37:28 +01:00
expression.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
expression.h Counter expressions (#3534) 2019-02-02 13:56:49 -05:00
featureset.cpp rework formatting with cmake-format (#4627) 2022-06-08 21:14:26 -04:00
featureset.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
get_pb_extension.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
get_pb_extension.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
passwordhasher.cpp miscellaneous refactors (#4521) 2022-01-16 17:58:53 -05:00
passwordhasher.h miscellaneous refactors (#4521) 2022-01-16 17:58:53 -05:00
rng_abstract.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
rng_abstract.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
rng_sfmt.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
rng_sfmt.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
room_message_type.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server.h Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server_abstractuserinterface.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_abstractuserinterface.h apply chat flood prevention in games next to rooms (#4387) 2021-06-28 01:57:46 -04:00
server_arrow.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_arrow.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
server_arrowtarget.cpp Tabs to spaces. 2014-07-08 22:53:02 -04:00
server_arrowtarget.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
server_card.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_card.h Prevent bad access potential for removals by checking bounds (#4617) 2022-05-08 20:26:50 +02:00
server_cardzone.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server_cardzone.h remove cards being looked at from the count on drawing (#4671) 2022-10-17 16:35:54 -04:00
server_counter.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_counter.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_database_interface.cpp Overhaul common's CMakeLists.txt 2014-06-11 01:24:34 +02:00
server_database_interface.h Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server_game.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server_game.h fix deprecation of QMutex::Recursive in favor of QRecursiveMutex (#4328) 2021-05-01 18:51:17 -04:00
server_metatypes.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_player.cpp Allow revealing specific cards from hand and library (#4743) 2023-02-07 17:12:04 -05:00
server_player.h Fix move (#4491) 2021-12-07 22:56:58 -05:00
server_player_reference.h Clang-format (#3028) 2018-01-27 10:41:32 +01:00
server_protocolhandler.cpp Display Welcome Message as Most Recent Message (#4720) 2022-12-11 23:40:47 +01:00
server_protocolhandler.h Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
server_remoteuserinterface.cpp clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_remoteuserinterface.h apply chat flood prevention in games next to rooms (#4387) 2021-06-28 01:57:46 -04:00
server_response_containers.cpp send hidden info to judge instead of player (#4297) 2021-03-25 22:35:46 -04:00
server_response_containers.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00
server_room.cpp use hashed passwords in all commands (#4493) 2022-01-16 20:32:30 -05:00
server_room.h add option to delete a user's messages (#4362) 2021-09-14 16:05:20 -04:00
serverinfo_user_container.cpp Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
serverinfo_user_container.h Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
stringsizes.h Support Qt6, Min Qt5.8, Fix Win32, Fix Servatrice 2022-05-06 17:31:08 -04:00
user_level.h clangify everything with the new header sorting (#3908) 2020-03-18 17:36:02 -04:00