1+ // SPDX-License-Identifier: GPL-3.0-only
2+ /*
3+ * Freesm Launcher - Minecraft Launcher
4+ * Copyright (C) 2026 so5iso4ka <so5iso4ka@icloud.com>
5+ *
6+ * This program is free software: you can redistribute it and/or modify
7+ * it under the terms of the GNU General Public License as published by
8+ * the Free Software Foundation, version 3.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17+ */
18+
19+ #pragma once
20+
21+ #include < QString>
22+
23+ class MinecraftAccount ;
24+
25+ /* !
26+ * Account identifier that can disambiguate profile ID conflicts when type/auth URL are present.
27+ */
28+ class AccountIdentifier {
29+ public:
30+ AccountIdentifier () = delete ;
31+
32+ /* !
33+ * Constructs identifier from user provided input.
34+ * If input is invalid, isValid() considered to be false.
35+ *
36+ * @param str "ProfileID[:type[:AuthURL]]" formatted string, where ProfileID is the Minecraft profile ID, type is account type (msa /
37+ * elyby / custom / offline) and AuthURL is authlib-injector auth URL, used for matching only custom accounts.
38+ * Only first two ':' characters are separators.
39+ */
40+ explicit AccountIdentifier (const QString& str);
41+
42+ /* !
43+ * Constructs identifier from profile ID, account type and authlib-injector auth URL.
44+ *
45+ * @param profileId Minecraft profile ID
46+ * @param accountType Account type ("msa" / "elyby" / "custom" / "offline" / "")
47+ * @param authUrl authlib-injector auth URL, used for matching only custom accounts
48+ */
49+ explicit AccountIdentifier (QString profileId, QString accountType, QString authUrl = {});
50+
51+ /* !
52+ * Constructs identifier from existing Minecraft account.
53+ *
54+ * @param account a valid Minecraft account
55+ */
56+ explicit AccountIdentifier (const MinecraftAccount& account);
57+
58+ /* !
59+ * @return whether the identifier is valid
60+ */
61+ bool isValid () const ;
62+
63+ /* !
64+ * @return profile ID
65+ */
66+ QString profileId () const ;
67+
68+ /* !
69+ * @return account type string
70+ */
71+ QString accountType () const ;
72+
73+ /* !
74+ * @return authlib-injector auth URL
75+ */
76+ QString authUrl () const ;
77+
78+ /* !
79+ * Matches specified account with identifier. Returns false if the identifier is not valid.
80+ * Empty account type matches any account with the same profile ID.
81+ * For custom accounts, a non-empty auth URL must also match.
82+ *
83+ * @param account a valid Minecraft account
84+ * @return whether the account match this identifier
85+ */
86+ bool matches (const MinecraftAccount& account) const ;
87+
88+ private:
89+ QString m_profileId;
90+ QString m_accountType;
91+ QString m_authUrl;
92+ };
93+
94+ enum class AccountFindError { NoError, InvalidId, NotFound, Ambiguous };
95+
96+ struct AccountFindResult {
97+ int index = -1 ;
98+ AccountFindError error = AccountFindError::NotFound;
99+
100+ bool found () const { return index >= 0 && error == AccountFindError::NoError; }
101+ };
0 commit comments