/ src / Ryujinx.Horizon / Friends / FriendsServerManager.cs
FriendsServerManager.cs
 1  using Ryujinx.Horizon.Common;
 2  using Ryujinx.Horizon.Sdk.Account;
 3  using Ryujinx.Horizon.Sdk.Friends.Detail.Ipc;
 4  using Ryujinx.Horizon.Sdk.Sf.Hipc;
 5  using Ryujinx.Horizon.Sdk.Sm;
 6  using System;
 7  
 8  namespace Ryujinx.Horizon.Friends
 9  {
10      class FriendsServerManager : ServerManager
11      {
12          private readonly IEmulatorAccountManager _accountManager;
13          private readonly NotificationEventHandler _notificationEventHandler;
14  
15          public FriendsServerManager(HeapAllocator allocator, SmApi sm, int maxPorts, ManagerOptions options, int maxSessions) : base(allocator, sm, maxPorts, options, maxSessions)
16          {
17              _accountManager = HorizonStatic.Options.AccountManager;
18              _notificationEventHandler = new();
19          }
20  
21          protected override Result OnNeedsToAccept(int portIndex, Server server)
22          {
23              return (FriendsPortIndex)portIndex switch
24              {
25  #pragma warning disable IDE0055 // Disable formatting
26                  FriendsPortIndex.Admin   => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Admin)),
27                  FriendsPortIndex.User    => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.User)),
28                  FriendsPortIndex.Viewer  => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Viewer)),
29                  FriendsPortIndex.Manager => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.Manager)),
30                  FriendsPortIndex.System  => AcceptImpl(server, new ServiceCreator(_accountManager, _notificationEventHandler, FriendsServicePermissionLevel.System)),
31                  _                        => throw new ArgumentOutOfRangeException(nameof(portIndex)),
32  #pragma warning restore IDE0055
33              };
34          }
35      }
36  }