aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Friend/IFriendService.cs
blob: e20de267ffc460fb44c96c9772e61ddac31a51bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Ipc;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.HLE.Utilities;
using System.Collections.Generic;

namespace Ryujinx.HLE.HOS.Services.Friend
{
    class IFriendService : IpcService
    {
        private Dictionary<int, ServiceProcessRequest> m_Commands;

        public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;

        public IFriendService()
        {
            m_Commands = new Dictionary<int, ServiceProcessRequest>()
            {
                { 10101, GetFriendList                 },
                { 10601, DeclareCloseOnlinePlaySession },
                { 10610, UpdateUserPresence            }
            };
        }

        // nn::friends::GetFriendListGetFriendListIds(nn::account::Uid, int Unknown0, nn::friends::detail::ipc::SizedFriendFilter, ulong Unknown1) -> int CounterIds,  array<nn::account::NetworkServiceAccountId>
        public long GetFriendList(ServiceCtx Context)
        {
            UInt128 Uuid = new UInt128(
                Context.RequestData.ReadInt64(),
                Context.RequestData.ReadInt64());

            int Unknown0 = Context.RequestData.ReadInt32();

            FriendFilter Filter = new FriendFilter()
            {
                PresenceStatus           = (PresenceStatusFilter)Context.RequestData.ReadInt32(),
                IsFavoriteOnly           = Context.RequestData.ReadBoolean(),
                IsSameAppPresenceOnly    = Context.RequestData.ReadBoolean(),
                IsSameAppPlayedOnly      = Context.RequestData.ReadBoolean(),
                IsArbitraryAppPlayedOnly = Context.RequestData.ReadBoolean(),
                PresenceGroupId          = Context.RequestData.ReadInt64()
            };

            long Unknown1 = Context.RequestData.ReadInt64();

            // There are no friends online, so we return 0 because the nn::account::NetworkServiceAccountId array is empty.
            Context.ResponseData.Write(0);

            Logger.PrintStub(LogClass.ServiceFriend, $"Stubbed. UserId: {Uuid.ToString()} - " +
                                                     $"Unknown0: {Unknown0} - " +
                                                     $"PresenceStatus: {Filter.PresenceStatus} - " +
                                                     $"IsFavoriteOnly: {Filter.IsFavoriteOnly} - " +
                                                     $"IsSameAppPresenceOnly: {Filter.IsSameAppPresenceOnly} - " +
                                                     $"IsSameAppPlayedOnly: {Filter.IsSameAppPlayedOnly} - " +
                                                     $"IsArbitraryAppPlayedOnly: {Filter.IsArbitraryAppPlayedOnly} - " +
                                                     $"PresenceGroupId: {Filter.PresenceGroupId} - " +
                                                     $"Unknown1: {Unknown1}");

            return 0;
        }

        // DeclareCloseOnlinePlaySession(nn::account::Uid)
        public long DeclareCloseOnlinePlaySession(ServiceCtx Context)
        {
            UInt128 Uuid = new UInt128(
                Context.RequestData.ReadInt64(),
                Context.RequestData.ReadInt64());

            if (Context.Device.System.State.TryGetUser(Uuid, out UserProfile Profile))
            {
                Profile.OnlinePlayState = OpenCloseState.Closed;
            }

            Logger.PrintStub(LogClass.ServiceFriend, $"Stubbed. Uuid: {Uuid.ToString()} - " +
                                                     $"OnlinePlayState: {Profile.OnlinePlayState}");

            return 0;
        }

        // UpdateUserPresence(nn::account::Uid, ulong Unknown0) -> buffer<Unknown1, type: 0x19, size: 0xe0>
        public long UpdateUserPresence(ServiceCtx Context)
        {
            UInt128 Uuid = new UInt128(
                Context.RequestData.ReadInt64(),
                Context.RequestData.ReadInt64());

            long Unknown0 = Context.RequestData.ReadInt64();

            long Position = Context.Request.PtrBuff[0].Position;
            long Size     = Context.Request.PtrBuff[0].Size;

            //Todo: Write the buffer content.

            Logger.PrintStub(LogClass.ServiceFriend, $"Stubbed. Uuid: {Uuid.ToString()} - " +
                                                     $"Unknown0: {Unknown0}");

            return 0;
        }
    }
}