IAccountService.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. using Ryujinx.Common.Logging;
  2. using Ryujinx.HLE.HOS.Ipc;
  3. using Ryujinx.HLE.HOS.SystemState;
  4. using Ryujinx.HLE.Utilities;
  5. using System.Collections.Generic;
  6. using static Ryujinx.HLE.HOS.ErrorCode;
  7. namespace Ryujinx.HLE.HOS.Services.Acc
  8. {
  9. class IAccountService : IpcService
  10. {
  11. private Dictionary<int, ServiceProcessRequest> _commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  13. public IAccountService()
  14. {
  15. _commands = new Dictionary<int, ServiceProcessRequest>
  16. {
  17. { 0, GetUserCount },
  18. { 1, GetUserExistence },
  19. { 2, ListAllUsers },
  20. { 3, ListOpenUsers },
  21. { 4, GetLastOpenedUser },
  22. { 5, GetProfile },
  23. { 50, IsUserRegistrationRequestPermitted },
  24. { 51, TrySelectUserWithoutInteraction },
  25. { 100, InitializeApplicationInfo },
  26. { 101, GetBaasAccountManagerForApplication }
  27. };
  28. }
  29. // GetUserCount() -> i32
  30. public long GetUserCount(ServiceCtx context)
  31. {
  32. context.ResponseData.Write(context.Device.System.State.GetUserCount());
  33. return 0;
  34. }
  35. // GetUserExistence(nn::account::Uid) -> bool
  36. public long GetUserExistence(ServiceCtx context)
  37. {
  38. UInt128 uuid = new UInt128(
  39. context.RequestData.ReadInt64(),
  40. context.RequestData.ReadInt64());
  41. context.ResponseData.Write(context.Device.System.State.TryGetUser(uuid, out _));
  42. return 0;
  43. }
  44. // ListAllUsers() -> array<nn::account::Uid, 0xa>
  45. public long ListAllUsers(ServiceCtx context)
  46. {
  47. return WriteUserList(context, context.Device.System.State.GetAllUsers());
  48. }
  49. // ListOpenUsers() -> array<nn::account::Uid, 0xa>
  50. public long ListOpenUsers(ServiceCtx context)
  51. {
  52. return WriteUserList(context, context.Device.System.State.GetOpenUsers());
  53. }
  54. private long WriteUserList(ServiceCtx context, IEnumerable<UserProfile> profiles)
  55. {
  56. long outputPosition = context.Request.RecvListBuff[0].Position;
  57. long outputSize = context.Request.RecvListBuff[0].Size;
  58. long offset = 0;
  59. foreach (UserProfile profile in profiles)
  60. {
  61. if ((ulong)offset + 16 > (ulong)outputSize)
  62. {
  63. break;
  64. }
  65. context.Memory.WriteInt64(outputPosition, profile.Uuid.Low);
  66. context.Memory.WriteInt64(outputPosition + 8, profile.Uuid.High);
  67. }
  68. return 0;
  69. }
  70. // GetLastOpenedUser() -> nn::account::Uid
  71. public long GetLastOpenedUser(ServiceCtx context)
  72. {
  73. UserProfile lastOpened = context.Device.System.State.LastOpenUser;
  74. lastOpened.Uuid.Write(context.ResponseData);
  75. return 0;
  76. }
  77. // GetProfile(nn::account::Uid) -> object<nn::account::profile::IProfile>
  78. public long GetProfile(ServiceCtx context)
  79. {
  80. UInt128 uuid = new UInt128(
  81. context.RequestData.ReadInt64(),
  82. context.RequestData.ReadInt64());
  83. if (!context.Device.System.State.TryGetUser(uuid, out UserProfile profile))
  84. {
  85. Logger.PrintWarning(LogClass.ServiceAcc, $"User 0x{uuid} not found!");
  86. return MakeError(ErrorModule.Account, AccErr.UserNotFound);
  87. }
  88. MakeObject(context, new IProfile(profile));
  89. return 0;
  90. }
  91. // IsUserRegistrationRequestPermitted(u64, pid) -> bool
  92. public long IsUserRegistrationRequestPermitted(ServiceCtx context)
  93. {
  94. long unknown = context.RequestData.ReadInt64();
  95. Logger.PrintStub(LogClass.ServiceAcc, new { unknown });
  96. context.ResponseData.Write(false);
  97. return 0;
  98. }
  99. // TrySelectUserWithoutInteraction(bool) -> nn::account::Uid
  100. public long TrySelectUserWithoutInteraction(ServiceCtx context)
  101. {
  102. bool unknown = context.RequestData.ReadBoolean();
  103. Logger.PrintStub(LogClass.ServiceAcc, new { unknown });
  104. UserProfile profile = context.Device.System.State.LastOpenUser;
  105. profile.Uuid.Write(context.ResponseData);
  106. return 0;
  107. }
  108. // InitializeApplicationInfo(u64, pid)
  109. public long InitializeApplicationInfo(ServiceCtx context)
  110. {
  111. long unknown = context.RequestData.ReadInt64();
  112. Logger.PrintStub(LogClass.ServiceAcc, new { unknown });
  113. return 0;
  114. }
  115. // GetBaasAccountManagerForApplication(nn::account::Uid) -> object<nn::account::baas::IManagerForApplication>
  116. public long GetBaasAccountManagerForApplication(ServiceCtx context)
  117. {
  118. UInt128 uuid = new UInt128(
  119. context.RequestData.ReadInt64(),
  120. context.RequestData.ReadInt64());
  121. MakeObject(context, new IManagerForApplication(uuid));
  122. return 0;
  123. }
  124. }
  125. }