#ifndef TRICE_LIMITS_H #define TRICE_LIMITS_H #include #include #include // max size for short strings, like names and things that are generally a single phrase constexpr int MAX_NAME_LENGTH = 0xff; // max size for chat messages and text contents constexpr int MAX_TEXT_LENGTH = 0xfff; // max size for deck files and pictures constexpr int MAX_FILE_LENGTH = 0x1fffff; // about 2 megabytes 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; // Counter value bounds [0, MAX_COUNTER_VALUE]. // Counters (on cards or players) are non-negative values. // The max of 999 is a display constraint (3-digit rendering) and reasonable gameplay limit. // Server enforces these bounds; client may also check for UX optimization. constexpr int MAX_COUNTER_VALUE = 999; /** * @brief Overflow-safe clamped addition: returns value + delta bounded to [minValue, maxValue]. * * Uses a 64-bit intermediate so the addition itself cannot overflow int. Shared by the * counter arithmetic in Server_Card and Server_Counter so both stay in sync. */ inline int addClamped(int value, int delta, int minValue, int maxValue) { const auto result = static_cast(value) + static_cast(delta); return static_cast(qBound(static_cast(minValue), result, static_cast(maxValue))); } // optimized functions to get qstrings that are at most that long static inline QString nameFromStdString(const std::string &_string) { return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_NAME_LENGTH)); } static inline QString textFromStdString(const std::string &_string) { return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_TEXT_LENGTH)); } static inline QString fileFromStdString(const std::string &_string) { return QString::fromUtf8(_string.data(), std::min(int(_string.size()), MAX_FILE_LENGTH)); } #endif // TRICE_LIMITS_H