From c5509db2514cfe804574991309a669ba2aab8f8e Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 19 Dec 2011 00:03:05 +0100 Subject: [PATCH] reasonable defaults --- cockatrice/src/player.cpp | 33 ++++++++----------- common/pb/proto/command_attach_card.proto | 6 ++-- common/pb/proto/command_create_arrow.proto | 10 +++--- common/pb/proto/command_deck_del.proto | 2 +- common/pb/proto/command_deck_download.proto | 2 +- common/pb/proto/command_deck_select.proto | 2 +- common/pb/proto/command_del_counter.proto | 2 +- common/pb/proto/command_delete_arrow.proto | 2 +- common/pb/proto/command_dump_zone.proto | 2 +- common/pb/proto/command_flip_card.proto | 2 +- .../pb/proto/command_inc_card_counter.proto | 4 +-- common/pb/proto/command_inc_counter.proto | 2 +- common/pb/proto/command_kick_from_game.proto | 4 +-- common/pb/proto/command_move_card.proto | 8 ++--- common/pb/proto/command_reveal_cards.proto | 4 +-- common/pb/proto/command_set_card_attr.proto | 2 +- .../pb/proto/command_set_card_counter.proto | 4 +-- common/pb/proto/command_set_counter.proto | 2 +- common/pb/proto/room_commands.proto | 2 +- common/server_protocolhandler.cpp | 15 ++++----- 20 files changed, 50 insertions(+), 60 deletions(-) diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index ac82c63f..d1c37f2d 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -357,33 +357,26 @@ void Player::playerListActionTriggered() { QAction *action = static_cast(sender()); QMenu *menu = static_cast(action->parentWidget()); - int otherPlayerId = action->data().toInt(); - if (menu == mRevealLibrary) { - Command_RevealCards cmd; - cmd.set_zone_name("deck"); - cmd.set_card_id(-1); + Command_RevealCards cmd; + const int otherPlayerId = action->data().toInt(); + if (otherPlayerId != -1) cmd.set_player_id(otherPlayerId); - sendGameCommand(cmd); - } else if (menu == mRevealTopCard) { - Command_RevealCards cmd; + + if (menu == mRevealLibrary) + cmd.set_zone_name("deck"); + else if (menu == mRevealTopCard) { cmd.set_zone_name("deck"); cmd.set_card_id(0); - cmd.set_player_id(otherPlayerId); - sendGameCommand(cmd); - } else if (menu == mRevealHand) { - Command_RevealCards cmd; + } else if (menu == mRevealHand) cmd.set_zone_name("hand"); - cmd.set_card_id(-1); - cmd.set_player_id(otherPlayerId); - sendGameCommand(cmd); - } else if (menu == mRevealRandomHandCard) { - Command_RevealCards cmd; + else if (menu == mRevealRandomHandCard) { cmd.set_zone_name("hand"); cmd.set_card_id(-2); - cmd.set_player_id(otherPlayerId); - sendGameCommand(cmd); - } + } else + return; + + sendGameCommand(cmd); } void Player::rearrangeZones() diff --git a/common/pb/proto/command_attach_card.proto b/common/pb/proto/command_attach_card.proto index 3eaac621..02fbb9ce 100644 --- a/common/pb/proto/command_attach_card.proto +++ b/common/pb/proto/command_attach_card.proto @@ -4,10 +4,10 @@ message Command_AttachCard { optional Command_AttachCard ext = 1009; } optional string start_zone = 1; - optional sint32 card_id = 2; - optional sint32 target_player_id = 3; + optional sint32 card_id = 2 [default = -1]; + optional sint32 target_player_id = 3 [default = -1]; optional string target_zone = 4; - optional sint32 target_card_id = 5; + optional sint32 target_card_id = 5 [default = -1]; } diff --git a/common/pb/proto/command_create_arrow.proto b/common/pb/proto/command_create_arrow.proto index e662d693..31c29c5b 100644 --- a/common/pb/proto/command_create_arrow.proto +++ b/common/pb/proto/command_create_arrow.proto @@ -5,13 +5,11 @@ message Command_CreateArrow { extend GameCommand { optional Command_CreateArrow ext = 1011; } - optional sint32 start_player_id = 1; + optional sint32 start_player_id = 1 [default = -1]; optional string start_zone = 2; - optional sint32 start_card_id = 3; - optional sint32 target_player_id = 4; + optional sint32 start_card_id = 3 [default = -1]; + optional sint32 target_player_id = 4 [default = -1]; optional string target_zone = 5; - optional sint32 target_card_id = 6; + optional sint32 target_card_id = 6 [default = -1]; optional color arrow_color = 7; } - - diff --git a/common/pb/proto/command_deck_del.proto b/common/pb/proto/command_deck_del.proto index 530a998f..261ad630 100644 --- a/common/pb/proto/command_deck_del.proto +++ b/common/pb/proto/command_deck_del.proto @@ -4,5 +4,5 @@ message Command_DeckDel { extend SessionCommand { optional Command_DeckDel ext = 1011; } - optional uint32 deck_id = 1; + optional sint32 deck_id = 1 [default = -1]; } diff --git a/common/pb/proto/command_deck_download.proto b/common/pb/proto/command_deck_download.proto index 0444e164..822754ca 100644 --- a/common/pb/proto/command_deck_download.proto +++ b/common/pb/proto/command_deck_download.proto @@ -4,6 +4,6 @@ message Command_DeckDownload { extend SessionCommand { optional Command_DeckDownload ext = 1012; } - optional uint32 deck_id = 1; + optional sint32 deck_id = 1 [default = -1]; } diff --git a/common/pb/proto/command_deck_select.proto b/common/pb/proto/command_deck_select.proto index ffa9958b..e696dae0 100644 --- a/common/pb/proto/command_deck_select.proto +++ b/common/pb/proto/command_deck_select.proto @@ -4,5 +4,5 @@ message Command_DeckSelect { optional Command_DeckSelect ext = 1029; } optional string deck = 1; - optional sint32 deck_id = 2; + optional sint32 deck_id = 2 [default = -1]; } diff --git a/common/pb/proto/command_del_counter.proto b/common/pb/proto/command_del_counter.proto index 639191ef..1e59b336 100644 --- a/common/pb/proto/command_del_counter.proto +++ b/common/pb/proto/command_del_counter.proto @@ -3,5 +3,5 @@ message Command_DelCounter { extend GameCommand { optional Command_DelCounter ext = 1021; } - optional sint32 counter_id = 1; + optional sint32 counter_id = 1 [default = -1]; } diff --git a/common/pb/proto/command_delete_arrow.proto b/common/pb/proto/command_delete_arrow.proto index b3fba9ac..ffccacf0 100644 --- a/common/pb/proto/command_delete_arrow.proto +++ b/common/pb/proto/command_delete_arrow.proto @@ -3,5 +3,5 @@ message Command_DeleteArrow { extend GameCommand { optional Command_DeleteArrow ext = 1012; } - optional sint32 arrow_id = 1; + optional sint32 arrow_id = 1 [default = -1]; } diff --git a/common/pb/proto/command_dump_zone.proto b/common/pb/proto/command_dump_zone.proto index 9e722706..15fbe3c0 100644 --- a/common/pb/proto/command_dump_zone.proto +++ b/common/pb/proto/command_dump_zone.proto @@ -3,7 +3,7 @@ message Command_DumpZone { extend GameCommand { optional Command_DumpZone ext = 1024; } - optional sint32 player_id = 1; + optional sint32 player_id = 1 [default = -1]; optional string zone_name = 2; optional sint32 number_cards = 3; } diff --git a/common/pb/proto/command_flip_card.proto b/common/pb/proto/command_flip_card.proto index 90a3092f..25692f9c 100644 --- a/common/pb/proto/command_flip_card.proto +++ b/common/pb/proto/command_flip_card.proto @@ -4,7 +4,7 @@ message Command_FlipCard { optional Command_FlipCard ext = 1008; } optional string zone = 1; - optional sint32 card_id = 2; + optional sint32 card_id = 2 [default = -1]; optional bool face_down = 3; } diff --git a/common/pb/proto/command_inc_card_counter.proto b/common/pb/proto/command_inc_card_counter.proto index 9c0280e8..e8b5f1ca 100644 --- a/common/pb/proto/command_inc_card_counter.proto +++ b/common/pb/proto/command_inc_card_counter.proto @@ -4,7 +4,7 @@ message Command_IncCardCounter { optional Command_IncCardCounter ext = 1015; } optional string zone = 1; - optional sint32 card_id = 2; - optional sint32 counter_id = 3; + optional sint32 card_id = 2 [default = -1]; + optional sint32 counter_id = 3 [default = -1]; optional sint32 counter_delta = 4; } diff --git a/common/pb/proto/command_inc_counter.proto b/common/pb/proto/command_inc_counter.proto index 42856bb3..a14a2801 100644 --- a/common/pb/proto/command_inc_counter.proto +++ b/common/pb/proto/command_inc_counter.proto @@ -3,6 +3,6 @@ message Command_IncCounter { extend GameCommand { optional Command_IncCounter ext = 1018; } - optional sint32 counter_id = 1; + optional sint32 counter_id = 1 [default = -1]; optional sint32 delta = 2; } diff --git a/common/pb/proto/command_kick_from_game.proto b/common/pb/proto/command_kick_from_game.proto index e60f7f88..b340cb07 100644 --- a/common/pb/proto/command_kick_from_game.proto +++ b/common/pb/proto/command_kick_from_game.proto @@ -2,7 +2,7 @@ import "game_commands.proto"; message Command_KickFromGame { extend GameCommand { optional Command_KickFromGame ext = 1000; - } - optional sint32 player_id = 1; +} + optional sint32 player_id = 1 [default = -1]; } diff --git a/common/pb/proto/command_move_card.proto b/common/pb/proto/command_move_card.proto index cee74cd1..401c5a48 100644 --- a/common/pb/proto/command_move_card.proto +++ b/common/pb/proto/command_move_card.proto @@ -1,6 +1,6 @@ import "game_commands.proto"; message CardToMove { - optional sint32 card_id = 1; + optional sint32 card_id = 1 [default = -1]; optional bool face_down = 2; optional string pt = 3; optional bool tapped = 4; @@ -16,9 +16,9 @@ message Command_MoveCard { } optional string start_zone = 1; optional ListOfCardsToMove cards_to_move = 2; - optional sint32 target_player_id = 3; + optional sint32 target_player_id = 3 [default = -1]; optional string target_zone = 4; - optional sint32 x = 5; - optional sint32 y = 6; + optional sint32 x = 5 [default = -1]; + optional sint32 y = 6 [default = -1]; } diff --git a/common/pb/proto/command_reveal_cards.proto b/common/pb/proto/command_reveal_cards.proto index 64c20011..6f59a92b 100644 --- a/common/pb/proto/command_reveal_cards.proto +++ b/common/pb/proto/command_reveal_cards.proto @@ -4,6 +4,6 @@ message Command_RevealCards { optional Command_RevealCards ext = 1026; } optional string zone_name = 1; - optional sint32 card_id = 2; - optional sint32 player_id = 3; + optional sint32 card_id = 2 [default = -1]; + optional sint32 player_id = 3 [default = -1]; } diff --git a/common/pb/proto/command_set_card_attr.proto b/common/pb/proto/command_set_card_attr.proto index 957e2421..0c3ee3d1 100644 --- a/common/pb/proto/command_set_card_attr.proto +++ b/common/pb/proto/command_set_card_attr.proto @@ -4,7 +4,7 @@ message Command_SetCardAttr { optional Command_SetCardAttr ext = 1013; } optional string zone = 1; - optional sint32 card_id = 2; + optional sint32 card_id = 2 [default = -1]; optional string attr_name = 3; optional string attr_value = 4; } diff --git a/common/pb/proto/command_set_card_counter.proto b/common/pb/proto/command_set_card_counter.proto index 36a5f21b..b258a861 100644 --- a/common/pb/proto/command_set_card_counter.proto +++ b/common/pb/proto/command_set_card_counter.proto @@ -4,7 +4,7 @@ message Command_SetCardCounter { optional Command_SetCardCounter ext = 1014; } optional string zone = 1; - optional sint32 card_id = 2; - optional sint32 counter_id = 3; + optional sint32 card_id = 2 [default = -1]; + optional sint32 counter_id = 3 [default = -1]; optional sint32 counter_value = 4; } diff --git a/common/pb/proto/command_set_counter.proto b/common/pb/proto/command_set_counter.proto index aef07783..a2f34cc2 100644 --- a/common/pb/proto/command_set_counter.proto +++ b/common/pb/proto/command_set_counter.proto @@ -3,6 +3,6 @@ message Command_SetCounter { extend GameCommand { optional Command_SetCounter ext = 1020; } - optional sint32 counter_id = 1; + optional sint32 counter_id = 1 [default = -1]; optional sint32 value = 2; } diff --git a/common/pb/proto/room_commands.proto b/common/pb/proto/room_commands.proto index f3aed05d..e7411674 100644 --- a/common/pb/proto/room_commands.proto +++ b/common/pb/proto/room_commands.proto @@ -41,7 +41,7 @@ message Command_JoinGame { extend RoomCommand { optional Command_JoinGame ext = 1003; } - optional uint32 game_id = 1; + optional sint32 game_id = 1 [default = -1]; optional string password = 2; optional bool spectator = 3; optional bool override_restrictions = 4; diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 9c6a6ebe..aa47ad44 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -949,13 +949,11 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd if (!card) return RespNameNotFound; - int playerId = cmd.target_player_id(); Server_Player *targetPlayer = 0; Server_CardZone *targetzone = 0; Server_Card *targetCard = 0; - qDebug() << "playerId="<getPlayer(cmd.target_player_id()); if (!targetPlayer) return RespNameNotFound; @@ -968,7 +966,8 @@ ResponseCode Server_ProtocolHandler::cmdAttachCard(const Command_AttachCard &cmd // Possibly a flag will have to be introduced for this sometime. if (!targetzone->hasCoords()) return RespContextError; - targetCard = targetzone->getCard(cmd.target_card_id()); + if (cmd.has_target_card_id()) + targetCard = targetzone->getCard(cmd.target_card_id()); if (targetCard) if (targetCard->getParentCard()) return RespContextError; @@ -1391,7 +1390,7 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &c return RespContextError; Server_Player *otherPlayer = 0; - if (cmd.player_id() != -1) { + if (cmd.has_player_id()) { otherPlayer = game->getPlayer(cmd.player_id()); if (!otherPlayer) return RespNameNotFound; @@ -1401,7 +1400,7 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &c return RespNameNotFound; QList cardsToReveal; - if (cmd.card_id() == -1) + if (!cmd.has_card_id()) cardsToReveal = zone->cards; else if (cmd.card_id() == -2) { if (zone->cards.isEmpty()) @@ -1435,12 +1434,12 @@ ResponseCode Server_ProtocolHandler::cmdRevealCards(const Command_RevealCards &c attachCardId = card->getParentCard()->getId(); } - if (cmd.player_id() != -1) + if (cmd.has_player_id()) respCardListPrivate.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getFaceDown(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), card->getDoesntUntap(), cardCounterListPrivate, attachPlayerId, attachZone, attachCardId)); respCardListOmniscient.append(new ServerInfo_Card(card->getId(), card->getName(), card->getX(), card->getY(), card->getFaceDown(), card->getTapped(), card->getAttacking(), card->getColor(), card->getPT(), card->getAnnotation(), card->getDestroyOnZoneChange(), card->getDoesntUntap(), cardCounterListOmniscient, attachPlayerId, attachZone, attachCardId)); } - if (cmd.player_id() == -1) + if (!cmd.has_player_id()) bla->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), -1, respCardListOmniscient), game->getGameId()); else { bla->enqueueGameEventPublic(new Event_RevealCards(player->getPlayerId(), zone->getName(), cmd.card_id(), otherPlayer->getPlayerId()), game->getGameId());