From ca07c4d9ff0d9077e79c62ecbb2459052d473685 Mon Sep 17 00:00:00 2001 From: milimoe Date: Thu, 26 Sep 2024 01:19:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=20WebSocket=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Main.cs | 14 +------------- Library/Tests/FunGame.cs | 17 +++++++++++++++++ Library/Tests/WebSocketTest.cs | 31 +++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 Library/Tests/WebSocketTest.cs diff --git a/Library/Main.cs b/Library/Main.cs index b0d34f7..5ceaadc 100644 --- a/Library/Main.cs +++ b/Library/Main.cs @@ -1,15 +1,3 @@ using Milimoe.FunGame.Testing.Tests; -FunGameSimulation.LoadModules(); - -bool printout = true; -List strs = FunGameSimulation.StartGame(printout); -if (printout == false) -{ - foreach (string str in strs) - { - Console.WriteLine(str); - } -} - -Console.ReadKey(); +_ = new WebSocketTest(); diff --git a/Library/Tests/FunGame.cs b/Library/Tests/FunGame.cs index 8e7d513..e1f73e8 100644 --- a/Library/Tests/FunGame.cs +++ b/Library/Tests/FunGame.cs @@ -10,6 +10,23 @@ namespace Milimoe.FunGame.Testing.Tests { public class FunGameSimulation { + public FunGameSimulation() + { + LoadModules(); + + bool printout = true; + List strs = StartGame(printout); + if (printout == false) + { + foreach (string str in strs) + { + Console.WriteLine(str); + } + } + + Console.ReadKey(); + } + public static List Characters { get; } = []; public static Dictionary CharacterStatistics { get; } = []; public static PluginConfig StatsConfig { get; } = new(nameof(FunGameSimulation), nameof(CharacterStatistics)); diff --git a/Library/Tests/WebSocketTest.cs b/Library/Tests/WebSocketTest.cs new file mode 100644 index 0000000..18072b5 --- /dev/null +++ b/Library/Tests/WebSocketTest.cs @@ -0,0 +1,31 @@ +using System.Collections; +using Milimoe.FunGame.Core.Api.Utility; +using Milimoe.FunGame.Core.Library.Common.Network; + +namespace Milimoe.FunGame.Testing.Tests +{ + public class WebSocketTest + { + public WebSocketTest() + { + TaskUtility.NewTask(async () => + { + HTTPClient client = await HTTPClient.Connect("localhost", 22223, false, "ws"); + ArrayList list = []; + list.Add(new string[] { "oshima.fungame.fastauto" }); + list.Add(false); + Console.WriteLine(NetworkUtility.JsonSerialize(new SocketObject(Core.Library.Constant.SocketMessageType.Connect, Guid.NewGuid(), list))); + await client.Send(Core.Library.Constant.SocketMessageType.Connect, list); + while (true) + { + await Task.Delay(1000); + await client.Send(Core.Library.Constant.SocketMessageType.HeartBeat); + } + }).OnError(Console.WriteLine); + while (true) + { + string str = Console.ReadLine() ?? ""; + } + } + } +}