diff --git a/src/Ryujinx.Common/SharedConstants.cs b/src/Ryujinx.Common/SharedConstants.cs new file mode 100644 index 000000000..f40afeb2b --- /dev/null +++ b/src/Ryujinx.Common/SharedConstants.cs @@ -0,0 +1,9 @@ +namespace Ryujinx.Common +{ + public static class SharedConstants + { + public const string DefaultLanPlayHost = "ryuldn.vudjun.com"; + public const short LanPlayPort = 30456; + public const string DefaultLanPlayWebHost = "ryuldnweb.vudjun.com"; + } +} diff --git a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs index 5c6ee7732..9f7e6206b 100644 --- a/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs +++ b/src/Ryujinx.HLE/HOS/Services/Ldn/UserServiceCreator/IUserLocalCommunicationService.cs @@ -23,9 +23,6 @@ namespace Ryujinx.HLE.HOS.Services.Ldn.UserServiceCreator { class IUserLocalCommunicationService : IpcService, IDisposable { - public static string DefaultLanPlayHost = "ryuldn.vudjun.com"; - public static short LanPlayPort = 30456; - public INetworkClient NetworkClient { get; private set; } private const int NifmRequestID = 90; @@ -1092,20 +1089,18 @@ public ResultCode InitializeImpl(ServiceCtx context, ulong pid, int nifmRequestI case MultiplayerMode.LdnRyu: try { - string ldnServer = context.Device.Configuration.MultiplayerLdnServer; - if (string.IsNullOrEmpty(ldnServer)) - { - ldnServer = DefaultLanPlayHost; - } + string ldnServer = context.Device.Configuration.MultiplayerLdnServer + ?? throw new InvalidOperationException("Cannot initialize RyuLDN with a null Multiplayer server."); + if (!IPAddress.TryParse(ldnServer, out IPAddress ipAddress)) { ipAddress = Dns.GetHostEntry(ldnServer).AddressList[0]; } - NetworkClient = new LdnMasterProxyClient(ipAddress.ToString(), LanPlayPort, context.Device.Configuration); + NetworkClient = new LdnMasterProxyClient(ipAddress.ToString(), SharedConstants.LanPlayPort, context.Device.Configuration); } catch (Exception ex) { - Logger.Error?.Print(LogClass.ServiceLdn, "Could not locate LdnRyu server. Defaulting to stubbed wireless."); + Logger.Error?.Print(LogClass.ServiceLdn, "Could not locate RyuLDN server. Defaulting to stubbed wireless."); Logger.Error?.Print(LogClass.ServiceLdn, ex.Message); NetworkClient = new LdnDisabledClient(); } diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index b26921e6a..4147b8a5e 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -951,7 +951,7 @@ private void InitEmulatedSwitch() ConfigurationState.Instance.Multiplayer.Mode, ConfigurationState.Instance.Multiplayer.DisableP2p, ConfigurationState.Instance.Multiplayer.LdnPassphrase, - ConfigurationState.Instance.Multiplayer.LdnServer, + ConfigurationState.Instance.Multiplayer.GetLdnServer(), ConfigurationState.Instance.Graphics.CustomVSyncInterval.Value, ConfigurationState.Instance.Hacks.ShowDirtyHacks ? ConfigurationState.Instance.Hacks.EnabledHacks : null)); } diff --git a/src/Ryujinx/Assets/locales.json b/src/Ryujinx/Assets/locales.json index 6e2577182..a48e294b9 100644 --- a/src/Ryujinx/Assets/locales.json +++ b/src/Ryujinx/Assets/locales.json @@ -24073,4 +24073,4 @@ } } ] -} +} \ No newline at end of file diff --git a/src/Ryujinx/Utilities/AppLibrary/ApplicationLibrary.cs b/src/Ryujinx/Utilities/AppLibrary/ApplicationLibrary.cs index 79cac1a0e..260fabee5 100644 --- a/src/Ryujinx/Utilities/AppLibrary/ApplicationLibrary.cs +++ b/src/Ryujinx/Utilities/AppLibrary/ApplicationLibrary.cs @@ -42,7 +42,6 @@ namespace Ryujinx.Ava.Utilities.AppLibrary { public class ApplicationLibrary { - public const string DefaultLanPlayWebHost = "ryuldnweb.vudjun.com"; public Language DesiredLanguage { get; set; } public event EventHandler ApplicationCountUpdated; public event Action LdnGameDataReceived; @@ -826,7 +825,6 @@ public void LoadApplications(List appDirs) public async Task RefreshLdn() { - if (ConfigurationState.Instance.Multiplayer.Mode == MultiplayerMode.LdnRyu) { try @@ -834,33 +832,22 @@ public async Task RefreshLdn() string ldnWebHost = ConfigurationState.Instance.Multiplayer.LdnServer; if (string.IsNullOrEmpty(ldnWebHost)) { - ldnWebHost = DefaultLanPlayWebHost; + ldnWebHost = SharedConstants.DefaultLanPlayWebHost; } - IEnumerable ldnGameDataArray = Array.Empty(); + using HttpClient httpClient = new(); string ldnGameDataArrayString = await httpClient.GetStringAsync($"https://{ldnWebHost}/api/public_games"); - ldnGameDataArray = JsonHelper.Deserialize(ldnGameDataArrayString, _ldnDataSerializerContext.IEnumerableLdnGameData); - LdnGameDataReceived?.Invoke(new LdnGameDataReceivedEventArgs - { - LdnData = ldnGameDataArray - }); + LdnGameData[] ldnGameDataArray = JsonHelper.Deserialize(ldnGameDataArrayString, _ldnDataSerializerContext.IEnumerableLdnGameData).ToArray(); + LdnGameDataReceived?.Invoke(new LdnGameDataReceivedEventArgs(ldnGameDataArray)); + return; } catch (Exception ex) { Logger.Warning?.Print(LogClass.Application, $"Failed to fetch the public games JSON from the API. Player and game count in the game list will be unavailable.\n{ex.Message}"); - LdnGameDataReceived?.Invoke(new LdnGameDataReceivedEventArgs - { - LdnData = Array.Empty() - }); } } - else - { - LdnGameDataReceived?.Invoke(new LdnGameDataReceivedEventArgs - { - LdnData = Array.Empty() - }); - } + + LdnGameDataReceived?.Invoke(LdnGameDataReceivedEventArgs.Empty); } // Replace the currently stored DLC state for the game with the provided DLC state. diff --git a/src/Ryujinx/Utilities/AppLibrary/LdnGameDataReceivedEventArgs.cs b/src/Ryujinx/Utilities/AppLibrary/LdnGameDataReceivedEventArgs.cs index 97299c9e8..0eaa6ecb3 100644 --- a/src/Ryujinx/Utilities/AppLibrary/LdnGameDataReceivedEventArgs.cs +++ b/src/Ryujinx/Utilities/AppLibrary/LdnGameDataReceivedEventArgs.cs @@ -5,6 +5,14 @@ namespace Ryujinx.Ava.Utilities.AppLibrary { public class LdnGameDataReceivedEventArgs : EventArgs { - public IEnumerable LdnData { get; set; } + public static new readonly LdnGameDataReceivedEventArgs Empty = new(null); + + public LdnGameDataReceivedEventArgs(LdnGameData[] ldnData) + { + LdnData = ldnData ?? []; + } + + + public LdnGameData[] LdnData { get; set; } } } diff --git a/src/Ryujinx/Utilities/Configuration/ConfigurationState.Model.cs b/src/Ryujinx/Utilities/Configuration/ConfigurationState.Model.cs index 3f22c6c0f..ead99fbac 100644 --- a/src/Ryujinx/Utilities/Configuration/ConfigurationState.Model.cs +++ b/src/Ryujinx/Utilities/Configuration/ConfigurationState.Model.cs @@ -1,5 +1,6 @@ using ARMeilleure; using Gommon; +using Ryujinx.Ava.Utilities.AppLibrary; using Ryujinx.Ava.Utilities.Configuration.System; using Ryujinx.Ava.Utilities.Configuration.UI; using Ryujinx.Common; @@ -647,6 +648,14 @@ public class MultiplayerSection /// public ReactiveObject LdnServer { get; private set; } + public string GetLdnServer() + { + string ldnServer = LdnServer; + return string.IsNullOrEmpty(ldnServer) + ? SharedConstants.DefaultLanPlayHost + : ldnServer; + } + public MultiplayerSection() { LanInterfaceId = new ReactiveObject();