IFriendService.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE.HOS.SystemState;
  4. using Ryujinx.HLE.Utilities;
  5. using System.IO;
  6. using System.Runtime.InteropServices;
  7. namespace Ryujinx.HLE.HOS.Services.Friend
  8. {
  9. class IFriendService : IpcService
  10. {
  11. private FriendServicePermissionLevel _permissionLevel;
  12. public IFriendService(FriendServicePermissionLevel permissionLevel)
  13. {
  14. _permissionLevel = permissionLevel;
  15. }
  16. [Command(10100)]
  17. // nn::friends::GetFriendListIds(int offset, nn::account::Uid userUUID, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid)
  18. // -> int outCount, array<nn::account::NetworkServiceAccountId, 0xa>
  19. public ResultCode GetFriendListIds(ServiceCtx context)
  20. {
  21. int offset = context.RequestData.ReadInt32();
  22. // Padding
  23. context.RequestData.ReadInt32();
  24. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  25. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  26. // Pid placeholder
  27. context.RequestData.ReadInt64();
  28. if (uuid.IsNull)
  29. {
  30. return ResultCode.InvalidArgument;
  31. }
  32. // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
  33. context.ResponseData.Write(0);
  34. Logger.PrintStub(LogClass.ServiceFriend, new
  35. {
  36. UserId = uuid.ToString(),
  37. offset,
  38. filter.PresenceStatus,
  39. filter.IsFavoriteOnly,
  40. filter.IsSameAppPresenceOnly,
  41. filter.IsSameAppPlayedOnly,
  42. filter.IsArbitraryAppPlayedOnly,
  43. filter.PresenceGroupId,
  44. });
  45. return ResultCode.Success;
  46. }
  47. [Command(10101)]
  48. // nn::friends::GetFriendList(int offset, nn::account::Uid userUUID, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid)
  49. // -> int outCount, array<nn::friends::detail::FriendImpl, 0x6>
  50. public ResultCode GetFriendList(ServiceCtx context)
  51. {
  52. int offset = context.RequestData.ReadInt32();
  53. // Padding
  54. context.RequestData.ReadInt32();
  55. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  56. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  57. // Pid placeholder
  58. context.RequestData.ReadInt64();
  59. if (uuid.IsNull)
  60. {
  61. return ResultCode.InvalidArgument;
  62. }
  63. // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
  64. context.ResponseData.Write(0);
  65. Logger.PrintStub(LogClass.ServiceFriend, new {
  66. UserId = uuid.ToString(),
  67. offset,
  68. filter.PresenceStatus,
  69. filter.IsFavoriteOnly,
  70. filter.IsSameAppPresenceOnly,
  71. filter.IsSameAppPlayedOnly,
  72. filter.IsArbitraryAppPlayedOnly,
  73. filter.PresenceGroupId,
  74. });
  75. return ResultCode.Success;
  76. }
  77. [Command(10600)]
  78. // nn::friends::DeclareOpenOnlinePlaySession(nn::account::Uid)
  79. public ResultCode DeclareOpenOnlinePlaySession(ServiceCtx context)
  80. {
  81. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  82. if (uuid.IsNull)
  83. {
  84. return ResultCode.InvalidArgument;
  85. }
  86. if (context.Device.System.State.Account.TryGetUser(uuid, out UserProfile profile))
  87. {
  88. profile.OnlinePlayState = AccountState.Open;
  89. }
  90. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), profile.OnlinePlayState });
  91. return ResultCode.Success;
  92. }
  93. [Command(10601)]
  94. // nn::friends::DeclareCloseOnlinePlaySession(nn::account::Uid)
  95. public ResultCode DeclareCloseOnlinePlaySession(ServiceCtx context)
  96. {
  97. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  98. if (uuid.IsNull)
  99. {
  100. return ResultCode.InvalidArgument;
  101. }
  102. if (context.Device.System.State.Account.TryGetUser(uuid, out UserProfile profile))
  103. {
  104. profile.OnlinePlayState = AccountState.Closed;
  105. }
  106. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), profile.OnlinePlayState });
  107. return ResultCode.Success;
  108. }
  109. [Command(10610)]
  110. // nn::friends::UpdateUserPresence(nn::account::Uid, u64, pid, buffer<nn::friends::detail::UserPresenceImpl, 0x19>)
  111. public ResultCode UpdateUserPresence(ServiceCtx context)
  112. {
  113. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  114. // Pid placeholder
  115. context.RequestData.ReadInt64();
  116. long position = context.Request.PtrBuff[0].Position;
  117. long size = context.Request.PtrBuff[0].Size;
  118. byte[] bufferContent = context.Memory.ReadBytes(position, size);
  119. if (uuid.IsNull)
  120. {
  121. return ResultCode.InvalidArgument;
  122. }
  123. int elementCount = bufferContent.Length / Marshal.SizeOf<UserPresence>();
  124. using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(bufferContent)))
  125. {
  126. UserPresence[] userPresenceInputArray = bufferReader.ReadStructArray<UserPresence>(elementCount);
  127. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), userPresenceInputArray });
  128. }
  129. return ResultCode.Success;
  130. }
  131. }
  132. }