mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
[Server][Game] Make undo draw failure visible in chat (#6889)
* [Server][Game] Make undo draw failure visible in chat * genericize the proto
This commit is contained in:
parent
5219cffa6b
commit
10b9a65f17
8 changed files with 54 additions and 0 deletions
|
|
@ -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("<span style=\"color:black\">");
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include <libcockatrice/protocol/pb/event_draw_cards.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_dump_zone.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_flip_card.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_game_log_notice.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_game_say.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_move_card.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_reveal_cards.pb.h>
|
||||
|
|
@ -581,6 +582,18 @@ void PlayerEventHandler::eventChangeZoneProperties(const Event_ChangeZonePropert
|
|||
}
|
||||
}
|
||||
|
||||
void PlayerEventHandler::eventGameLogNotice(const Event_GameLogNotice &event)
|
||||
{
|
||||
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,
|
||||
const GameEvent &event,
|
||||
const GameEventContext &context,
|
||||
|
|
@ -644,6 +657,9 @@ void PlayerEventHandler::processGameEvent(GameEvent::GameEventType type,
|
|||
case GameEvent::CHANGE_ZONE_PROPERTIES:
|
||||
eventChangeZoneProperties(event.GetExtension(Event_ChangeZoneProperties::ext));
|
||||
break;
|
||||
case GameEvent::GAME_LOG_NOTICE:
|
||||
eventGameLogNotice(event.GetExtension(Event_GameLogNotice::ext));
|
||||
break;
|
||||
default: {
|
||||
qWarning() << "unhandled game event" << type;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ class Event_SetCardAttr;
|
|||
class Event_SetCardCounter;
|
||||
class Event_SetCounter;
|
||||
class Event_Shuffle;
|
||||
class Event_GameLogNotice;
|
||||
|
||||
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 eventGameLogNotice(const Event_GameLogNotice &event);
|
||||
|
||||
private:
|
||||
PlayerLogic *player;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include <libcockatrice/protocol/pb/event_create_counter.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_del_counter.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_draw_cards.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_game_log_notice.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_player_properties_changed.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_set_counter.pb.h>
|
||||
#include <libcockatrice/protocol/pb/event_shuffle.pb.h>
|
||||
|
|
@ -409,6 +410,9 @@ Server_Player::cmdUndoDraw(const Command_UndoDraw & /*cmd*/, ResponseContainer &
|
|||
}
|
||||
|
||||
if (lastDrawList.isEmpty()) {
|
||||
Event_GameLogNotice event;
|
||||
event.set_notice_type(Event_GameLogNotice::UNDO_DRAW_FAILED);
|
||||
ges.enqueueGameEvent(event, playerId);
|
||||
return Response::RespContextError;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ message GameEvent {
|
|||
// STOP_DUMP_ZONE = 2019; // obsolete
|
||||
CHANGE_ZONE_PROPERTIES = 2020;
|
||||
REVERSE_TURN = 2021;
|
||||
GAME_LOG_NOTICE = 2022;
|
||||
}
|
||||
optional sint32 player_id = 1 [default = -1];
|
||||
extensions 100 to max;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue