mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-08-26 10:45:02 -05:00
[Server] Add deck validation strategy interface (#7129)
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 44 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Servatrice_Debian 12 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Some checks failed
Build Desktop / Configure (push) Has been cancelled
Build Desktop / Debian 13 (push) Has been cancelled
Build Desktop / Debian 12 (push) Has been cancelled
Build Desktop / Fedora 44 (push) Has been cancelled
Build Desktop / Fedora 43 (push) Has been cancelled
Build Desktop / Servatrice_Debian 12 (push) Has been cancelled
Build Desktop / Ubuntu 26.04 (push) Has been cancelled
Build Desktop / Ubuntu 24.04 (push) Has been cancelled
Build Desktop / Arch (push) Has been cancelled
Build Desktop / macOS 14 (push) Has been cancelled
Build Desktop / macOS 15 (push) Has been cancelled
Build Desktop / macOS 13 Intel (push) Has been cancelled
Build Desktop / macOS 15 Debug (push) Has been cancelled
Build Desktop / Windows 10 (push) Has been cancelled
Build Docker Image / amd64 & arm64 (push) Has been cancelled
Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
@@ -11,6 +11,7 @@ set(HEADERS
|
||||
game/server_cardzone.h
|
||||
game/server_counter.h
|
||||
game/game_config.h
|
||||
game/server_deck_validation_strategy.h
|
||||
game/server_game.h
|
||||
game/server_player.h
|
||||
game/server_spectator.h
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef SERVER_DECK_VALIDATION_STRATEGY_H
|
||||
#define SERVER_DECK_VALIDATION_STRATEGY_H
|
||||
|
||||
#include <libcockatrice/protocol/pb/response.pb.h>
|
||||
|
||||
class DeckList;
|
||||
class Server_Game;
|
||||
class Server_Player;
|
||||
class ResponseContainer;
|
||||
|
||||
/**
|
||||
* @brief Strategy for validating a player's deck before it is loaded into a game.
|
||||
*
|
||||
* Subclasses decide whether a deck may be accepted; the default implementation
|
||||
* accepts every deck.
|
||||
*/
|
||||
class Server_DeckValidationStrategy
|
||||
{
|
||||
public:
|
||||
virtual ~Server_DeckValidationStrategy() = default;
|
||||
|
||||
/**
|
||||
* @brief Validate @p deck for @p player in @p game.
|
||||
*
|
||||
* @p rc is an out parameter used to attach the response details for a rejected
|
||||
* deck (e.g. an error response extension via ResponseContainer::setResponseExtension).
|
||||
* @return Response::RespOk when the deck is accepted, an error code otherwise.
|
||||
*/
|
||||
virtual Response::ResponseCode
|
||||
validate(Server_Game *game, Server_Player *player, DeckList *deck, ResponseContainer &rc) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Default deck validation strategy that accepts every deck.
|
||||
*/
|
||||
class Server_DefaultDeckValidationStrategy : public Server_DeckValidationStrategy
|
||||
{
|
||||
public:
|
||||
Response::ResponseCode validate(Server_Game *, Server_Player *, DeckList *, ResponseContainer &) override
|
||||
{
|
||||
return Response::RespOk;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -62,7 +62,8 @@ Server_Game::Server_Game(const GameConfig &config, Server_Room *_room)
|
||||
spectatorsCanTalk(config.spectatorsCanTalk), spectatorsSeeEverything(config.spectatorsSeeEverything),
|
||||
startingLifeTotal(config.startingLifeTotal), shareDecklistsOnLoad(config.shareDecklistsOnLoad),
|
||||
inactivityCounter(0), startTimeOfThisGame(0), secondsElapsed(0), firstGameStarted(false),
|
||||
turnOrderReversed(false), startTime(QDateTime::currentDateTime()), pingClock(nullptr), gameMutex()
|
||||
turnOrderReversed(false), startTime(QDateTime::currentDateTime()), pingClock(nullptr),
|
||||
deckValidationStrategy(new Server_DefaultDeckValidationStrategy), gameMutex()
|
||||
{
|
||||
currentReplay = new GameReplay;
|
||||
currentReplay->set_replay_id(room->getServer()->getDatabaseInterface()->getNextReplayId());
|
||||
@@ -886,3 +887,8 @@ void Server_Game::returnCardsFromPlayer(GameEventStorage &ges, Server_AbstractPl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Server_Game::setDeckValidationStrategy(Server_DeckValidationStrategy *strategy)
|
||||
{
|
||||
deckValidationStrategy.reset(strategy);
|
||||
}
|
||||
|
||||
@@ -22,11 +22,13 @@
|
||||
|
||||
#include "../server_response_containers.h"
|
||||
#include "game_config.h"
|
||||
#include "server_deck_validation_strategy.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QScopedPointer>
|
||||
#include <QSet>
|
||||
#include <QStringList>
|
||||
#include <libcockatrice/protocol/pb/event_leave.pb.h>
|
||||
@@ -79,6 +81,8 @@ private:
|
||||
QList<GameReplay *> replayList;
|
||||
GameReplay *currentReplay;
|
||||
|
||||
QScopedPointer<Server_DeckValidationStrategy> deckValidationStrategy;
|
||||
|
||||
void createGameStateChangedEvent(Event_GameStateChanged *event,
|
||||
Server_AbstractParticipant *recipient,
|
||||
bool omniscient,
|
||||
@@ -208,6 +212,14 @@ public:
|
||||
GameEventStorageItem::SendToOthers,
|
||||
int privatePlayerId = -1);
|
||||
void returnCardsFromPlayer(GameEventStorage &ges, Server_AbstractPlayer *player);
|
||||
|
||||
/** @brief Get the current deck validation strategy (non-owning). */
|
||||
Server_DeckValidationStrategy *getDeckValidationStrategy() const
|
||||
{
|
||||
return deckValidationStrategy.data();
|
||||
}
|
||||
/** @brief Replace the deck validation strategy; takes ownership of @p strategy. */
|
||||
void setDeckValidationStrategy(Server_DeckValidationStrategy *strategy);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user