Allow up to 100 dice to be rolled at a time (#5047)

* Allow up to 100 dice to be rolled at a time
- Fix #4276
This commit is contained in:
Zach H 2024-06-12 08:37:04 -04:00 committed by GitHub
parent c95cc1dd9d
commit ce8092318e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 184 additions and 58 deletions

View file

@ -1,6 +1,6 @@
#include "debug_pb_message.h"
#include "stringsizes.h"
#include "trice_limits.h"
#include <QList>
#include <QString>

View file

@ -5,4 +5,5 @@ message Command_RollDie {
optional Command_RollDie ext = 1005;
}
optional uint32 sides = 1;
optional uint32 count = 2;
}

View file

@ -7,4 +7,5 @@ message Event_RollDie {
}
optional uint32 sides = 1;
optional uint32 value = 2;
repeated uint32 values = 3;
}

View file

@ -79,7 +79,7 @@
#include "server_database_interface.h"
#include "server_game.h"
#include "server_room.h"
#include "stringsizes.h"
#include "trice_limits.h"
#include <QDebug>
#include <algorithm>
@ -1060,7 +1060,7 @@ Server_Player::cmdMulligan(const Command_Mulligan &cmd, ResponseContainer & /*rc
}
Response::ResponseCode
Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges)
Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/, GameEventStorage &ges) const
{
if (spectator) {
return Response::RespFunctionNotAllowed;
@ -1069,9 +1069,15 @@ Server_Player::cmdRollDie(const Command_RollDie &cmd, ResponseContainer & /*rc*/
return Response::RespContextError;
}
const auto validatedSides = static_cast<int>(std::min(std::max(cmd.sides(), MINIMUM_DIE_SIDES), MAXIMUM_DIE_SIDES));
const auto validatedDiceToRoll =
static_cast<int>(std::min(std::max(cmd.count(), MINIMUM_DICE_TO_ROLL), MAXIMUM_DICE_TO_ROLL));
Event_RollDie event;
event.set_sides(cmd.sides());
event.set_value(rng->rand(1, cmd.sides()));
event.set_sides(validatedSides);
for (auto i = 0; i < validatedDiceToRoll; ++i) {
event.add_values(rng->rand(1, validatedSides));
}
ges.enqueueGameEvent(event, playerId);
return Response::RespOk;

View file

@ -203,7 +203,7 @@ public:
Response::ResponseCode cmdGameSay(const Command_GameSay &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdShuffle(const Command_Shuffle &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdMulligan(const Command_Mulligan &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdRollDie(const Command_RollDie &cmd, ResponseContainer &rc, GameEventStorage &ges) const;
Response::ResponseCode cmdDrawCards(const Command_DrawCards &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdUndoDraw(const Command_UndoDraw &cmd, ResponseContainer &rc, GameEventStorage &ges);
Response::ResponseCode cmdMoveCard(const Command_MoveCard &cmd, ResponseContainer &rc, GameEventStorage &ges);

View file

@ -21,7 +21,7 @@
#include "server_game.h"
#include "server_player.h"
#include "server_room.h"
#include "stringsizes.h"
#include "trice_limits.h"
#include <QDateTime>
#include <QDebug>

View file

@ -11,7 +11,7 @@
#include "pb/serverinfo_room.pb.h"
#include "server_game.h"
#include "server_protocolhandler.h"
#include "stringsizes.h"
#include "trice_limits.h"
#include <QDateTime>
#include <QDebug>

View file

@ -1,6 +1,5 @@
// max sizes of strings used in the protocol
#ifndef STRINGSIZES_H
#define STRINGSIZES_H
#ifndef TRICE_LIMITS_H
#define TRICE_LIMITS_H
#include <QString>
@ -11,6 +10,11 @@ constexpr int MAX_TEXT_LENGTH = 0xfff;
// max size for deck files and pictures
constexpr int MAX_FILE_LENGTH = 0xfffff; // about a megabyte
constexpr uint MINIMUM_DIE_SIDES = 2;
constexpr uint MAXIMUM_DIE_SIDES = 1000000;
constexpr uint MINIMUM_DICE_TO_ROLL = 1;
constexpr uint MAXIMUM_DICE_TO_ROLL = 100;
// optimized functions to get qstrings that are at most that long
static inline QString nameFromStdString(const std::string &_string)
{
@ -25,4 +29,4 @@ static inline QString fileFromStdString(const std::string &_string)
return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_FILE_LENGTH));
}
#endif // STRINGSIZES_H
#endif // TRICE_LIMITS_H