friends update

This commit is contained in:
TurtleP 2021-04-02 13:26:25 -04:00
parent 1d7259295c
commit 17c4e2dfff
2 changed files with 81 additions and 2 deletions

View File

@ -11,6 +11,14 @@
#include "../services/acc.h" #include "../services/acc.h"
#include "../sf/service.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 /// InAppScreenName
typedef struct { typedef struct {
char name[0x40]; ///< UTF-8 string, NUL-terminated. char name[0x40]; ///< UTF-8 string, NUL-terminated.
@ -32,6 +40,33 @@ typedef struct {
u64 id; ///< Id. u64 id; ///< Id.
} FriendsFriendInvitationGroupId; } 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. * @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. * @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. * @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); Result friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buffer, u64 size, u64 *out_size);

View File

@ -1,6 +1,52 @@
#include "service_guard.h" #include "service_guard.h"
#include "services/friends.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 friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buffer, u64 size, u64 *out_size) {
Result rc=0; Result rc=0;
AppletStorage storage; AppletStorage storage;
@ -27,4 +73,3 @@ Result friendsTryPopFriendInvitationNotificationInfo(AccountUid *uid, void* buff
appletStorageClose(&storage); appletStorageClose(&storage);
return rc; return rc;
} }