mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 04:46:27 -05:00
Second round of account changes
This commit is contained in:
parent
82fa0bcea7
commit
dfea525cbe
3 changed files with 21 additions and 18 deletions
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "core/hle/service/acc/profile_manager.h"
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
#include "profile_manager.h"
|
|
||||||
|
|
||||||
namespace Service::Account {
|
namespace Service::Account {
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "core/hle/service/acc/profile_manager.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "profile_manager.h"
|
|
||||||
|
|
||||||
namespace Service::Account {
|
namespace Service::Account {
|
||||||
// TODO(ogniK): Get actual error codes
|
// TODO(ogniK): Get actual error codes
|
||||||
|
@ -28,10 +28,9 @@ size_t ProfileManager::AddToProfiles(const ProfileInfo& user) {
|
||||||
bool ProfileManager::RemoveProfileAtIdx(size_t index) {
|
bool ProfileManager::RemoveProfileAtIdx(size_t index) {
|
||||||
if (index >= MAX_USERS || index >= user_count)
|
if (index >= MAX_USERS || index >= user_count)
|
||||||
return false;
|
return false;
|
||||||
profiles[index] = ProfileInfo{};
|
|
||||||
if (index < user_count - 1)
|
if (index < user_count - 1)
|
||||||
for (size_t i = index; i < user_count - 1; i++)
|
std::rotate(profiles.begin() + index, profiles.begin() + index + 1, profiles.end());
|
||||||
profiles[i] = profiles[i + 1]; // Shift upper profiles down
|
profiles.back() = {};
|
||||||
user_count--;
|
user_count--;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -50,9 +49,10 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna
|
||||||
return ERROR_ARGUMENT_IS_NULL;
|
return ERROR_ARGUMENT_IS_NULL;
|
||||||
if (username[0] == 0x0)
|
if (username[0] == 0x0)
|
||||||
return ERROR_ARGUMENT_IS_NULL;
|
return ERROR_ARGUMENT_IS_NULL;
|
||||||
for (unsigned i = 0; i < user_count; i++)
|
if (std::any_of(profiles.begin(), profiles.end(),
|
||||||
if (uuid == profiles[i].user_uuid)
|
[&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) {
|
||||||
return ERROR_USER_ALREADY_EXISTS;
|
return ERROR_USER_ALREADY_EXISTS;
|
||||||
|
}
|
||||||
ProfileInfo prof_inf;
|
ProfileInfo prof_inf;
|
||||||
prof_inf.user_uuid = std::move(uuid);
|
prof_inf.user_uuid = std::move(uuid);
|
||||||
prof_inf.username = std::move(username);
|
prof_inf.username = std::move(username);
|
||||||
|
@ -62,7 +62,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna
|
||||||
return AddUser(prof_inf);
|
return AddUser(prof_inf);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) {
|
ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
|
||||||
std::array<u8, 0x20> username_output;
|
std::array<u8, 0x20> username_output;
|
||||||
if (username.size() > username_output.size())
|
if (username.size() > username_output.size())
|
||||||
std::copy_n(username.begin(), username_output.size(), username_output.begin());
|
std::copy_n(username.begin(), username_output.size(), username_output.begin());
|
||||||
|
@ -74,10 +74,13 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::string username) {
|
||||||
size_t ProfileManager::GetUserIndex(const UUID& uuid) const {
|
size_t ProfileManager::GetUserIndex(const UUID& uuid) const {
|
||||||
if (!uuid)
|
if (!uuid)
|
||||||
return std::numeric_limits<size_t>::max();
|
return std::numeric_limits<size_t>::max();
|
||||||
for (unsigned i = 0; i < user_count; i++)
|
|
||||||
if (profiles[i].user_uuid == uuid)
|
auto iter = std::find_if(profiles.begin(), profiles.end(),
|
||||||
return i;
|
[&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; });
|
||||||
return std::numeric_limits<size_t>::max();
|
if (iter == profiles.end()) {
|
||||||
|
return std::numeric_limits<size_t>::max();
|
||||||
|
}
|
||||||
|
return static_cast<size_t>(std::distance(profiles.begin(), iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ProfileManager::GetUserIndex(ProfileInfo user) const {
|
size_t ProfileManager::GetUserIndex(ProfileInfo user) const {
|
||||||
|
|
|
@ -12,10 +12,11 @@
|
||||||
namespace Service::Account {
|
namespace Service::Account {
|
||||||
constexpr size_t MAX_USERS = 8;
|
constexpr size_t MAX_USERS = 8;
|
||||||
constexpr size_t MAX_DATA = 128;
|
constexpr size_t MAX_DATA = 128;
|
||||||
|
static const u128 INVALID_UUID = {0, 0};
|
||||||
|
|
||||||
struct UUID {
|
struct UUID {
|
||||||
// UUIDs which are 0 are considered invalid!
|
// UUIDs which are 0 are considered invalid!
|
||||||
u128 uuid{0, 0};
|
u128 uuid = INVALID_UUID;
|
||||||
UUID() = default;
|
UUID() = default;
|
||||||
explicit UUID(const u128& id) : uuid{id} {}
|
explicit UUID(const u128& id) : uuid{id} {}
|
||||||
explicit UUID(const u64 lo, const u64 hi) {
|
explicit UUID(const u64 lo, const u64 hi) {
|
||||||
|
@ -23,7 +24,7 @@ struct UUID {
|
||||||
uuid[1] = hi;
|
uuid[1] = hi;
|
||||||
};
|
};
|
||||||
explicit operator bool() const {
|
explicit operator bool() const {
|
||||||
return uuid[0] != 0x0 || uuid[1] != 0x0;
|
return uuid[0] != INVALID_UUID[0] && uuid[1] != INVALID_UUID[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const UUID& rhs) const {
|
bool operator==(const UUID& rhs) const {
|
||||||
|
@ -41,8 +42,7 @@ struct UUID {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
void Invalidate() {
|
void Invalidate() {
|
||||||
uuid[0] = 0;
|
uuid = INVALID_UUID;
|
||||||
uuid[1] = 0;
|
|
||||||
}
|
}
|
||||||
std::string Format() const {
|
std::string Format() const {
|
||||||
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
|
return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
ProfileManager(); // TODO(ogniK): Load from system save
|
ProfileManager(); // TODO(ogniK): Load from system save
|
||||||
ResultCode AddUser(ProfileInfo user);
|
ResultCode AddUser(ProfileInfo user);
|
||||||
ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username);
|
ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username);
|
||||||
ResultCode CreateNewUser(UUID uuid, std::string username);
|
ResultCode CreateNewUser(UUID uuid, const std::string& username);
|
||||||
size_t GetUserIndex(const UUID& uuid) const;
|
size_t GetUserIndex(const UUID& uuid) const;
|
||||||
size_t GetUserIndex(ProfileInfo user) const;
|
size_t GetUserIndex(ProfileInfo user) const;
|
||||||
bool GetProfileBase(size_t index, ProfileBase& profile) const;
|
bool GetProfileBase(size_t index, ProfileBase& profile) const;
|
||||||
|
|
Loading…
Reference in a new issue