IFriendService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using Ryujinx.Common;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.HLE.HOS.Ipc;
  4. using Ryujinx.HLE.HOS.SystemState;
  5. using Ryujinx.HLE.Utilities;
  6. using System.Collections.Generic;
  7. using System.IO;
  8. using System.Runtime.InteropServices;
  9. using static Ryujinx.HLE.HOS.ErrorCode;
  10. namespace Ryujinx.HLE.HOS.Services.Friend
  11. {
  12. class IFriendService : IpcService
  13. {
  14. private Dictionary<int, ServiceProcessRequest> _commands;
  15. private FriendServicePermissionLevel _permissionLevel;
  16. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
  17. public IFriendService(FriendServicePermissionLevel permissionLevel)
  18. {
  19. _commands = new Dictionary<int, ServiceProcessRequest>
  20. {
  21. //{ 0, GetCompletionEvent },
  22. //{ 1, Cancel },
  23. { 10100, GetFriendListIds },
  24. { 10101, GetFriendList },
  25. //{ 10102, UpdateFriendInfo },
  26. //{ 10110, GetFriendProfileImage },
  27. //{ 10200, SendFriendRequestForApplication },
  28. //{ 10211, AddFacedFriendRequestForApplication },
  29. //{ 10400, GetBlockedUserListIds },
  30. //{ 10500, GetProfileList },
  31. { 10600, DeclareOpenOnlinePlaySession },
  32. { 10601, DeclareCloseOnlinePlaySession },
  33. { 10610, UpdateUserPresence },
  34. //{ 10700, GetPlayHistoryRegistrationKey },
  35. //{ 10701, GetPlayHistoryRegistrationKeyWithNetworkServiceAccountId },
  36. //{ 10702, AddPlayHistory },
  37. //{ 11000, GetProfileImageUrl },
  38. //{ 20100, GetFriendCount },
  39. //{ 20101, GetNewlyFriendCount },
  40. //{ 20102, GetFriendDetailedInfo },
  41. //{ 20103, SyncFriendList },
  42. //{ 20104, RequestSyncFriendList },
  43. //{ 20110, LoadFriendSetting },
  44. //{ 20200, GetReceivedFriendRequestCount },
  45. //{ 20201, GetFriendRequestList },
  46. //{ 20300, GetFriendCandidateList },
  47. //{ 20301, GetNintendoNetworkIdInfo }, // 3.0.0+
  48. //{ 20302, GetSnsAccountLinkage }, // 5.0.0+
  49. //{ 20303, GetSnsAccountProfile }, // 5.0.0+
  50. //{ 20304, GetSnsAccountFriendList }, // 5.0.0+
  51. //{ 20400, GetBlockedUserList },
  52. //{ 20401, SyncBlockedUserList },
  53. //{ 20500, GetProfileExtraList },
  54. //{ 20501, GetRelationship },
  55. //{ 20600, GetUserPresenceView },
  56. //{ 20700, GetPlayHistoryList },
  57. //{ 20701, GetPlayHistoryStatistics },
  58. //{ 20800, LoadUserSetting },
  59. //{ 20801, SyncUserSetting },
  60. //{ 20900, RequestListSummaryOverlayNotification },
  61. //{ 21000, GetExternalApplicationCatalog },
  62. //{ 30100, DropFriendNewlyFlags },
  63. //{ 30101, DeleteFriend },
  64. //{ 30110, DropFriendNewlyFlag },
  65. //{ 30120, ChangeFriendFavoriteFlag },
  66. //{ 30121, ChangeFriendOnlineNotificationFlag },
  67. //{ 30200, SendFriendRequest },
  68. //{ 30201, SendFriendRequestWithApplicationInfo },
  69. //{ 30202, CancelFriendRequest },
  70. //{ 30203, AcceptFriendRequest },
  71. //{ 30204, RejectFriendRequest },
  72. //{ 30205, ReadFriendRequest },
  73. //{ 30210, GetFacedFriendRequestRegistrationKey },
  74. //{ 30211, AddFacedFriendRequest },
  75. //{ 30212, CancelFacedFriendRequest },
  76. //{ 30213, GetFacedFriendRequestProfileImage },
  77. //{ 30214, GetFacedFriendRequestProfileImageFromPath },
  78. //{ 30215, SendFriendRequestWithExternalApplicationCatalogId },
  79. //{ 30216, ResendFacedFriendRequest },
  80. //{ 30217, SendFriendRequestWithNintendoNetworkIdInfo }, // 3.0.0+
  81. //{ 30300, GetSnsAccountLinkPageUrl }, // 5.0.0+
  82. //{ 30301, UnlinkSnsAccount }, // 5.0.0+
  83. //{ 30400, BlockUser },
  84. //{ 30401, BlockUserWithApplicationInfo },
  85. //{ 30402, UnblockUser },
  86. //{ 30500, GetProfileExtraFromFriendCode },
  87. //{ 30700, DeletePlayHistory },
  88. //{ 30810, ChangePresencePermission },
  89. //{ 30811, ChangeFriendRequestReception },
  90. //{ 30812, ChangePlayLogPermission },
  91. //{ 30820, IssueFriendCode },
  92. //{ 30830, ClearPlayLog },
  93. //{ 49900, DeleteNetworkServiceAccountCache },
  94. };
  95. _permissionLevel = permissionLevel;
  96. }
  97. // nn::friends::GetFriendListIds(int offset, nn::account::Uid userUUID, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid) -> int outCount, array<nn::account::NetworkServiceAccountId, 0xa>
  98. public long GetFriendListIds(ServiceCtx context)
  99. {
  100. int offset = context.RequestData.ReadInt32();
  101. // Padding
  102. context.RequestData.ReadInt32();
  103. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  104. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  105. // Pid placeholder
  106. context.RequestData.ReadInt64();
  107. if (uuid.IsNull)
  108. {
  109. return MakeError(ErrorModule.Friends, FriendError.InvalidArgument);
  110. }
  111. // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
  112. context.ResponseData.Write(0);
  113. Logger.PrintStub(LogClass.ServiceFriend, new
  114. {
  115. UserId = uuid.ToString(),
  116. offset,
  117. filter.PresenceStatus,
  118. filter.IsFavoriteOnly,
  119. filter.IsSameAppPresenceOnly,
  120. filter.IsSameAppPlayedOnly,
  121. filter.IsArbitraryAppPlayedOnly,
  122. filter.PresenceGroupId,
  123. });
  124. return 0;
  125. }
  126. // nn::friends::GetFriendList(int offset, nn::account::Uid userUUID, nn::friends::detail::ipc::SizedFriendFilter friendFilter, ulong pidPlaceHolder, pid) -> int outCount, array<nn::friends::detail::FriendImpl, 0x6>
  127. public long GetFriendList(ServiceCtx context)
  128. {
  129. int offset = context.RequestData.ReadInt32();
  130. // Padding
  131. context.RequestData.ReadInt32();
  132. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  133. FriendFilter filter = context.RequestData.ReadStruct<FriendFilter>();
  134. // Pid placeholder
  135. context.RequestData.ReadInt64();
  136. if (uuid.IsNull)
  137. {
  138. return MakeError(ErrorModule.Friends, FriendError.InvalidArgument);
  139. }
  140. // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
  141. context.ResponseData.Write(0);
  142. Logger.PrintStub(LogClass.ServiceFriend, new {
  143. UserId = uuid.ToString(),
  144. offset,
  145. filter.PresenceStatus,
  146. filter.IsFavoriteOnly,
  147. filter.IsSameAppPresenceOnly,
  148. filter.IsSameAppPlayedOnly,
  149. filter.IsArbitraryAppPlayedOnly,
  150. filter.PresenceGroupId,
  151. });
  152. return 0;
  153. }
  154. // nn::friends::DeclareOpenOnlinePlaySession(nn::account::Uid)
  155. public long DeclareOpenOnlinePlaySession(ServiceCtx context)
  156. {
  157. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  158. if (uuid.IsNull)
  159. {
  160. return MakeError(ErrorModule.Friends, FriendError.InvalidArgument);
  161. }
  162. if (context.Device.System.State.Account.TryGetUser(uuid, out UserProfile profile))
  163. {
  164. profile.OnlinePlayState = AccountState.Open;
  165. }
  166. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), profile.OnlinePlayState });
  167. return 0;
  168. }
  169. // nn::friends::DeclareCloseOnlinePlaySession(nn::account::Uid)
  170. public long DeclareCloseOnlinePlaySession(ServiceCtx context)
  171. {
  172. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  173. if (uuid.IsNull)
  174. {
  175. return MakeError(ErrorModule.Friends, FriendError.InvalidArgument);
  176. }
  177. if (context.Device.System.State.Account.TryGetUser(uuid, out UserProfile profile))
  178. {
  179. profile.OnlinePlayState = AccountState.Closed;
  180. }
  181. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), profile.OnlinePlayState });
  182. return 0;
  183. }
  184. // nn::friends::UpdateUserPresence(nn::account::Uid, u64, pid, buffer<nn::friends::detail::UserPresenceImpl, 0x19>)
  185. public long UpdateUserPresence(ServiceCtx context)
  186. {
  187. UInt128 uuid = context.RequestData.ReadStruct<UInt128>();
  188. // Pid placeholder
  189. context.RequestData.ReadInt64();
  190. long position = context.Request.PtrBuff[0].Position;
  191. long size = context.Request.PtrBuff[0].Size;
  192. byte[] bufferContent = context.Memory.ReadBytes(position, size);
  193. if (uuid.IsNull)
  194. {
  195. return MakeError(ErrorModule.Friends, FriendError.InvalidArgument);
  196. }
  197. int elementCount = bufferContent.Length / Marshal.SizeOf<UserPresence>();
  198. using (BinaryReader bufferReader = new BinaryReader(new MemoryStream(bufferContent)))
  199. {
  200. UserPresence[] userPresenceInputArray = bufferReader.ReadStructArray<UserPresence>(elementCount);
  201. Logger.PrintStub(LogClass.ServiceFriend, new { UserId = uuid.ToString(), userPresenceInputArray });
  202. }
  203. return 0;
  204. }
  205. }
  206. }