From f12e9bf3cd075cdd3efc10d43f48349754d9efd4 Mon Sep 17 00:00:00 2001 From: Shiroiame-Kusu Date: Mon, 12 Feb 2024 10:44:15 +0800 Subject: [PATCH] v0.12.0-A1: Fixed motd fetch. --- Serein/Universal/Base/Motd/Motdje.cs | 27 +++++++++++++++++++++++++-- Serein/Universal/Utils/Runtime.cs | 4 ++++ Serein/WPF/Serein-WPF.csproj | 2 +- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Serein/Universal/Base/Motd/Motdje.cs b/Serein/Universal/Base/Motd/Motdje.cs index 39c3874c..3b767378 100644 --- a/Serein/Universal/Base/Motd/Motdje.cs +++ b/Serein/Universal/Base/Motd/Motdje.cs @@ -7,6 +7,7 @@ using System.Net; using System.Net.Sockets; using System.Text; +using static Serein.Base.Motd.MotdjePacket; namespace Serein.Base.Motd { @@ -113,16 +114,38 @@ internal override void Get() Origin = Origin.Substring(Origin.IndexOf('{')); Logger.Output(LogType.Debug, $"Origin: {Origin}"); - MotdjePacket.Packet packet = JsonConvert.DeserializeObject(Origin) ?? throw new ArgumentNullException(); + //MotdjePacket.Packet packet = JsonConvert.DeserializeObject(Origin) ?? throw new ArgumentNullException(); JObject PacketData = JObject.Parse(Origin); PlayerListData = PacketData["players"]?.ToObject(); IsSuccessful = true; - OnlinePlayer = packet.Players.Online; + try + { + MotdjePacket.Packet packet = JsonConvert.DeserializeObject(Origin); + OnlinePlayer = packet.Players.Online; + MaxPlayer = packet.Players.Max; + Version = packet.Version.Name; + Protocol = packet.Version.Protocol.ToString(); + Description = packet.Description?.Text; + Favicon = packet.Favicon; + } + catch(Exception e) + { + Console.WriteLine(e.ToString()); + OnlinePlayer = (long)PacketData["players"]["online"]; + MaxPlayer = (long)PacketData["players"]["max"]; + Version = PacketData["version"]["name"].ToString(); + Protocol = PacketData["version"]["protocol"].ToString(); + Description = PacketData["description"].ToString(); + //Favicon = PacketData.Favicon; + } + + /*OnlinePlayer = packet.Players.Online; MaxPlayer = packet.Players.Max; Version = packet.Version.Name; Protocol = packet.Version.Protocol.ToString(); Description = packet.Description?.Text; Favicon = packet.Favicon; + */ } else { diff --git a/Serein/Universal/Utils/Runtime.cs b/Serein/Universal/Utils/Runtime.cs index 0a4441ca..810a8277 100644 --- a/Serein/Universal/Utils/Runtime.cs +++ b/Serein/Universal/Utils/Runtime.cs @@ -7,6 +7,8 @@ using System.IO; using System.Text; using System.Threading.Tasks; +using System.Threading; + #if !CONSOLE using Ookii.Dialogs.Wpf; @@ -28,6 +30,8 @@ public static void Init() { CrashInterception.Init(); Debug.WriteLine(Global.LOGO); + ProcessThreadCollection threadCollection = Process.GetCurrentProcess().Threads; + Directory.SetCurrentDirectory(Global.PATH); IO.ReadAll(); Task.Run(SystemInfo.Init); diff --git a/Serein/WPF/Serein-WPF.csproj b/Serein/WPF/Serein-WPF.csproj index 4bfd583d..4def6a2f 100644 --- a/Serein/WPF/Serein-WPF.csproj +++ b/Serein/WPF/Serein-WPF.csproj @@ -1,7 +1,7 @@ - WinExe + Exe net6.0-windows true false