diff options
| author | 2018-08-20 10:59:15 -0400 | |
|---|---|---|
| committer | 2018-08-20 10:59:15 -0400 | |
| commit | 943771e703c7493b2c807fa86b6208a5bd903913 (patch) | |
| tree | 13aea6a3c32686a1d465d30735e31b7293262684 /src | |
| parent | Merge pull request #1120 from ogniK5377/rgba8-uint (diff) | |
| parent | Better UUID randomness (diff) | |
| download | yuzu-943771e703c7493b2c807fa86b6208a5bd903913.tar.gz yuzu-943771e703c7493b2c807fa86b6208a5bd903913.tar.xz yuzu-943771e703c7493b2c807fa86b6208a5bd903913.zip | |
Merge pull request #1017 from ogniK5377/better-account
New account backend to allow for future extended support
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 126 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc.h | 6 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_aa.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_aa.h | 3 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_su.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_su.h | 3 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_u0.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_u0.h | 3 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_u1.cpp | 5 | ||||
| -rw-r--r-- | src/core/hle/service/acc/acc_u1.h | 3 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 226 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 124 |
13 files changed, 440 insertions, 74 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 67ad6109a..31a7bf6fd 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -122,6 +122,8 @@ add_library(core STATIC | |||
| 122 | hle/service/acc/acc_u0.h | 122 | hle/service/acc/acc_u0.h |
| 123 | hle/service/acc/acc_u1.cpp | 123 | hle/service/acc/acc_u1.cpp |
| 124 | hle/service/acc/acc_u1.h | 124 | hle/service/acc/acc_u1.h |
| 125 | hle/service/acc/profile_manager.cpp | ||
| 126 | hle/service/acc/profile_manager.h | ||
| 125 | hle/service/am/am.cpp | 127 | hle/service/am/am.cpp |
| 126 | hle/service/am/am.h | 128 | hle/service/am/am.h |
| 127 | hle/service/am/applet_ae.cpp | 129 | hle/service/am/applet_ae.cpp |
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index f3c5b1b9c..979f2f892 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -3,7 +3,10 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include "common/common_types.h" | ||
| 6 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/swap.h" | ||
| 9 | #include "core/core_timing.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | 10 | #include "core/hle/ipc_helpers.h" |
| 8 | #include "core/hle/service/acc/acc.h" | 11 | #include "core/hle/service/acc/acc.h" |
| 9 | #include "core/hle/service/acc/acc_aa.h" | 12 | #include "core/hle/service/acc/acc_aa.h" |
| @@ -13,7 +16,6 @@ | |||
| 13 | #include "core/settings.h" | 16 | #include "core/settings.h" |
| 14 | 17 | ||
| 15 | namespace Service::Account { | 18 | namespace Service::Account { |
| 16 | |||
| 17 | // TODO: RE this structure | 19 | // TODO: RE this structure |
| 18 | struct UserData { | 20 | struct UserData { |
| 19 | INSERT_PADDING_WORDS(1); | 21 | INSERT_PADDING_WORDS(1); |
| @@ -25,19 +27,13 @@ struct UserData { | |||
| 25 | }; | 27 | }; |
| 26 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 27 | 29 | ||
| 28 | struct ProfileBase { | ||
| 29 | u128 user_id; | ||
| 30 | u64 timestamp; | ||
| 31 | std::array<u8, 0x20> username; | ||
| 32 | }; | ||
| 33 | static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); | ||
| 34 | |||
| 35 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? | 30 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? |
| 36 | static constexpr u128 DEFAULT_USER_ID{1ull, 0ull}; | 31 | static UUID DEFAULT_USER_ID{1ull, 0ull}; |
| 37 | 32 | ||
| 38 | class IProfile final : public ServiceFramework<IProfile> { | 33 | class IProfile final : public ServiceFramework<IProfile> { |
| 39 | public: | 34 | public: |
| 40 | explicit IProfile(u128 user_id) : ServiceFramework("IProfile"), user_id(user_id) { | 35 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| 36 | : ServiceFramework("IProfile"), user_id(user_id), profile_manager(profile_manager) { | ||
| 41 | static const FunctionInfo functions[] = { | 37 | static const FunctionInfo functions[] = { |
| 42 | {0, &IProfile::Get, "Get"}, | 38 | {0, &IProfile::Get, "Get"}, |
| 43 | {1, &IProfile::GetBase, "GetBase"}, | 39 | {1, &IProfile::GetBase, "GetBase"}, |
| @@ -49,38 +45,34 @@ public: | |||
| 49 | 45 | ||
| 50 | private: | 46 | private: |
| 51 | void Get(Kernel::HLERequestContext& ctx) { | 47 | void Get(Kernel::HLERequestContext& ctx) { |
| 52 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 48 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); |
| 53 | ProfileBase profile_base{}; | 49 | ProfileBase profile_base{}; |
| 54 | profile_base.user_id = user_id; | 50 | std::array<u8, MAX_DATA> data{}; |
| 55 | if (Settings::values.username.size() > profile_base.username.size()) { | 51 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { |
| 56 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 52 | ctx.WriteBuffer(data); |
| 57 | profile_base.username.begin()); | 53 | IPC::ResponseBuilder rb{ctx, 16}; |
| 54 | rb.Push(RESULT_SUCCESS); | ||
| 55 | rb.PushRaw(profile_base); | ||
| 58 | } else { | 56 | } else { |
| 59 | std::copy(Settings::values.username.begin(), Settings::values.username.end(), | 57 | LOG_ERROR(Service_ACC, "Failed to get profile base and data for user={}", |
| 60 | profile_base.username.begin()); | 58 | user_id.Format()); |
| 59 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 60 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code | ||
| 61 | } | 61 | } |
| 62 | |||
| 63 | IPC::ResponseBuilder rb{ctx, 16}; | ||
| 64 | rb.Push(RESULT_SUCCESS); | ||
| 65 | rb.PushRaw(profile_base); | ||
| 66 | } | 62 | } |
| 67 | 63 | ||
| 68 | void GetBase(Kernel::HLERequestContext& ctx) { | 64 | void GetBase(Kernel::HLERequestContext& ctx) { |
| 69 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 65 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); |
| 70 | |||
| 71 | // TODO(Subv): Retrieve this information from somewhere. | ||
| 72 | ProfileBase profile_base{}; | 66 | ProfileBase profile_base{}; |
| 73 | profile_base.user_id = user_id; | 67 | if (profile_manager.GetProfileBase(user_id, profile_base)) { |
| 74 | if (Settings::values.username.size() > profile_base.username.size()) { | 68 | IPC::ResponseBuilder rb{ctx, 16}; |
| 75 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 69 | rb.Push(RESULT_SUCCESS); |
| 76 | profile_base.username.begin()); | 70 | rb.PushRaw(profile_base); |
| 77 | } else { | 71 | } else { |
| 78 | std::copy(Settings::values.username.begin(), Settings::values.username.end(), | 72 | LOG_ERROR(Service_ACC, "Failed to get profile base for user={}", user_id.Format()); |
| 79 | profile_base.username.begin()); | 73 | IPC::ResponseBuilder rb{ctx, 2}; |
| 74 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code | ||
| 80 | } | 75 | } |
| 81 | IPC::ResponseBuilder rb{ctx, 16}; | ||
| 82 | rb.Push(RESULT_SUCCESS); | ||
| 83 | rb.PushRaw(profile_base); | ||
| 84 | } | 76 | } |
| 85 | 77 | ||
| 86 | void LoadImage(Kernel::HLERequestContext& ctx) { | 78 | void LoadImage(Kernel::HLERequestContext& ctx) { |
| @@ -104,7 +96,8 @@ private: | |||
| 104 | rb.Push<u32>(jpeg_size); | 96 | rb.Push<u32>(jpeg_size); |
| 105 | } | 97 | } |
| 106 | 98 | ||
| 107 | u128 user_id; ///< The user id this profile refers to. | 99 | const ProfileManager& profile_manager; |
| 100 | UUID user_id; ///< The user id this profile refers to. | ||
| 108 | }; | 101 | }; |
| 109 | 102 | ||
| 110 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { | 103 | class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { |
| @@ -141,44 +134,57 @@ private: | |||
| 141 | }; | 134 | }; |
| 142 | 135 | ||
| 143 | void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { | 136 | void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { |
| 144 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 137 | LOG_INFO(Service_ACC, "called"); |
| 145 | IPC::ResponseBuilder rb{ctx, 3}; | 138 | IPC::ResponseBuilder rb{ctx, 3}; |
| 146 | rb.Push(RESULT_SUCCESS); | 139 | rb.Push(RESULT_SUCCESS); |
| 147 | rb.Push<u32>(1); | 140 | rb.Push<u32>(static_cast<u32>(profile_manager->GetUserCount())); |
| 148 | } | 141 | } |
| 149 | 142 | ||
| 150 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { | 143 | void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { |
| 151 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 144 | IPC::RequestParser rp{ctx}; |
| 145 | UUID user_id = rp.PopRaw<UUID>(); | ||
| 146 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); | ||
| 147 | |||
| 152 | IPC::ResponseBuilder rb{ctx, 3}; | 148 | IPC::ResponseBuilder rb{ctx, 3}; |
| 153 | rb.Push(RESULT_SUCCESS); | 149 | rb.Push(RESULT_SUCCESS); |
| 154 | rb.Push(true); // TODO: Check when this is supposed to return true and when not | 150 | rb.Push(profile_manager->UserExists(user_id)); |
| 155 | } | 151 | } |
| 156 | 152 | ||
| 157 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { | 153 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { |
| 158 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 154 | LOG_INFO(Service_ACC, "called"); |
| 159 | // TODO(Subv): There is only one user for now. | 155 | ctx.WriteBuffer(profile_manager->GetAllUsers()); |
| 160 | const std::vector<u128> user_ids = {DEFAULT_USER_ID}; | ||
| 161 | ctx.WriteBuffer(user_ids); | ||
| 162 | IPC::ResponseBuilder rb{ctx, 2}; | 156 | IPC::ResponseBuilder rb{ctx, 2}; |
| 163 | rb.Push(RESULT_SUCCESS); | 157 | rb.Push(RESULT_SUCCESS); |
| 164 | } | 158 | } |
| 165 | 159 | ||
| 166 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { | 160 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { |
| 167 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 161 | LOG_INFO(Service_ACC, "called"); |
| 168 | // TODO(Subv): There is only one user for now. | 162 | ctx.WriteBuffer(profile_manager->GetOpenUsers()); |
| 169 | const std::vector<u128> user_ids = {DEFAULT_USER_ID}; | ||
| 170 | ctx.WriteBuffer(user_ids); | ||
| 171 | IPC::ResponseBuilder rb{ctx, 2}; | 163 | IPC::ResponseBuilder rb{ctx, 2}; |
| 172 | rb.Push(RESULT_SUCCESS); | 164 | rb.Push(RESULT_SUCCESS); |
| 173 | } | 165 | } |
| 174 | 166 | ||
| 167 | void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | ||
| 168 | LOG_INFO(Service_ACC, "called"); | ||
| 169 | IPC::ResponseBuilder rb{ctx, 6}; | ||
| 170 | rb.Push(RESULT_SUCCESS); | ||
| 171 | rb.PushRaw<UUID>(profile_manager->GetLastOpenedUser()); | ||
| 172 | } | ||
| 173 | |||
| 175 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { | 174 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { |
| 176 | IPC::RequestParser rp{ctx}; | 175 | IPC::RequestParser rp{ctx}; |
| 177 | u128 user_id = rp.PopRaw<u128>(); | 176 | UUID user_id = rp.PopRaw<UUID>(); |
| 178 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 177 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 179 | rb.Push(RESULT_SUCCESS); | 178 | rb.Push(RESULT_SUCCESS); |
| 180 | rb.PushIpcInterface<IProfile>(user_id); | 179 | rb.PushIpcInterface<IProfile>(user_id, *profile_manager); |
| 181 | LOG_DEBUG(Service_ACC, "called user_id=0x{:016X}{:016X}", user_id[1], user_id[0]); | 180 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); |
| 181 | } | ||
| 182 | |||
| 183 | void Module::Interface::IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx) { | ||
| 184 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 185 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 186 | rb.Push(RESULT_SUCCESS); | ||
| 187 | rb.Push(profile_manager->CanSystemRegisterUser()); | ||
| 182 | } | 188 | } |
| 183 | 189 | ||
| 184 | void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { | 190 | void Module::Interface::InitializeApplicationInfo(Kernel::HLERequestContext& ctx) { |
| @@ -194,22 +200,18 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo | |||
| 194 | LOG_DEBUG(Service_ACC, "called"); | 200 | LOG_DEBUG(Service_ACC, "called"); |
| 195 | } | 201 | } |
| 196 | 202 | ||
| 197 | void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | 203 | Module::Interface::Interface(std::shared_ptr<Module> module, |
| 198 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 204 | std::shared_ptr<ProfileManager> profile_manager, const char* name) |
| 199 | IPC::ResponseBuilder rb{ctx, 6}; | 205 | : ServiceFramework(name), module(std::move(module)), |
| 200 | rb.Push(RESULT_SUCCESS); | 206 | profile_manager(std::move(profile_manager)) {} |
| 201 | rb.PushRaw(DEFAULT_USER_ID); | ||
| 202 | } | ||
| 203 | |||
| 204 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) | ||
| 205 | : ServiceFramework(name), module(std::move(module)) {} | ||
| 206 | 207 | ||
| 207 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 208 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
| 208 | auto module = std::make_shared<Module>(); | 209 | auto module = std::make_shared<Module>(); |
| 209 | std::make_shared<ACC_AA>(module)->InstallAsService(service_manager); | 210 | auto profile_manager = std::make_shared<ProfileManager>(); |
| 210 | std::make_shared<ACC_SU>(module)->InstallAsService(service_manager); | 211 | std::make_shared<ACC_AA>(module, profile_manager)->InstallAsService(service_manager); |
| 211 | std::make_shared<ACC_U0>(module)->InstallAsService(service_manager); | 212 | std::make_shared<ACC_SU>(module, profile_manager)->InstallAsService(service_manager); |
| 212 | std::make_shared<ACC_U1>(module)->InstallAsService(service_manager); | 213 | std::make_shared<ACC_U0>(module, profile_manager)->InstallAsService(service_manager); |
| 214 | std::make_shared<ACC_U1>(module, profile_manager)->InstallAsService(service_manager); | ||
| 213 | } | 215 | } |
| 214 | 216 | ||
| 215 | } // namespace Service::Account | 217 | } // namespace Service::Account |
diff --git a/src/core/hle/service/acc/acc.h b/src/core/hle/service/acc/acc.h index 88cabaa01..d7c6d2415 100644 --- a/src/core/hle/service/acc/acc.h +++ b/src/core/hle/service/acc/acc.h | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/service/acc/profile_manager.h" | ||
| 7 | #include "core/hle/service/service.h" | 8 | #include "core/hle/service/service.h" |
| 8 | 9 | ||
| 9 | namespace Service::Account { | 10 | namespace Service::Account { |
| @@ -12,7 +13,8 @@ class Module final { | |||
| 12 | public: | 13 | public: |
| 13 | class Interface : public ServiceFramework<Interface> { | 14 | class Interface : public ServiceFramework<Interface> { |
| 14 | public: | 15 | public: |
| 15 | explicit Interface(std::shared_ptr<Module> module, const char* name); | 16 | explicit Interface(std::shared_ptr<Module> module, |
| 17 | std::shared_ptr<ProfileManager> profile_manager, const char* name); | ||
| 16 | 18 | ||
| 17 | void GetUserCount(Kernel::HLERequestContext& ctx); | 19 | void GetUserCount(Kernel::HLERequestContext& ctx); |
| 18 | void GetUserExistence(Kernel::HLERequestContext& ctx); | 20 | void GetUserExistence(Kernel::HLERequestContext& ctx); |
| @@ -22,9 +24,11 @@ public: | |||
| 22 | void GetProfile(Kernel::HLERequestContext& ctx); | 24 | void GetProfile(Kernel::HLERequestContext& ctx); |
| 23 | void InitializeApplicationInfo(Kernel::HLERequestContext& ctx); | 25 | void InitializeApplicationInfo(Kernel::HLERequestContext& ctx); |
| 24 | void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx); | 26 | void GetBaasAccountManagerForApplication(Kernel::HLERequestContext& ctx); |
| 27 | void IsUserRegistrationRequestPermitted(Kernel::HLERequestContext& ctx); | ||
| 25 | 28 | ||
| 26 | protected: | 29 | protected: |
| 27 | std::shared_ptr<Module> module; | 30 | std::shared_ptr<Module> module; |
| 31 | std::shared_ptr<ProfileManager> profile_manager; | ||
| 28 | }; | 32 | }; |
| 29 | }; | 33 | }; |
| 30 | 34 | ||
diff --git a/src/core/hle/service/acc/acc_aa.cpp b/src/core/hle/service/acc/acc_aa.cpp index 280b3e464..9bd595a37 100644 --- a/src/core/hle/service/acc/acc_aa.cpp +++ b/src/core/hle/service/acc/acc_aa.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | namespace Service::Account { | 7 | namespace Service::Account { |
| 8 | 8 | ||
| 9 | ACC_AA::ACC_AA(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:aa") { | 9 | ACC_AA::ACC_AA(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager) |
| 10 | : Module::Interface(std::move(module), std::move(profile_manager), "acc:aa") { | ||
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {0, nullptr, "EnsureCacheAsync"}, | 12 | {0, nullptr, "EnsureCacheAsync"}, |
| 12 | {1, nullptr, "LoadCache"}, | 13 | {1, nullptr, "LoadCache"}, |
diff --git a/src/core/hle/service/acc/acc_aa.h b/src/core/hle/service/acc/acc_aa.h index 796f7ef85..2e08c781a 100644 --- a/src/core/hle/service/acc/acc_aa.h +++ b/src/core/hle/service/acc/acc_aa.h | |||
| @@ -10,7 +10,8 @@ namespace Service::Account { | |||
| 10 | 10 | ||
| 11 | class ACC_AA final : public Module::Interface { | 11 | class ACC_AA final : public Module::Interface { |
| 12 | public: | 12 | public: |
| 13 | explicit ACC_AA(std::shared_ptr<Module> module); | 13 | explicit ACC_AA(std::shared_ptr<Module> module, |
| 14 | std::shared_ptr<ProfileManager> profile_manager); | ||
| 14 | }; | 15 | }; |
| 15 | 16 | ||
| 16 | } // namespace Service::Account | 17 | } // namespace Service::Account |
diff --git a/src/core/hle/service/acc/acc_su.cpp b/src/core/hle/service/acc/acc_su.cpp index 8b2a71f37..0218ee859 100644 --- a/src/core/hle/service/acc/acc_su.cpp +++ b/src/core/hle/service/acc/acc_su.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | namespace Service::Account { | 7 | namespace Service::Account { |
| 8 | 8 | ||
| 9 | ACC_SU::ACC_SU(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:su") { | 9 | ACC_SU::ACC_SU(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager) |
| 10 | : Module::Interface(std::move(module), std::move(profile_manager), "acc:su") { | ||
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {0, &ACC_SU::GetUserCount, "GetUserCount"}, | 12 | {0, &ACC_SU::GetUserCount, "GetUserCount"}, |
| 12 | {1, &ACC_SU::GetUserExistence, "GetUserExistence"}, | 13 | {1, &ACC_SU::GetUserExistence, "GetUserExistence"}, |
| @@ -15,7 +16,7 @@ ACC_SU::ACC_SU(std::shared_ptr<Module> module) : Module::Interface(std::move(mod | |||
| 15 | {4, &ACC_SU::GetLastOpenedUser, "GetLastOpenedUser"}, | 16 | {4, &ACC_SU::GetLastOpenedUser, "GetLastOpenedUser"}, |
| 16 | {5, &ACC_SU::GetProfile, "GetProfile"}, | 17 | {5, &ACC_SU::GetProfile, "GetProfile"}, |
| 17 | {6, nullptr, "GetProfileDigest"}, | 18 | {6, nullptr, "GetProfileDigest"}, |
| 18 | {50, nullptr, "IsUserRegistrationRequestPermitted"}, | 19 | {50, &ACC_SU::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"}, |
| 19 | {51, nullptr, "TrySelectUserWithoutInteraction"}, | 20 | {51, nullptr, "TrySelectUserWithoutInteraction"}, |
| 20 | {60, nullptr, "ListOpenContextStoredUsers"}, | 21 | {60, nullptr, "ListOpenContextStoredUsers"}, |
| 21 | {100, nullptr, "GetUserRegistrationNotifier"}, | 22 | {100, nullptr, "GetUserRegistrationNotifier"}, |
diff --git a/src/core/hle/service/acc/acc_su.h b/src/core/hle/service/acc/acc_su.h index 3894a6991..79a47d88d 100644 --- a/src/core/hle/service/acc/acc_su.h +++ b/src/core/hle/service/acc/acc_su.h | |||
| @@ -11,7 +11,8 @@ namespace Account { | |||
| 11 | 11 | ||
| 12 | class ACC_SU final : public Module::Interface { | 12 | class ACC_SU final : public Module::Interface { |
| 13 | public: | 13 | public: |
| 14 | explicit ACC_SU(std::shared_ptr<Module> module); | 14 | explicit ACC_SU(std::shared_ptr<Module> module, |
| 15 | std::shared_ptr<ProfileManager> profile_manager); | ||
| 15 | }; | 16 | }; |
| 16 | 17 | ||
| 17 | } // namespace Account | 18 | } // namespace Account |
diff --git a/src/core/hle/service/acc/acc_u0.cpp b/src/core/hle/service/acc/acc_u0.cpp index d84c8b2e1..84a4d05b8 100644 --- a/src/core/hle/service/acc/acc_u0.cpp +++ b/src/core/hle/service/acc/acc_u0.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | namespace Service::Account { | 7 | namespace Service::Account { |
| 8 | 8 | ||
| 9 | ACC_U0::ACC_U0(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:u0") { | 9 | ACC_U0::ACC_U0(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager) |
| 10 | : Module::Interface(std::move(module), std::move(profile_manager), "acc:u0") { | ||
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {0, &ACC_U0::GetUserCount, "GetUserCount"}, | 12 | {0, &ACC_U0::GetUserCount, "GetUserCount"}, |
| 12 | {1, &ACC_U0::GetUserExistence, "GetUserExistence"}, | 13 | {1, &ACC_U0::GetUserExistence, "GetUserExistence"}, |
| @@ -15,7 +16,7 @@ ACC_U0::ACC_U0(std::shared_ptr<Module> module) : Module::Interface(std::move(mod | |||
| 15 | {4, &ACC_U0::GetLastOpenedUser, "GetLastOpenedUser"}, | 16 | {4, &ACC_U0::GetLastOpenedUser, "GetLastOpenedUser"}, |
| 16 | {5, &ACC_U0::GetProfile, "GetProfile"}, | 17 | {5, &ACC_U0::GetProfile, "GetProfile"}, |
| 17 | {6, nullptr, "GetProfileDigest"}, | 18 | {6, nullptr, "GetProfileDigest"}, |
| 18 | {50, nullptr, "IsUserRegistrationRequestPermitted"}, | 19 | {50, &ACC_U0::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"}, |
| 19 | {51, nullptr, "TrySelectUserWithoutInteraction"}, | 20 | {51, nullptr, "TrySelectUserWithoutInteraction"}, |
| 20 | {60, nullptr, "ListOpenContextStoredUsers"}, | 21 | {60, nullptr, "ListOpenContextStoredUsers"}, |
| 21 | {100, &ACC_U0::InitializeApplicationInfo, "InitializeApplicationInfo"}, | 22 | {100, &ACC_U0::InitializeApplicationInfo, "InitializeApplicationInfo"}, |
diff --git a/src/core/hle/service/acc/acc_u0.h b/src/core/hle/service/acc/acc_u0.h index 6ded596b3..e8a114f99 100644 --- a/src/core/hle/service/acc/acc_u0.h +++ b/src/core/hle/service/acc/acc_u0.h | |||
| @@ -10,7 +10,8 @@ namespace Service::Account { | |||
| 10 | 10 | ||
| 11 | class ACC_U0 final : public Module::Interface { | 11 | class ACC_U0 final : public Module::Interface { |
| 12 | public: | 12 | public: |
| 13 | explicit ACC_U0(std::shared_ptr<Module> module); | 13 | explicit ACC_U0(std::shared_ptr<Module> module, |
| 14 | std::shared_ptr<ProfileManager> profile_manager); | ||
| 14 | }; | 15 | }; |
| 15 | 16 | ||
| 16 | } // namespace Service::Account | 17 | } // namespace Service::Account |
diff --git a/src/core/hle/service/acc/acc_u1.cpp b/src/core/hle/service/acc/acc_u1.cpp index 0ceaf06b5..495693949 100644 --- a/src/core/hle/service/acc/acc_u1.cpp +++ b/src/core/hle/service/acc/acc_u1.cpp | |||
| @@ -6,7 +6,8 @@ | |||
| 6 | 6 | ||
| 7 | namespace Service::Account { | 7 | namespace Service::Account { |
| 8 | 8 | ||
| 9 | ACC_U1::ACC_U1(std::shared_ptr<Module> module) : Module::Interface(std::move(module), "acc:u1") { | 9 | ACC_U1::ACC_U1(std::shared_ptr<Module> module, std::shared_ptr<ProfileManager> profile_manager) |
| 10 | : Module::Interface(std::move(module), std::move(profile_manager), "acc:u1") { | ||
| 10 | static const FunctionInfo functions[] = { | 11 | static const FunctionInfo functions[] = { |
| 11 | {0, &ACC_U1::GetUserCount, "GetUserCount"}, | 12 | {0, &ACC_U1::GetUserCount, "GetUserCount"}, |
| 12 | {1, &ACC_U1::GetUserExistence, "GetUserExistence"}, | 13 | {1, &ACC_U1::GetUserExistence, "GetUserExistence"}, |
| @@ -15,7 +16,7 @@ ACC_U1::ACC_U1(std::shared_ptr<Module> module) : Module::Interface(std::move(mod | |||
| 15 | {4, &ACC_U1::GetLastOpenedUser, "GetLastOpenedUser"}, | 16 | {4, &ACC_U1::GetLastOpenedUser, "GetLastOpenedUser"}, |
| 16 | {5, &ACC_U1::GetProfile, "GetProfile"}, | 17 | {5, &ACC_U1::GetProfile, "GetProfile"}, |
| 17 | {6, nullptr, "GetProfileDigest"}, | 18 | {6, nullptr, "GetProfileDigest"}, |
| 18 | {50, nullptr, "IsUserRegistrationRequestPermitted"}, | 19 | {50, &ACC_U1::IsUserRegistrationRequestPermitted, "IsUserRegistrationRequestPermitted"}, |
| 19 | {51, nullptr, "TrySelectUserWithoutInteraction"}, | 20 | {51, nullptr, "TrySelectUserWithoutInteraction"}, |
| 20 | {60, nullptr, "ListOpenContextStoredUsers"}, | 21 | {60, nullptr, "ListOpenContextStoredUsers"}, |
| 21 | {100, nullptr, "GetUserRegistrationNotifier"}, | 22 | {100, nullptr, "GetUserRegistrationNotifier"}, |
diff --git a/src/core/hle/service/acc/acc_u1.h b/src/core/hle/service/acc/acc_u1.h index 5e3e7659b..a77520e6f 100644 --- a/src/core/hle/service/acc/acc_u1.h +++ b/src/core/hle/service/acc/acc_u1.h | |||
| @@ -10,7 +10,8 @@ namespace Service::Account { | |||
| 10 | 10 | ||
| 11 | class ACC_U1 final : public Module::Interface { | 11 | class ACC_U1 final : public Module::Interface { |
| 12 | public: | 12 | public: |
| 13 | explicit ACC_U1(std::shared_ptr<Module> module); | 13 | explicit ACC_U1(std::shared_ptr<Module> module, |
| 14 | std::shared_ptr<ProfileManager> profile_manager); | ||
| 14 | }; | 15 | }; |
| 15 | 16 | ||
| 16 | } // namespace Service::Account | 17 | } // namespace Service::Account |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp new file mode 100644 index 000000000..62c2121fa --- /dev/null +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <boost/optional.hpp> | ||
| 6 | #include "core/hle/service/acc/profile_manager.h" | ||
| 7 | #include "core/settings.h" | ||
| 8 | |||
| 9 | namespace Service::Account { | ||
| 10 | // TODO(ogniK): Get actual error codes | ||
| 11 | constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); | ||
| 12 | constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); | ||
| 13 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | ||
| 14 | |||
| 15 | ProfileManager::ProfileManager() { | ||
| 16 | // TODO(ogniK): Create the default user we have for now until loading/saving users is added | ||
| 17 | auto user_uuid = UUID{1, 0}; | ||
| 18 | CreateNewUser(user_uuid, Settings::values.username); | ||
| 19 | OpenUser(user_uuid); | ||
| 20 | } | ||
| 21 | |||
| 22 | /// After a users creation it needs to be "registered" to the system. AddToProfiles handles the | ||
| 23 | /// internal management of the users profiles | ||
| 24 | boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) { | ||
| 25 | if (user_count >= MAX_USERS) { | ||
| 26 | return boost::none; | ||
| 27 | } | ||
| 28 | profiles[user_count] = std::move(user); | ||
| 29 | return user_count++; | ||
| 30 | } | ||
| 31 | |||
| 32 | /// Deletes a specific profile based on it's profile index | ||
| 33 | bool ProfileManager::RemoveProfileAtIndex(size_t index) { | ||
| 34 | if (index >= MAX_USERS || index >= user_count) { | ||
| 35 | return false; | ||
| 36 | } | ||
| 37 | if (index < user_count - 1) { | ||
| 38 | std::rotate(profiles.begin() + index, profiles.begin() + index + 1, profiles.end()); | ||
| 39 | } | ||
| 40 | profiles.back() = {}; | ||
| 41 | user_count--; | ||
| 42 | return true; | ||
| 43 | } | ||
| 44 | |||
| 45 | /// Helper function to register a user to the system | ||
| 46 | ResultCode ProfileManager::AddUser(ProfileInfo user) { | ||
| 47 | if (AddToProfiles(user) == boost::none) { | ||
| 48 | return ERROR_TOO_MANY_USERS; | ||
| 49 | } | ||
| 50 | return RESULT_SUCCESS; | ||
| 51 | } | ||
| 52 | |||
| 53 | /// Create a new user on the system. If the uuid of the user already exists, the user is not | ||
| 54 | /// created. | ||
| 55 | ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& username) { | ||
| 56 | if (user_count == MAX_USERS) { | ||
| 57 | return ERROR_TOO_MANY_USERS; | ||
| 58 | } | ||
| 59 | if (!uuid) { | ||
| 60 | return ERROR_ARGUMENT_IS_NULL; | ||
| 61 | } | ||
| 62 | if (username[0] == 0x0) { | ||
| 63 | return ERROR_ARGUMENT_IS_NULL; | ||
| 64 | } | ||
| 65 | if (std::any_of(profiles.begin(), profiles.end(), | ||
| 66 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { | ||
| 67 | return ERROR_USER_ALREADY_EXISTS; | ||
| 68 | } | ||
| 69 | ProfileInfo profile; | ||
| 70 | profile.user_uuid = std::move(uuid); | ||
| 71 | profile.username = username; | ||
| 72 | profile.data = {}; | ||
| 73 | profile.creation_time = 0x0; | ||
| 74 | profile.is_open = false; | ||
| 75 | return AddUser(profile); | ||
| 76 | } | ||
| 77 | |||
| 78 | /// Creates a new user on the system. This function allows a much simpler method of registration | ||
| 79 | /// specifically by allowing an std::string for the username. This is required specifically since | ||
| 80 | /// we're loading a string straight from the config | ||
| 81 | ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { | ||
| 82 | std::array<u8, 0x20> username_output; | ||
| 83 | if (username.size() > username_output.size()) { | ||
| 84 | std::copy_n(username.begin(), username_output.size(), username_output.begin()); | ||
| 85 | } else { | ||
| 86 | std::copy(username.begin(), username.end(), username_output.begin()); | ||
| 87 | } | ||
| 88 | return CreateNewUser(uuid, username_output); | ||
| 89 | } | ||
| 90 | |||
| 91 | /// Returns a users profile index based on their user id. | ||
| 92 | boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { | ||
| 93 | if (!uuid) { | ||
| 94 | return boost::none; | ||
| 95 | } | ||
| 96 | auto iter = std::find_if(profiles.begin(), profiles.end(), | ||
| 97 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | ||
| 98 | if (iter == profiles.end()) { | ||
| 99 | return boost::none; | ||
| 100 | } | ||
| 101 | return static_cast<size_t>(std::distance(profiles.begin(), iter)); | ||
| 102 | } | ||
| 103 | |||
| 104 | /// Returns a users profile index based on their profile | ||
| 105 | boost::optional<size_t> ProfileManager::GetUserIndex(ProfileInfo user) const { | ||
| 106 | return GetUserIndex(user.user_uuid); | ||
| 107 | } | ||
| 108 | |||
| 109 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | ||
| 110 | bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const { | ||
| 111 | if (index == boost::none || index >= MAX_USERS) { | ||
| 112 | return false; | ||
| 113 | } | ||
| 114 | const auto& prof_info = profiles[index.get()]; | ||
| 115 | profile.user_uuid = prof_info.user_uuid; | ||
| 116 | profile.username = prof_info.username; | ||
| 117 | profile.timestamp = prof_info.creation_time; | ||
| 118 | return true; | ||
| 119 | } | ||
| 120 | |||
| 121 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | ||
| 122 | bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const { | ||
| 123 | auto idx = GetUserIndex(uuid); | ||
| 124 | return GetProfileBase(idx, profile); | ||
| 125 | } | ||
| 126 | |||
| 127 | /// Returns the data structure used by the switch when GetProfileBase is called on acc:* | ||
| 128 | bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) const { | ||
| 129 | return GetProfileBase(user.user_uuid, profile); | ||
| 130 | } | ||
| 131 | |||
| 132 | /// Returns the current user count on the system. We keep a variable which tracks the count so we | ||
| 133 | /// don't have to loop the internal profile array every call. | ||
| 134 | size_t ProfileManager::GetUserCount() const { | ||
| 135 | return user_count; | ||
| 136 | } | ||
| 137 | |||
| 138 | /// Lists the current "opened" users on the system. Users are typically not open until they sign | ||
| 139 | /// into something or pick a profile. As of right now users should all be open until qlaunch is | ||
| 140 | /// booting | ||
| 141 | size_t ProfileManager::GetOpenUserCount() const { | ||
| 142 | return std::count_if(profiles.begin(), profiles.end(), | ||
| 143 | [](const ProfileInfo& p) { return p.is_open; }); | ||
| 144 | } | ||
| 145 | |||
| 146 | /// Checks if a user id exists in our profile manager | ||
| 147 | bool ProfileManager::UserExists(UUID uuid) const { | ||
| 148 | return (GetUserIndex(uuid) != boost::none); | ||
| 149 | } | ||
| 150 | |||
| 151 | /// Opens a specific user | ||
| 152 | void ProfileManager::OpenUser(UUID uuid) { | ||
| 153 | auto idx = GetUserIndex(uuid); | ||
| 154 | if (idx == boost::none) { | ||
| 155 | return; | ||
| 156 | } | ||
| 157 | profiles[idx.get()].is_open = true; | ||
| 158 | last_opened_user = uuid; | ||
| 159 | } | ||
| 160 | |||
| 161 | /// Closes a specific user | ||
| 162 | void ProfileManager::CloseUser(UUID uuid) { | ||
| 163 | auto idx = GetUserIndex(uuid); | ||
| 164 | if (idx == boost::none) { | ||
| 165 | return; | ||
| 166 | } | ||
| 167 | profiles[idx.get()].is_open = false; | ||
| 168 | } | ||
| 169 | |||
| 170 | /// Gets all valid user ids on the system | ||
| 171 | std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { | ||
| 172 | std::array<UUID, MAX_USERS> output; | ||
| 173 | std::transform(profiles.begin(), profiles.end(), output.begin(), | ||
| 174 | [](const ProfileInfo& p) { return p.user_uuid; }); | ||
| 175 | return output; | ||
| 176 | } | ||
| 177 | |||
| 178 | /// Get all the open users on the system and zero out the rest of the data. This is specifically | ||
| 179 | /// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out | ||
| 180 | std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const { | ||
| 181 | std::array<UUID, MAX_USERS> output; | ||
| 182 | std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) { | ||
| 183 | if (p.is_open) | ||
| 184 | return p.user_uuid; | ||
| 185 | return UUID{}; | ||
| 186 | }); | ||
| 187 | std::stable_partition(output.begin(), output.end(), [](const UUID& uuid) { return uuid; }); | ||
| 188 | return output; | ||
| 189 | } | ||
| 190 | |||
| 191 | /// Returns the last user which was opened | ||
| 192 | UUID ProfileManager::GetLastOpenedUser() const { | ||
| 193 | return last_opened_user; | ||
| 194 | } | ||
| 195 | |||
| 196 | /// Return the users profile base and the unknown arbitary data. | ||
| 197 | bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, | ||
| 198 | std::array<u8, MAX_DATA>& data) const { | ||
| 199 | if (GetProfileBase(index, profile)) { | ||
| 200 | std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA); | ||
| 201 | return true; | ||
| 202 | } | ||
| 203 | return false; | ||
| 204 | } | ||
| 205 | |||
| 206 | /// Return the users profile base and the unknown arbitary data. | ||
| 207 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | ||
| 208 | std::array<u8, MAX_DATA>& data) const { | ||
| 209 | auto idx = GetUserIndex(uuid); | ||
| 210 | return GetProfileBaseAndData(idx, profile, data); | ||
| 211 | } | ||
| 212 | |||
| 213 | /// Return the users profile base and the unknown arbitary data. | ||
| 214 | bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | ||
| 215 | std::array<u8, MAX_DATA>& data) const { | ||
| 216 | return GetProfileBaseAndData(user.user_uuid, profile, data); | ||
| 217 | } | ||
| 218 | |||
| 219 | /// Returns if the system is allowing user registrations or not | ||
| 220 | bool ProfileManager::CanSystemRegisterUser() const { | ||
| 221 | return false; // TODO(ogniK): Games shouldn't have | ||
| 222 | // access to user registration, when we | ||
| 223 | // emulate qlaunch. Update this to dynamically change. | ||
| 224 | } | ||
| 225 | |||
| 226 | }; // namespace Service::Account | ||
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h new file mode 100644 index 000000000..314bccbf9 --- /dev/null +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <random> | ||
| 9 | #include "boost/optional.hpp" | ||
| 10 | #include "common/common_types.h" | ||
| 11 | #include "common/swap.h" | ||
| 12 | #include "core/hle/result.h" | ||
| 13 | |||
| 14 | namespace Service::Account { | ||
| 15 | constexpr size_t MAX_USERS = 8; | ||
| 16 | constexpr size_t MAX_DATA = 128; | ||
| 17 | static const u128 INVALID_UUID = {0, 0}; | ||
| 18 | |||
| 19 | struct UUID { | ||
| 20 | // UUIDs which are 0 are considered invalid! | ||
| 21 | u128 uuid = INVALID_UUID; | ||
| 22 | UUID() = default; | ||
| 23 | explicit UUID(const u128& id) : uuid{id} {} | ||
| 24 | explicit UUID(const u64 lo, const u64 hi) { | ||
| 25 | uuid[0] = lo; | ||
| 26 | uuid[1] = hi; | ||
| 27 | }; | ||
| 28 | explicit operator bool() const { | ||
| 29 | return uuid[0] != INVALID_UUID[0] || uuid[1] != INVALID_UUID[1]; | ||
| 30 | } | ||
| 31 | |||
| 32 | bool operator==(const UUID& rhs) const { | ||
| 33 | return std::tie(uuid[0], uuid[1]) == std::tie(rhs.uuid[0], rhs.uuid[1]); | ||
| 34 | } | ||
| 35 | |||
| 36 | bool operator!=(const UUID& rhs) const { | ||
| 37 | return !operator==(rhs); | ||
| 38 | } | ||
| 39 | |||
| 40 | // TODO(ogniK): Properly generate uuids based on RFC-4122 | ||
| 41 | const UUID& Generate() { | ||
| 42 | std::random_device device; | ||
| 43 | std::mt19937 gen(device()); | ||
| 44 | std::uniform_int_distribution<uint64_t> distribution(1, | ||
| 45 | std::numeric_limits<uint64_t>::max()); | ||
| 46 | uuid[0] = distribution(gen); | ||
| 47 | uuid[1] = distribution(gen); | ||
| 48 | return *this; | ||
| 49 | } | ||
| 50 | |||
| 51 | // Set the UUID to {0,0} to be considered an invalid user | ||
| 52 | void Invalidate() { | ||
| 53 | uuid = INVALID_UUID; | ||
| 54 | } | ||
| 55 | std::string Format() const { | ||
| 56 | return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]); | ||
| 57 | } | ||
| 58 | }; | ||
| 59 | static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); | ||
| 60 | |||
| 61 | /// This holds general information about a users profile. This is where we store all the information | ||
| 62 | /// based on a specific user | ||
| 63 | struct ProfileInfo { | ||
| 64 | UUID user_uuid; | ||
| 65 | std::array<u8, 0x20> username; | ||
| 66 | u64 creation_time; | ||
| 67 | std::array<u8, MAX_DATA> data; // TODO(ognik): Work out what this is | ||
| 68 | bool is_open; | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct ProfileBase { | ||
| 72 | UUID user_uuid; | ||
| 73 | u64_le timestamp; | ||
| 74 | std::array<u8, 0x20> username; | ||
| 75 | |||
| 76 | // Zero out all the fields to make the profile slot considered "Empty" | ||
| 77 | void Invalidate() { | ||
| 78 | user_uuid.Invalidate(); | ||
| 79 | timestamp = 0; | ||
| 80 | username.fill(0); | ||
| 81 | } | ||
| 82 | }; | ||
| 83 | static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size"); | ||
| 84 | |||
| 85 | /// The profile manager is used for handling multiple user profiles at once. It keeps track of open | ||
| 86 | /// users, all the accounts registered on the "system" as well as fetching individual "ProfileInfo" | ||
| 87 | /// objects | ||
| 88 | class ProfileManager { | ||
| 89 | public: | ||
| 90 | ProfileManager(); // TODO(ogniK): Load from system save | ||
| 91 | ResultCode AddUser(ProfileInfo user); | ||
| 92 | ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username); | ||
| 93 | ResultCode CreateNewUser(UUID uuid, const std::string& username); | ||
| 94 | boost::optional<size_t> GetUserIndex(const UUID& uuid) const; | ||
| 95 | boost::optional<size_t> GetUserIndex(ProfileInfo user) const; | ||
| 96 | bool GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const; | ||
| 97 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; | ||
| 98 | bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const; | ||
| 99 | bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, | ||
| 100 | std::array<u8, MAX_DATA>& data) const; | ||
| 101 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | ||
| 102 | std::array<u8, MAX_DATA>& data) const; | ||
| 103 | bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | ||
| 104 | std::array<u8, MAX_DATA>& data) const; | ||
| 105 | size_t GetUserCount() const; | ||
| 106 | size_t GetOpenUserCount() const; | ||
| 107 | bool UserExists(UUID uuid) const; | ||
| 108 | void OpenUser(UUID uuid); | ||
| 109 | void CloseUser(UUID uuid); | ||
| 110 | std::array<UUID, MAX_USERS> GetOpenUsers() const; | ||
| 111 | std::array<UUID, MAX_USERS> GetAllUsers() const; | ||
| 112 | UUID GetLastOpenedUser() const; | ||
| 113 | |||
| 114 | bool CanSystemRegisterUser() const; | ||
| 115 | |||
| 116 | private: | ||
| 117 | std::array<ProfileInfo, MAX_USERS> profiles{}; | ||
| 118 | size_t user_count = 0; | ||
| 119 | boost::optional<size_t> AddToProfiles(const ProfileInfo& profile); | ||
| 120 | bool RemoveProfileAtIndex(size_t index); | ||
| 121 | UUID last_opened_user{0, 0}; | ||
| 122 | }; | ||
| 123 | |||
| 124 | }; // namespace Service::Account | ||