diff --git a/nx/include/switch/services/friends.h b/nx/include/switch/services/friends.h index 36a9a2fd..b7f419da 100644 --- a/nx/include/switch/services/friends.h +++ b/nx/include/switch/services/friends.h @@ -11,6 +11,14 @@ #include "../services/acc.h" #include "../sf/service.h" +typedef enum { + FriendServiceType_User = 0, ///< Initializes friend:u + FriendServiceType_V = 1, ///< Initializes friend:v + FriendServiceType_M = 2, ///< Initializes friend:m + FriendServiceType_S = 3, ///< Initializes friend:s + FriendServiceType_Application = 4 ///< Initializes friend:a +} FriendServiceType; + /// InAppScreenName typedef struct { char name[0x40]; ///< UTF-8 string, NUL-terminated. @@ -32,6 +40,33 @@ typedef struct { u64 id; ///< Id. } FriendsFriendInvitationGroupId; +/// FriendsUserSetting +typedef struct { + AccountUid uid; + u32 presence_permission; + u32 play_log_permission; + u64 friend_request_reception; // maybe u32? + char friend_code[0x20]; + u64 friend_code_next_issuable_time; // or u64? I think sizeof(time_t) == 8 + char extra[0x7C8]; +} FriendUserSetting; + +/// Initialize friends +Result friendsInitialize(FriendServiceType service_type); + +/// Exit friends +void friendsExit(); + +/// Gets the Service object for the actual friends service session. +Service * friendsGetServiceSession(); + +/** + * @brief Gets the \ref FriendUserSetting details + * @param[in] uid \ref User AccountUid. + * @param[out] user_setting \ref FriendUserSetting + */ +Result friendsGetUserSetting(AccountUid uid, FriendUserSetting * user_setting); + /** * @brief Gets an Event which is signaled when data is available with \ref friendsTryPopFriendInvitationNotificationInfo. * @note This is a wrapper for \ref appletGetFriendInvitationStorageChannelEvent, see that for the usage requirements. @@ -51,4 +86,3 @@ NX_INLINE Result friendsGetFriendInvitationNotificationEvent(Event *out_event) { * @param[out] out_size Size of the data which was written into the output buffer. Optional, can be NULL. */ Result friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buffer, u64 size, u64 *out_size); - diff --git a/nx/source/services/friends.c b/nx/source/services/friends.c index 4195f203..c8bdc75b 100644 --- a/nx/source/services/friends.c +++ b/nx/source/services/friends.c @@ -1,6 +1,52 @@ #include "service_guard.h" #include "services/friends.h" +static FriendServiceType g_friendsServiceType; +static Service g_friendsSrv; + +NX_GENERATE_SERVICE_GUARD_PARAMS(friends, (FriendServiceType service_type), (service_type)); + +Result _friendsInitialize(FriendServiceType service_type) { + Result rc = MAKERESULT(Module_Libnx, LibnxError_BadInput); + + g_friendsServiceType = service_type; + + switch (g_friendsServiceType) { + case FriendServiceType_User: + rc = smGetService(&g_friendsSrv, "friend:u"); + break; + case FriendServiceType_Application: + rc = smGetService(&g_friendsSrv, "friend:a"); + break; + case FriendServiceType_M: + rc = smGetService(&g_friendsSrv, "friend:m"); + break; + case FriendServiceType_V: + rc = smGetService(&g_friendsSrv, "friend:v"); + break; + case FriendServiceType_S: + rc = smGetService(&g_friendsSrv, "friend:s"); + break; + } + + return rc; +} + +void _friendsCleanup(void) { + serviceClose(&g_friendsSrv); +} + +Service* friendsGetServiceSession(void) { + return &g_friendsSrv; +} + +Result friendsGetUserSetting(AccountUid uid, FriendUserSetting * user_setting) { + return serviceDispatchIn(&g_friendsSrv, 20800, uid, + .buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_Out | SfBufferAttr_FixedSize }, + .buffers = { { &(*user_setting), sizeof(FriendUserSetting) } } + ); +} + Result friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buffer, u64 size, u64 *out_size) { Result rc=0; AppletStorage storage; @@ -27,4 +73,3 @@ Result friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buff appletStorageClose(&storage); return rc; } -