2021-01-02 23:34:28 +01:00
|
|
|
|
using Ryujinx.Common;
|
|
|
|
|
using Ryujinx.Common.Logging;
|
|
|
|
|
using Ryujinx.Cpu;
|
2022-12-07 23:19:22 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Threading;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Account.Acc.AccountService;
|
2022-12-07 23:19:22 +01:00
|
|
|
|
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
using System.Collections.Generic;
|
2022-12-07 23:19:22 +01:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Account.Acc
|
|
|
|
|
{
|
|
|
|
|
class ApplicationServiceServer
|
|
|
|
|
{
|
|
|
|
|
readonly AccountServiceFlag _serviceFlag;
|
|
|
|
|
|
|
|
|
|
public ApplicationServiceServer(AccountServiceFlag serviceFlag)
|
|
|
|
|
{
|
|
|
|
|
_serviceFlag = serviceFlag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetUserCountImpl(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
context.ResponseData.Write(context.Device.System.AccountManager.GetUserCount());
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetUserExistenceImpl(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
ResultCode resultCode = CheckUserId(context, out UserId userId);
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 03:16:43 +02:00
|
|
|
|
context.ResponseData.Write(context.Device.System.AccountManager.TryGetUser(userId, out _));
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode ListAllUsers(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetAllUsers());
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode ListOpenUsers(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetOpenedUsers());
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ResultCode WriteUserList(ServiceCtx context, IEnumerable<UserProfile> profiles)
|
|
|
|
|
{
|
|
|
|
|
if (context.Request.RecvListBuff.Count == 0)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return ResultCode.InvalidBuffer;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong outputPosition = context.Request.RecvListBuff[0].Position;
|
|
|
|
|
ulong outputSize = context.Request.RecvListBuff[0].Size;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
MemoryHelper.FillWithZeros(context.Memory, outputPosition, (int)outputSize);
|
|
|
|
|
|
|
|
|
|
ulong offset = 0;
|
|
|
|
|
|
|
|
|
|
foreach (UserProfile userProfile in profiles)
|
|
|
|
|
{
|
2021-06-21 19:20:28 +02:00
|
|
|
|
if (offset + 0x10 > outputSize)
|
2021-01-02 23:34:28 +01:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
context.Memory.Write(outputPosition + offset, userProfile.UserId.High);
|
|
|
|
|
context.Memory.Write(outputPosition + offset + 8, userProfile.UserId.Low);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
offset += 0x10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetLastOpenedUser(ServiceCtx context)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
context.Device.System.AccountManager.LastOpenedUser.UserId.Write(context.ResponseData);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode GetProfile(ServiceCtx context, out IProfile profile)
|
|
|
|
|
{
|
|
|
|
|
profile = default;
|
|
|
|
|
|
|
|
|
|
ResultCode resultCode = CheckUserId(context, out UserId userId);
|
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 03:16:43 +02:00
|
|
|
|
if (!context.Device.System.AccountManager.TryGetUser(userId, out UserProfile userProfile))
|
2021-01-02 23:34:28 +01:00
|
|
|
|
{
|
|
|
|
|
Logger.Warning?.Print(LogClass.ServiceAcc, $"User 0x{userId} not found!");
|
|
|
|
|
|
|
|
|
|
return ResultCode.UserNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
profile = new IProfile(userProfile);
|
|
|
|
|
|
|
|
|
|
// Doesn't occur in our case.
|
|
|
|
|
// return ResultCode.NullObject;
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode IsUserRegistrationRequestPermitted(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
context.ResponseData.Write(_serviceFlag != AccountServiceFlag.Application);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode TrySelectUserWithoutInteraction(ServiceCtx context)
|
|
|
|
|
{
|
2021-06-21 19:20:28 +02:00
|
|
|
|
if (context.Device.System.AccountManager.GetUserCount() < 1)
|
2021-01-02 23:34:28 +01:00
|
|
|
|
{
|
|
|
|
|
// Invalid UserId.
|
|
|
|
|
UserId.Null.Write(context.ResponseData);
|
|
|
|
|
|
|
|
|
|
return ResultCode.UserNotFound;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool isNetworkServiceAccountRequired = context.RequestData.ReadBoolean();
|
|
|
|
|
|
|
|
|
|
if (isNetworkServiceAccountRequired)
|
|
|
|
|
{
|
|
|
|
|
// NOTE: This checks something related to baas (online), and then return an invalid UserId if the check in baas returns an error code.
|
|
|
|
|
// In our case, we can just log it for now.
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { isNetworkServiceAccountRequired });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NOTE: As we returned an invalid UserId if there is more than one user earlier, now we can return only the first one.
|
2021-04-13 03:16:43 +02:00
|
|
|
|
context.Device.System.AccountManager.GetFirst().UserId.Write(context.ResponseData);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-07 23:19:22 +01:00
|
|
|
|
public ResultCode CheckNetworkServiceAvailabilityAsync(ServiceCtx context, out IAsyncContext asyncContext)
|
|
|
|
|
{
|
|
|
|
|
KEvent asyncEvent = new(context.Device.System.KernelContext);
|
|
|
|
|
AsyncExecution asyncExecution = new(asyncEvent);
|
|
|
|
|
|
|
|
|
|
asyncExecution.Initialize(1000, CheckNetworkServiceAvailabilityAsyncImpl);
|
|
|
|
|
|
|
|
|
|
asyncContext = new IAsyncContext(asyncExecution);
|
|
|
|
|
|
|
|
|
|
// return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task CheckNetworkServiceAvailabilityAsyncImpl(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
|
|
|
|
|
|
// TODO: Use a real function instead, with the CancellationToken.
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 23:34:28 +01:00
|
|
|
|
public ResultCode StoreSaveDataThumbnail(ServiceCtx context)
|
|
|
|
|
{
|
2021-06-21 19:20:28 +02:00
|
|
|
|
ResultCode resultCode = CheckUserId(context, out UserId _);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (context.Request.SendBuff.Count == 0)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return ResultCode.InvalidBuffer;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
ulong inputPosition = context.Request.SendBuff[0].Position;
|
|
|
|
|
ulong inputSize = context.Request.SendBuff[0].Size;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
if (inputSize != 0x24000)
|
|
|
|
|
{
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return ResultCode.InvalidBufferSize;
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] thumbnailBuffer = new byte[inputSize];
|
|
|
|
|
|
2021-04-24 12:16:01 +02:00
|
|
|
|
context.Memory.Read(inputPosition, thumbnailBuffer);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
// NOTE: Account service call nn::fs::WriteSaveDataThumbnailFile().
|
|
|
|
|
// TODO: Store thumbnailBuffer somewhere, in save data 0x8000000000000010 ?
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode ClearSaveDataThumbnail(ServiceCtx context)
|
|
|
|
|
{
|
2021-06-21 19:20:28 +02:00
|
|
|
|
ResultCode resultCode = CheckUserId(context, out UserId _);
|
2021-01-02 23:34:28 +01:00
|
|
|
|
|
|
|
|
|
if (resultCode != ResultCode.Success)
|
|
|
|
|
{
|
|
|
|
|
return resultCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// NOTE: Doesn't occur in our case.
|
|
|
|
|
if (userId == null)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.InvalidArgument;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// NOTE: Account service call nn::fs::WriteSaveDataThumbnailFileHeader();
|
|
|
|
|
// TODO: Clear the Thumbnail somewhere, in save data 0x8000000000000010 ?
|
|
|
|
|
|
|
|
|
|
Logger.Stub?.PrintStub(LogClass.ServiceAcc);
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 02:24:52 +02:00
|
|
|
|
public ResultCode ListOpenContextStoredUsers(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetStoredOpenedUsers());
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 23:34:28 +01:00
|
|
|
|
public ResultCode ListQualifiedUsers(ServiceCtx context)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Determine how users are "qualified". We assume all users are "qualified" for now.
|
|
|
|
|
|
2021-04-13 03:16:43 +02:00
|
|
|
|
return WriteUserList(context, context.Device.System.AccountManager.GetAllUsers());
|
2021-01-02 23:34:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultCode CheckUserId(ServiceCtx context, out UserId userId)
|
|
|
|
|
{
|
|
|
|
|
userId = context.RequestData.ReadStruct<UserId>();
|
|
|
|
|
|
|
|
|
|
if (userId.IsNull)
|
|
|
|
|
{
|
|
|
|
|
return ResultCode.NullArgument;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ResultCode.Success;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|