IAccountService.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using Ryujinx.HLE.HOS.Ipc;
  2. using Ryujinx.HLE.HOS.SystemState;
  3. using Ryujinx.HLE.Logging;
  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> m_Commands;
  12. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  13. public IAccountService()
  14. {
  15. m_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. { 100, InitializeApplicationInfo },
  24. { 101, GetBaasAccountManagerForApplication }
  25. };
  26. }
  27. public long GetUserCount(ServiceCtx Context)
  28. {
  29. Context.ResponseData.Write(Context.Device.System.State.GetUserCount());
  30. return 0;
  31. }
  32. public long GetUserExistence(ServiceCtx Context)
  33. {
  34. UInt128 Uuid = new UInt128(
  35. Context.RequestData.ReadInt64(),
  36. Context.RequestData.ReadInt64());
  37. Context.ResponseData.Write(Context.Device.System.State.TryGetUser(Uuid, out _) ? 1 : 0);
  38. return 0;
  39. }
  40. public long ListAllUsers(ServiceCtx Context)
  41. {
  42. return WriteUserList(Context, Context.Device.System.State.GetAllUsers());
  43. }
  44. public long ListOpenUsers(ServiceCtx Context)
  45. {
  46. return WriteUserList(Context, Context.Device.System.State.GetOpenUsers());
  47. }
  48. private long WriteUserList(ServiceCtx Context, IEnumerable<UserProfile> Profiles)
  49. {
  50. long OutputPosition = Context.Request.RecvListBuff[0].Position;
  51. long OutputSize = Context.Request.RecvListBuff[0].Size;
  52. long Offset = 0;
  53. foreach (UserProfile Profile in Profiles)
  54. {
  55. if ((ulong)Offset + 16 > (ulong)OutputSize)
  56. {
  57. break;
  58. }
  59. Context.Memory.WriteInt64(OutputPosition, Profile.Uuid.High);
  60. Context.Memory.WriteInt64(OutputPosition + 8, Profile.Uuid.Low);
  61. }
  62. return 0;
  63. }
  64. public long GetLastOpenedUser(ServiceCtx Context)
  65. {
  66. UserProfile LastOpened = Context.Device.System.State.LastOpenUser;
  67. LastOpened.Uuid.Write(Context.ResponseData);
  68. return 0;
  69. }
  70. public long GetProfile(ServiceCtx Context)
  71. {
  72. UInt128 Uuid = new UInt128(
  73. Context.RequestData.ReadInt64(),
  74. Context.RequestData.ReadInt64());
  75. if (!Context.Device.System.State.TryGetUser(Uuid, out UserProfile Profile))
  76. {
  77. Context.Device.Log.PrintWarning(LogClass.ServiceAcc, $"User 0x{Uuid} not found!");
  78. return MakeError(ErrorModule.Account, AccErr.UserNotFound);
  79. }
  80. MakeObject(Context, new IProfile(Profile));
  81. return 0;
  82. }
  83. public long InitializeApplicationInfo(ServiceCtx Context)
  84. {
  85. Context.Device.Log.PrintStub(LogClass.ServiceAcc, "Stubbed.");
  86. return 0;
  87. }
  88. public long GetBaasAccountManagerForApplication(ServiceCtx Context)
  89. {
  90. MakeObject(Context, new IManagerForApplication());
  91. return 0;
  92. }
  93. }
  94. }