39 if (name.empty() || name.length() > 32)
45 return std::all_of(name.begin(), name.end(),
46 [](
unsigned char c) { return std::isalnum(c) || c ==
' '; });
58 if (name.empty() || name.length() > 32)
64 return std::all_of(name.begin(), name.end(),
65 [](
unsigned char c) { return std::isalnum(c) || c ==
' ' || c ==
'-'; });
76 if (ip.empty() || ip.length() > 15)
82 return std::all_of(ip.begin(), ip.end(), [](
char c) { return std::isdigit(c) || c ==
'.'; });
91 [[nodiscard]]
static bool isValidPort(std::uint16_t port) {
return port > 0 && port <= 65535; }
100 [[nodiscard]]
static std::string
sanitize(
const std::string &input,
size_t maxLength = 32)
103 result.reserve(std::min(input.length(), maxLength));
105 for (
unsigned char c : input)
107 if (std::isalnum(c) || c ==
' ' || c ==
'-' || c ==
'_')
109 if (result.length() < maxLength)
Security-related configuration constants.
constexpr size_t MAX_PACKETS_PER_SECOND
Maximum packets per second per client.
constexpr int SESSION_TIMEOUT_MINUTES
Session timeout duration (minutes)
constexpr std::uint32_t MAX_SESSION_ID
Maximum session ID value.
constexpr int CONNECTION_TIMEOUT_MS
Connection attempt timeout (milliseconds)
constexpr size_t HMAC_SIZE
HMAC size for message integrity (bytes) - SHA256.
constexpr size_t MAX_PLAYER_NAME_LENGTH
Maximum player name length.
constexpr std::uint32_t MIN_SESSION_ID
Minimum session ID value.
constexpr size_t MAX_PAYLOAD_SIZE
Maximum payload size (bytes)
constexpr size_t MAX_LOBBY_NAME_LENGTH
Maximum lobby name length.
constexpr int MAX_RETRY_ATTEMPTS
Maximum number of retry attempts.
constexpr size_t MAX_CLIENTS_PER_IP
Maximum concurrent connections per IP.
constexpr int CLIENT_TIMEOUT_SECONDS
Client timeout duration (seconds)
constexpr size_t MAX_PACKET_SIZE
Maximum packet size (bytes)