ManagerServer.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.Cpu;
  3. using Ryujinx.HLE.HOS.Kernel.Threading;
  4. using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
  8. {
  9. class ManagerServer
  10. {
  11. // TODO: Determine where and how NetworkServiceAccountId is set.
  12. private const long NetworkServiceAccountId = 0xcafe;
  13. private UserId _userId;
  14. public ManagerServer(UserId userId)
  15. {
  16. _userId = userId;
  17. }
  18. public ResultCode CheckAvailability(ServiceCtx context)
  19. {
  20. // 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".
  21. // Then it searches the Availability of Online Services related to the UserId in this file and returns it.
  22. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  23. // NOTE: Even if we try to return different error codes here, the guest still needs other calls.
  24. return ResultCode.Success;
  25. }
  26. public ResultCode GetAccountId(ServiceCtx context)
  27. {
  28. // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
  29. // as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
  30. // Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
  31. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
  32. context.ResponseData.Write(NetworkServiceAccountId);
  33. return ResultCode.Success;
  34. }
  35. public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context, out IAsyncContext asyncContext)
  36. {
  37. KEvent asyncEvent = new KEvent(context.Device.System.KernelContext);
  38. AsyncExecution asyncExecution = new AsyncExecution(asyncEvent);
  39. asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl);
  40. asyncContext = new IAsyncContext(asyncExecution);
  41. // return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
  42. return ResultCode.Success;
  43. }
  44. private async Task EnsureIdTokenCacheAsyncImpl(CancellationToken token)
  45. {
  46. // 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")
  47. // in the "account:/" savedata.
  48. // Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
  49. // 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.
  50. // Since we don't support online services, we can stub it.
  51. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  52. // TODO: Use a real function instead, with the CancellationToken.
  53. await Task.CompletedTask;
  54. }
  55. public ResultCode LoadIdTokenCache(ServiceCtx context)
  56. {
  57. ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
  58. ulong bufferSize = context.Request.ReceiveBuff[0].Size;
  59. // 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")
  60. // in the "account:/" savedata and writes some data in the buffer.
  61. // Since we don't support online services, we can stub it.
  62. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  63. /*
  64. if (internal_object != null)
  65. {
  66. if (bufferSize > 0xC00)
  67. {
  68. return ResultCode.InvalidIdTokenCacheBufferSize;
  69. }
  70. }
  71. */
  72. int idTokenCacheSize = 0;
  73. MemoryHelper.FillWithZeros(context.Memory, bufferPosition, (int)bufferSize);
  74. context.ResponseData.Write(idTokenCacheSize);
  75. return ResultCode.Success;
  76. }
  77. public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
  78. {
  79. Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
  80. context.ResponseData.Write(NetworkServiceAccountId);
  81. // TODO: determine and fill the output IPC buffer.
  82. return ResultCode.Success;
  83. }
  84. public ResultCode StoreOpenContext(ServiceCtx context)
  85. {
  86. Logger.Stub?.PrintStub(LogClass.ServiceAcc);
  87. return ResultCode.Success;
  88. }
  89. }
  90. }