Add option to share decklists on load.

Took 1 hour 58 minutes

Took 9 minutes


Took 39 minutes
This commit is contained in:
Lukas Brübach 2025-07-09 21:04:57 +02:00
parent 3a42354efd
commit 0e45652f3f
23 changed files with 198 additions and 25 deletions

View file

@ -7,4 +7,5 @@ message Context_DeckSelect {
}
optional string deck_hash = 1;
optional int32 sideboard_size = 2 [default = -1];
optional string deck_list = 3;
}

View file

@ -39,6 +39,7 @@ message Command_CreateGame {
optional bool join_as_judge = 11;
optional bool join_as_spectator = 12;
optional uint32 starting_life_total = 13;
optional bool share_decklists_on_load = 14;
}
message Command_JoinGame {

View file

@ -16,6 +16,7 @@ message ServerInfo_Game {
optional bool spectators_need_password = 12;
optional bool spectators_can_chat = 13;
optional bool spectators_omniscient = 14;
optional bool share_decklists_on_load = 15;
optional uint32 player_count = 30;
optional uint32 spectators_count = 31;
optional bool started = 50;

View file

@ -62,15 +62,16 @@ Server_Game::Server_Game(const ServerInfo_User &_creatorInfo,
bool _spectatorsCanTalk,
bool _spectatorsSeeEverything,
int _startingLifeTotal,
bool _shareDecklistsOnLoad,
Server_Room *_room)
: QObject(), room(_room), nextPlayerId(0), hostId(0), creatorInfo(new ServerInfo_User(_creatorInfo)),
gameStarted(false), gameClosed(false), gameId(_gameId), password(_password), maxPlayers(_maxPlayers),
gameTypes(_gameTypes), activePlayer(-1), activePhase(-1), onlyBuddies(_onlyBuddies),
onlyRegistered(_onlyRegistered), spectatorsAllowed(_spectatorsAllowed),
spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk),
spectatorsSeeEverything(_spectatorsSeeEverything), startingLifeTotal(_startingLifeTotal), inactivityCounter(0),
startTimeOfThisGame(0), secondsElapsed(0), firstGameStarted(false), turnOrderReversed(false),
startTime(QDateTime::currentDateTime()), pingClock(nullptr),
spectatorsSeeEverything(_spectatorsSeeEverything), startingLifeTotal(_startingLifeTotal),
shareDecklistsOnLoad(_shareDecklistsOnLoad), inactivityCounter(0), startTimeOfThisGame(0), secondsElapsed(0),
firstGameStarted(false), turnOrderReversed(false), startTime(QDateTime::currentDateTime()), pingClock(nullptr),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
gameMutex()
#else
@ -800,6 +801,7 @@ void Server_Game::getInfo(ServerInfo_Game &result) const
result.set_spectators_need_password(getSpectatorsNeedPassword());
result.set_spectators_can_chat(spectatorsCanTalk);
result.set_spectators_omniscient(spectatorsSeeEverything);
result.set_share_decklists_on_load(shareDecklistsOnLoad);
result.set_spectators_count(getSpectatorCount());
result.set_start_time(startTime.toSecsSinceEpoch());
}

View file

@ -67,6 +67,7 @@ private:
bool spectatorsCanTalk;
bool spectatorsSeeEverything;
int startingLifeTotal;
bool shareDecklistsOnLoad;
int inactivityCounter;
int startTimeOfThisGame, secondsElapsed;
bool firstGameStarted;
@ -106,7 +107,8 @@ public:
bool _spectatorsNeedPassword,
bool _spectatorsCanTalk,
bool _spectatorsSeeEverything,
int startingLifeTotal,
int _startingLifeTotal,
bool _shareDecklistsOnLoad,
Server_Room *parent);
~Server_Game() override;
Server_Room *getRoom() const
@ -168,6 +170,10 @@ public:
{
return startingLifeTotal;
}
bool getShareDecklistsOnLoad() const
{
return shareDecklistsOnLoad;
}
Response::ResponseCode
checkJoin(ServerInfo_User *user, const QString &_password, bool spectator, bool overrideRestrictions, bool asJudge);
bool containsUser(const QString &userName) const;

View file

@ -836,6 +836,9 @@ Server_Player::cmdDeckSelect(const Command_DeckSelect &cmd, ResponseContainer &r
Context_DeckSelect context;
context.set_deck_hash(deck->getDeckHash().toStdString());
context.set_sideboard_size(deck->getSideboardSize());
if (game->getShareDecklistsOnLoad()) {
context.set_deck_list(deck->writeToString_Native().toStdString());
}
ges.setGameEventContext(context);
auto *re = new Response_DeckDownload;

View file

@ -818,6 +818,8 @@ Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room
QString description = nameFromStdString(cmd.description());
int startingLifeTotal = cmd.has_starting_life_total() ? cmd.starting_life_total() : 20;
bool shareDecklistsOnLoad = cmd.has_share_decklists_on_load() ? cmd.share_decklists_on_load() : false;
const int gameId = databaseInterface->getNextGameId();
if (gameId == -1) {
return Response::RespInternalError;
@ -828,7 +830,7 @@ Server_ProtocolHandler::cmdCreateGame(const Command_CreateGame &cmd, Server_Room
Server_Game *game = new Server_Game(
copyUserInfo(false), gameId, description, QString::fromStdString(cmd.password()), cmd.max_players(), gameTypes,
cmd.only_buddies(), onlyRegisteredUsers, cmd.spectators_allowed(), cmd.spectators_need_password(),
cmd.spectators_can_talk(), cmd.spectators_see_everything(), startingLifeTotal, room);
cmd.spectators_can_talk(), cmd.spectators_see_everything(), startingLifeTotal, shareDecklistsOnLoad, room);
game->addPlayer(this, rc, asSpectator, asJudge, false);
room->addGame(game);