mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-09-22 01:25:10 -07:00
[Server] Add deck share links and public deck visibility (#7241)
* [Server] Add deck share links and public deck visibility * Address server review comments for deck share links * Document transaction teardown in deck share rollback paths * Address second round of deck share review comments --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
a5e94d8a4f
commit
073ec29c4d
29 changed files with 1202 additions and 23 deletions
|
|
@ -13,10 +13,32 @@
|
|||
#include <server.h>
|
||||
#include <server_database_interface.h>
|
||||
|
||||
#define DATABASE_SCHEMA_VERSION 36
|
||||
#define DATABASE_SCHEMA_VERSION 37
|
||||
|
||||
class Servatrice;
|
||||
|
||||
/** @brief Metadata of a single deck inside a temporary deck share bundle. */
|
||||
struct DeckShareItemRecord
|
||||
{
|
||||
int id = -1; ///< Database id, used for downloads.
|
||||
QString name; ///< Deck name.
|
||||
QStringList tags; ///< Deck tags.
|
||||
QString bannerCard; ///< Banner card name (deck image).
|
||||
QString gameFormat; ///< Game format the deck was built for.
|
||||
QString colorIdentity; ///< Color identity, e.g. "WUBRG".
|
||||
QString content; ///< Deck content (native format); empty in list queries.
|
||||
};
|
||||
|
||||
/** @brief Summary of a share bundle owned by a user. */
|
||||
struct DeckShareSummaryRecord
|
||||
{
|
||||
int id = -1; ///< Database id, used for revocation.
|
||||
QString name; ///< Share name.
|
||||
qint64 creationTime = 0; ///< Unix timestamp at which the share was created.
|
||||
qint64 expiresAt = 0; ///< Unix timestamp at which the share expires.
|
||||
int itemCount = 0; ///< Number of decks in the bundle.
|
||||
};
|
||||
|
||||
class Servatrice_DatabaseInterface : public Server_DatabaseInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -80,6 +102,37 @@ public:
|
|||
const QList<GameReplay *> &replayList) override;
|
||||
DeckList *getDeckFromDatabase(int deckId, int userId) override;
|
||||
|
||||
/**
|
||||
* @brief Creates a new temporary deck share bundle.
|
||||
* @param expiresAt Receives the actual expiry read back from the database.
|
||||
* @return false on failure.
|
||||
*/
|
||||
bool createDeckShare(const QString &token,
|
||||
const QString &name,
|
||||
int userId,
|
||||
const QList<DeckShareItemRecord> &items,
|
||||
int expiryDays,
|
||||
qint64 &expiresAt);
|
||||
/** @brief Lists the share bundles created by a user, newest first. */
|
||||
bool getDeckSharesForUser(int userId, QList<DeckShareSummaryRecord> &shares);
|
||||
/**
|
||||
* @brief Deletes one of a user's own share bundles (cascades to its items).
|
||||
* @return false if no such bundle belongs to the user.
|
||||
*/
|
||||
bool deleteDeckShare(int shareId, int userId);
|
||||
/**
|
||||
* @brief Looks up a valid (non-expired) share bundle by token.
|
||||
* @return false if the token is unknown or expired.
|
||||
*/
|
||||
bool getDeckShareList(const QString &token, QString &name, qint64 &expiresAt, QList<DeckShareItemRecord> &items);
|
||||
/**
|
||||
* @brief Fetches the content of one item of a valid share bundle.
|
||||
* @return false if the token is unknown/expired or the item does not belong to the bundle.
|
||||
*/
|
||||
bool getDeckShareItem(const QString &token, int itemId, QString &content);
|
||||
/** @brief Deletes all expired share bundles (cascades to their items). */
|
||||
void cleanupExpiredDeckShares();
|
||||
|
||||
int getNextGameId() override;
|
||||
int getNextReplayId() override;
|
||||
int getActiveUserCount(QString connectionType = QString()) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue