Files
eden/src/yuzu/multiplayer/validation.h
T

51 lines
1.5 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: Copyright 2017 Citra Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2021-12-25 20:27:52 +01:00
#pragma once
2022-10-17 16:55:40 -07:00
#include <QRegularExpression>
2021-12-25 20:27:52 +01:00
#include <QString>
#include <QValidator>
class Validation {
public:
Validation()
: room_name(room_name_regex), nickname(nickname_regex), ip(ip_regex), port(0, UINT16_MAX) {}
2021-12-25 20:27:52 +01:00
~Validation() = default;
const QValidator* GetRoomName() const {
return &room_name;
}
const QValidator* GetNickname() const {
return &nickname;
}
const QValidator* GetIP() const {
return &ip;
}
const QValidator* GetPort() const {
return &port;
}
private:
/// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
2022-10-17 16:55:40 -07:00
QRegularExpression room_name_regex =
QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}"));
QRegularExpressionValidator room_name;
2021-12-25 20:27:52 +01:00
/// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
2022-10-17 16:55:40 -07:00
const QRegularExpression nickname_regex =
QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}"));
QRegularExpressionValidator nickname;
2021-12-25 20:27:52 +01:00
/// ipv4 address only
// TODO remove this when we support hostnames in direct connect
2022-10-17 16:55:40 -07:00
QRegularExpression ip_regex = QRegularExpression(QStringLiteral(
2021-12-25 20:27:52 +01:00
"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|"
"2[0-4][0-9]|25[0-5])"));
2022-10-17 16:55:40 -07:00
QRegularExpressionValidator ip;
2021-12-25 20:27:52 +01:00
/// port must be between 0 and 65535
QIntValidator port;
};