chore: make all the regexes static const

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2025-04-16 18:55:26 +03:00
parent 21c90527d2
commit c5fd5e6ac1
37 changed files with 87 additions and 84 deletions

View File

@ -55,7 +55,8 @@
MinecraftAccount::MinecraftAccount(QObject* parent) : QObject(parent)
{
data.internalId = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
static const QRegularExpression s_removeChars("[{}-]");
data.internalId = QUuid::createUuid().toString().remove(s_removeChars);
}
MinecraftAccountPtr MinecraftAccount::loadFromJsonV3(const QJsonObject& json)
@ -76,14 +77,15 @@ MinecraftAccountPtr MinecraftAccount::createBlankMSA()
MinecraftAccountPtr MinecraftAccount::createOffline(const QString& username)
{
static const QRegularExpression s_removeChars("[{}-]");
auto account = makeShared<MinecraftAccount>();
account->data.type = AccountType::Offline;
account->data.yggdrasilToken.token = "0";
account->data.yggdrasilToken.validity = Validity::Certain;
account->data.yggdrasilToken.issueInstant = QDateTime::currentDateTimeUtc();
account->data.yggdrasilToken.extra["userName"] = username;
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(QRegularExpression("[{}-]"));
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(QRegularExpression("[{}-]"));
account->data.yggdrasilToken.extra["clientToken"] = QUuid::createUuid().toString().remove(s_removeChars);
account->data.minecraftProfile.id = uuidFromUsername(username).toString().remove(s_removeChars);
account->data.minecraftProfile.name = username;
account->data.minecraftProfile.validity = Validity::Certain;
return account;
@ -231,6 +233,7 @@ bool MinecraftAccount::shouldRefresh() const
void MinecraftAccount::fillSession(AuthSessionPtr session)
{
static const QRegularExpression s_removeChars("[{}-]");
if (ownsMinecraft() && !hasProfile()) {
session->status = AuthSession::RequiresProfileSetup;
} else {
@ -248,7 +251,7 @@ void MinecraftAccount::fillSession(AuthSessionPtr session)
// profile ID
session->uuid = data.profileId();
if (session->uuid.isEmpty())
session->uuid = uuidFromUsername(session->player_name).toString().remove(QRegularExpression("[{}-]"));
session->uuid = uuidFromUsername(session->player_name).toString().remove(s_removeChars);
// 'legacy' or 'mojang', depending on account type
session->user_type = typeString();
if (!session->access_token.isEmpty()) {