2021-01-02 14:34:28 -08:00
using Ryujinx.Common.Logging ;
2020-08-18 12:24:54 -07:00
using Ryujinx.Cpu ;
using Ryujinx.HLE.HOS.Kernel.Threading ;
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext ;
using System.Threading ;
using System.Threading.Tasks ;
2018-02-09 16:14:55 -08:00
2021-01-02 14:34:28 -08:00
namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
2018-02-09 16:14:55 -08:00
{
2021-01-02 14:34:28 -08:00
class ManagerServer
2018-02-09 16:14:55 -08:00
{
2020-08-18 12:24:54 -07:00
// TODO: Determine where and how NetworkServiceAccountId is set.
private const long NetworkServiceAccountId = 0xcafe ;
2021-01-02 14:34:28 -08:00
private UserId _userId ;
2018-10-13 16:16:02 -07:00
2021-01-02 14:34:28 -08:00
public ManagerServer ( UserId userId )
2018-02-09 16:14:55 -08:00
{
2021-01-02 14:34:28 -08:00
_userId = userId ;
2018-02-09 16:14:55 -08:00
}
2019-07-14 12:04:38 -07:00
public ResultCode CheckAvailability ( ServiceCtx context )
2018-04-16 17:24:42 -07:00
{
2020-08-18 12:24:54 -07:00
// NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x".
// Then it searches the Availability of Online Services related to the UserId in this file and returns it.
2020-08-03 16:32:53 -07:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
2018-04-16 17:24:42 -07:00
2020-08-18 12:24:54 -07:00
// NOTE: Even if we try to return different error codes here, the guest still needs other calls.
2019-07-14 12:04:38 -07:00
return ResultCode . Success ;
2018-02-09 16:14:55 -08:00
}
2019-07-14 12:04:38 -07:00
public ResultCode GetAccountId ( ServiceCtx context )
2018-02-09 16:14:55 -08:00
{
2020-12-11 19:06:20 -08:00
// NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
2020-08-18 12:24:54 -07:00
// as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
// Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
2020-08-03 16:32:53 -07:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { NetworkServiceAccountId } ) ;
2020-03-02 06:07:27 -08:00
context . ResponseData . Write ( NetworkServiceAccountId ) ;
return ResultCode . Success ;
}
2021-01-02 14:34:28 -08:00
public ResultCode EnsureIdTokenCacheAsync ( ServiceCtx context , out IAsyncContext asyncContext )
2020-08-18 12:24:54 -07:00
{
KEvent asyncEvent = new KEvent ( context . Device . System . KernelContext ) ;
AsyncExecution asyncExecution = new AsyncExecution ( asyncEvent ) ;
asyncExecution . Initialize ( 1000 , EnsureIdTokenCacheAsyncImpl ) ;
2021-01-02 14:34:28 -08:00
asyncContext = new IAsyncContext ( asyncExecution ) ;
2020-08-18 12:24:54 -07:00
// return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
return ResultCode . Success ;
}
private async Task EnsureIdTokenCacheAsyncImpl ( CancellationToken token )
{
// NOTE: This open the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
// in the "account:/" savedata.
// Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
// in "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the "account:/" savedata.
// Since we don't support online services, we can stub it.
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
// TODO: Use a real function instead, with the CancellationToken.
await Task . CompletedTask ;
}
public ResultCode LoadIdTokenCache ( ServiceCtx context )
{
2021-04-24 03:16:01 -07:00
ulong bufferPosition = context . Request . ReceiveBuff [ 0 ] . Position ;
ulong bufferSize = context . Request . ReceiveBuff [ 0 ] . Size ;
2020-08-18 12:24:54 -07:00
// NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
// in the "account:/" savedata and writes some data in the buffer.
// Since we don't support online services, we can stub it.
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
/ *
if ( internal_object ! = null )
{
if ( bufferSize > 0xC00 )
{
return ResultCode . InvalidIdTokenCacheBufferSize ;
}
}
* /
int idTokenCacheSize = 0 ;
MemoryHelper . FillWithZeros ( context . Memory , bufferPosition , ( int ) bufferSize ) ;
context . ResponseData . Write ( idTokenCacheSize ) ;
return ResultCode . Success ;
}
2020-03-02 06:07:27 -08:00
public ResultCode GetNintendoAccountUserResourceCacheForApplication ( ServiceCtx context )
{
2020-08-03 16:32:53 -07:00
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc , new { NetworkServiceAccountId } ) ;
2018-10-13 16:16:02 -07:00
2020-03-02 06:07:27 -08:00
context . ResponseData . Write ( NetworkServiceAccountId ) ;
2018-04-16 17:24:42 -07:00
2020-12-12 03:10:12 -08:00
// TODO: determine and fill the output IPC buffer.
2018-02-09 16:14:55 -08:00
2019-07-14 12:04:38 -07:00
return ResultCode . Success ;
2018-02-09 16:14:55 -08:00
}
2020-09-20 20:45:30 -07:00
public ResultCode StoreOpenContext ( ServiceCtx context )
{
Logger . Stub ? . PrintStub ( LogClass . ServiceAcc ) ;
return ResultCode . Success ;
}
2018-02-09 16:14:55 -08:00
}
}