IAccountServiceForApplication.cs 3.8 KB

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