diff --git a/osu.Desktop/LegacyIpc/LegacyTcpIpcProvider.cs b/osu.Desktop/LegacyIpc/LegacyTcpIpcProvider.cs index 4fb500fa9c..273e17d24b 100644 --- a/osu.Desktop/LegacyIpc/LegacyTcpIpcProvider.cs +++ b/osu.Desktop/LegacyIpc/LegacyTcpIpcProvider.cs @@ -2,9 +2,18 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Linq; using Newtonsoft.Json.Linq; using osu.Framework.Logging; using osu.Framework.Platform; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Legacy; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Catch; +using osu.Game.Rulesets.Mania; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Osu; +using osu.Game.Rulesets.Taiko; namespace osu.Desktop.LegacyIpc { @@ -33,7 +42,7 @@ namespace osu.Desktop.LegacyIpc var legacyData = ((JObject)msg.Value).ToObject(); object value = parseObject((JObject)legacyData!.MessageData, legacyData.MessageType); - object result = MessageReceived?.Invoke(value); + object result = onLegacyIpcMessageReceived(value); return result != null ? new LegacyIpcMessage { Value = result } : null; } catch (Exception ex) @@ -58,5 +67,39 @@ namespace osu.Desktop.LegacyIpc throw new ArgumentException($"Unknown type: {type}"); } } + + private object onLegacyIpcMessageReceived(object message) + { + switch (message) + { + case LegacyIpcDifficultyCalculationRequest req: + try + { + Ruleset ruleset = req.RulesetId switch + { + 0 => new OsuRuleset(), + 1 => new TaikoRuleset(), + 2 => new CatchRuleset(), + 3 => new ManiaRuleset(), + _ => throw new ArgumentException("Invalid ruleset id") + }; + + Mod[] mods = ruleset.ConvertFromLegacyMods((LegacyMods)req.Mods).ToArray(); + WorkingBeatmap beatmap = new FlatFileWorkingBeatmap(req.BeatmapFile, _ => ruleset); + + return new LegacyIpcDifficultyCalculationResponse + { + StarRating = ruleset.CreateDifficultyCalculator(beatmap).Calculate(mods).StarRating + }; + } + catch + { + return new LegacyIpcDifficultyCalculationResponse(); + } + } + + Console.WriteLine("Type not matched."); + return null; + } } } diff --git a/osu.Desktop/Program.cs b/osu.Desktop/Program.cs index 9542ccd8dc..a9e3575a49 100644 --- a/osu.Desktop/Program.cs +++ b/osu.Desktop/Program.cs @@ -3,7 +3,6 @@ using System; using System.IO; -using System.Linq; using System.Threading; using System.Threading.Tasks; using osu.Desktop.LegacyIpc; @@ -11,15 +10,7 @@ using osu.Framework; using osu.Framework.Development; using osu.Framework.Logging; using osu.Framework.Platform; -using osu.Game.Beatmaps; -using osu.Game.Beatmaps.Legacy; using osu.Game.IPC; -using osu.Game.Rulesets; -using osu.Game.Rulesets.Catch; -using osu.Game.Rulesets.Mania; -using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Osu; -using osu.Game.Rulesets.Taiko; using osu.Game.Tournament; namespace osu.Desktop @@ -98,7 +89,6 @@ namespace osu.Desktop { Logger.Log("Starting legacy IPC provider..."); legacyIpc = new LegacyTcpIpcProvider(); - legacyIpc.MessageReceived += onLegacyIpcMessageReceived; legacyIpc.Bind(); legacyIpc.StartAsync(); } @@ -132,39 +122,5 @@ namespace osu.Desktop return continueExecution; } - - private static object onLegacyIpcMessageReceived(object message) - { - switch (message) - { - case LegacyIpcDifficultyCalculationRequest req: - try - { - Ruleset ruleset = req.RulesetId switch - { - 0 => new OsuRuleset(), - 1 => new TaikoRuleset(), - 2 => new CatchRuleset(), - 3 => new ManiaRuleset(), - _ => throw new ArgumentException("Invalid ruleset id") - }; - - Mod[] mods = ruleset.ConvertFromLegacyMods((LegacyMods)req.Mods).ToArray(); - WorkingBeatmap beatmap = new FlatFileWorkingBeatmap(req.BeatmapFile, _ => ruleset); - - return new LegacyIpcDifficultyCalculationResponse - { - StarRating = ruleset.CreateDifficultyCalculator(beatmap).Calculate(mods).StarRating - }; - } - catch - { - return new LegacyIpcDifficultyCalculationResponse(); - } - } - - Console.WriteLine("Type not matched."); - return null; - } } }