mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-19 13:23:55 -07:00
implement max lengths for input dialogs that are sent to the server (#4522)
* implement max lengths for input dialogs that are sent to the server * missed a double setMaxLength * implement max string lengths server side * add custom getText dialog with max length * fix deck storage tab and miscellaneous server side * add max size for deck uploads * final pass on client side limits
This commit is contained in:
parent
d61c604bf4
commit
994704d353
37 changed files with 564 additions and 348 deletions
29
common/stringsizes.h
Normal file
29
common/stringsizes.h
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// max sizes of strings used in the protocol
|
||||
#ifndef STRINGSIZES_H
|
||||
#define STRINGSIZES_H
|
||||
|
||||
#include <QString>
|
||||
#include <QtMath>
|
||||
|
||||
// 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 = 0xfffff; // about a megabyte
|
||||
|
||||
// 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 // STRINGSIZES_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue