IFriendService.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE.HOS.Services.Account.Acc;
  4. using Ryujinx.HLE.HOS.Services.Friend.ServiceCreator.FriendService;
  5. using System.IO;
  6. using System.Runtime.InteropServices;
  7. namespace Ryujinx.HLE.HOS.Services.Friend.ServiceCreator
  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 userId, 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. UserId userId = context.RequestData.ReadStruct<UserId>();
  25. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  26. // Pid placeholder
  27. context.RequestData.ReadInt64();
  28. if (userId.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 = userId.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 userId, 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. UserId userId = context.RequestData.ReadStruct<UserId>();
  56. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  57. // Pid placeholder
  58. context.RequestData.ReadInt64();
  59. if (userId.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 = userId.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(10400)]
  78. // nn::friends::GetBlockedUserListIds(int offset, nn::account::Uid userId) -> (u32, buffer<nn::account::NetworkServiceAccountId, 0xa>)
  79. public ResultCode GetBlockedUserListIds(ServiceCtx context)
  80. {
  81. int offset = context.RequestData.ReadInt32();
  82. // Padding
  83. context.RequestData.ReadInt32();
  84. UserId userId = context.RequestData.ReadStruct<UserId>();
  85. // There are no friends blocked, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
  86. context.ResponseData.Write(0);
  87. Logger.PrintStub(LogClass.ServiceFriend, new { offset, UserId = userId.ToString() });
  88. return ResultCode.Success;
  89. }
  90. [Command(10600)]
  91. // nn::friends::DeclareOpenOnlinePlaySession(nn::account::Uid userId)
  92. public ResultCode DeclareOpenOnlinePlaySession(ServiceCtx context)
  93. {
  94. UserId userId = context.RequestData.ReadStruct<UserId>();
  95. if (userId.IsNull)
  96. {
  97. return ResultCode.InvalidArgument;
  98. }
  99. if (context.Device.System.State.Account.TryGetUser(userId, out UserProfile profile))
  100. {
  101. profile.OnlinePlayState = AccountState.Open;
  102. }
  103. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString(), profile.OnlinePlayState });
  104. return ResultCode.Success;
  105. }
  106. [Command(10601)]
  107. // nn::friends::DeclareCloseOnlinePlaySession(nn::account::Uid userId)
  108. public ResultCode DeclareCloseOnlinePlaySession(ServiceCtx context)
  109. {
  110. UserId userId = context.RequestData.ReadStruct<UserId>();
  111. if (userId.IsNull)
  112. {
  113. return ResultCode.InvalidArgument;
  114. }
  115. if (context.Device.System.State.Account.TryGetUser(userId, out UserProfile profile))
  116. {
  117. profile.OnlinePlayState = AccountState.Closed;
  118. }
  119. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = userId.ToString(), profile.OnlinePlayState });
  120. return ResultCode.Success;
  121. }
  122. [Command(10610)]
  123. // nn::friends::UpdateUserPresence(nn::account::Uid, u64, pid, buffer<nn::friends::detail::UserPresenceImpl, 0x19>)
  124. public ResultCode UpdateUserPresence(ServiceCtx context)
  125. {
  126. UserId uuid = context.RequestData.ReadStruct<UserId>();
  127. // Pid placeholder
  128. context.RequestData.ReadInt64();
  129. long position = context.Request.PtrBuff[0].Position;
  130. long size = context.Request.PtrBuff[0].Size;
  131. byte[] bufferContent = new byte[size];
  132. context.Memory.Read((ulong)position, bufferContent);
  133. if (uuid.IsNull)
  134. {
  135. return ResultCode.InvalidArgument;
  136. }
  137. int elementCount = bufferContent.Length / Marshal.SizeOf<UserPresence>();
  138. using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(bufferContent)))
  139. {
  140. UserPresence[] userPresenceInputArray = bufferReader.ReadStructArray<UserPresence>(elementCount);
  141. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), userPresenceInputArray });
  142. }
  143. return ResultCode.Success;
  144. }
  145. }
  146. }