Skip to content

Commit

Permalink
v0.12.0-A1: Fixed motd fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shiroiame-Kusu committed Feb 12, 2024
1 parent 31ef8fe commit f12e9bf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
27 changes: 25 additions & 2 deletions Serein/Universal/Base/Motd/Motdje.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using static Serein.Base.Motd.MotdjePacket;

namespace Serein.Base.Motd
{
Expand Down Expand Up @@ -113,16 +114,38 @@ internal override void Get()
Origin = Origin.Substring(Origin.IndexOf('{'));
Logger.Output(LogType.Debug, $"Origin: {Origin}");

MotdjePacket.Packet packet = JsonConvert.DeserializeObject<MotdjePacket.Packet>(Origin) ?? throw new ArgumentNullException();
//MotdjePacket.Packet packet = JsonConvert.DeserializeObject<MotdjePacket.Packet>(Origin) ?? throw new ArgumentNullException();
JObject PacketData = JObject.Parse(Origin);
PlayerListData = PacketData["players"]?.ToObject<JObject>();
IsSuccessful = true;
OnlinePlayer = packet.Players.Online;
try
{
MotdjePacket.Packet packet = JsonConvert.DeserializeObject<MotdjePacket.Packet>(Origin);

Check warning on line 123 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Converting null literal or possible null value to non-nullable type.

Check warning on line 123 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Converting null literal or possible null value to non-nullable type.

Check warning on line 123 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Converting null literal or possible null value to non-nullable type.
OnlinePlayer = packet.Players.Online;

Check warning on line 124 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 124 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.
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"];

Check warning on line 134 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 134 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Dereference of a possibly null reference.

Check warning on line 134 in Serein/Universal/Base/Motd/Motdje.cs

View workflow job for this annotation

GitHub Actions / BuildForWindows (WPF)

Possible null reference argument for parameter 'value' in 'JToken.explicit operator long(JToken value)'.
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
{
Expand Down
4 changes: 4 additions & 0 deletions Serein/Universal/Utils/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Threading;


#if !CONSOLE
using Ookii.Dialogs.Wpf;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Serein/WPF/Serein-WPF.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<TargetFrameworks>net6.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
Expand Down

0 comments on commit f12e9bf

Please sign in to comment.