From 30c03900b13c736cf0c03a9e8d846534a06deea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=82=A0=E9=9D=99=E8=90=9D=E8=8E=89?= Date: Mon, 30 Aug 2021 16:04:20 +0800 Subject: [PATCH] Update (#27) * Package Update to v1.4.1-Beta * Package Update to v1.5.0-Beta --- AuroraNative/AuroraNative.csproj | 6 +++--- AuroraNative/AuroraNative.xml | 15 +++++++++++++++ AuroraNative/Utils/Event.cs | 18 +++++++++++++----- AuroraNative/WebSockets/Client.cs | 8 ++++++++ AuroraNative/WebSockets/Server.cs | 12 ++++++++++-- AuroraNative/WebSockets/WebSocket.cs | 4 ++++ README.md | 4 ++-- 7 files changed, 55 insertions(+), 12 deletions(-) diff --git a/AuroraNative/AuroraNative.csproj b/AuroraNative/AuroraNative.csproj index bca1453..1148c5a 100644 --- a/AuroraNative/AuroraNative.csproj +++ b/AuroraNative/AuroraNative.csproj @@ -15,13 +15,13 @@ false false true - 1.4.1.0715 - 1.4.1.0715 + 1.5.0.0830 + 1.5.0.0830 Icon.png false AuroraNative AuroraNative - 1.4.1-Beta + 1.5.0-Beta true true diff --git a/AuroraNative/AuroraNative.xml b/AuroraNative/AuroraNative.xml index ef21441..6f87b40 100644 --- a/AuroraNative/AuroraNative.xml +++ b/AuroraNative/AuroraNative.xml @@ -2564,6 +2564,11 @@ 创建并连接到WebSocket服务器 + + + 创建并连接到WebSocket服务器 + + 立刻中断并释放连接注意!断开后需要重新Create @@ -2586,6 +2591,11 @@ 重写后的事件类实例 + + + 创建WebSocket服务器并监听端口 + + 创建WebSocket服务器并监听端口 @@ -2606,6 +2616,11 @@ 客户端创建 抽象方法 + + + 服务端创建 抽象方法 + + 客户端销毁 抽象方法 diff --git a/AuroraNative/Utils/Event.cs b/AuroraNative/Utils/Event.cs index 6396a96..2a1359c 100644 --- a/AuroraNative/Utils/Event.cs +++ b/AuroraNative/Utils/Event.cs @@ -4,6 +4,7 @@ using AuroraNative.WebSockets; using Newtonsoft.Json.Linq; using System; +using System.Collections.Generic; namespace AuroraNative { @@ -242,13 +243,20 @@ public void RouterNotify(JObject Json) internal static async void CheckVersion() { Logger.Debug("开始检查 go-cqhttp 版本是否符合最低版本..."); - if ((await API.CurrentApi.GetVersionInfo()).TryGetValue("AppVersion", out object Version) && new Version(Version.ToString().Substring(1, Version.ToString().IndexOf('-') - 1)) < WebSocket.DependencyVersion) + Dictionary Versions = (await API.CurrentApi.GetVersionInfo()); + if (Versions["AppVersion"].ToString().Contains("devel")) { - Logger.Warning($"框架最低依赖版本与 go-cqhttp 不符!请检查是否为最新的框架或符合的 go-cqhttp\ngo-cqhttp版本:{Version}\n框架最低依赖版本:v{WebSocket.DependencyVersion}"); + Logger.Debug("go-cqhttp 版本为开发版,跳过检测"); } - else - { - Logger.Debug("go-cqhttp 版本符合最低版本!"); + else { + if (Versions.TryGetValue("AppVersion", out object Version) && new Version(Version.ToString().Substring(1, Version.ToString().IndexOf('-') - 1)) < WebSocket.DependencyVersion) + { + Logger.Warning($"框架最低依赖版本与 go-cqhttp 不符!请检查是否为最新的框架或符合的 go-cqhttp\ngo-cqhttp版本:{Version}\n框架最低依赖版本:v{WebSocket.DependencyVersion}"); + } + else + { + Logger.Debug("go-cqhttp 版本符合最低版本!"); + } } WebSocket.IsCheckVersion = true; } diff --git a/AuroraNative/WebSockets/Client.cs b/AuroraNative/WebSockets/Client.cs index 0f41369..40c20bc 100644 --- a/AuroraNative/WebSockets/Client.cs +++ b/AuroraNative/WebSockets/Client.cs @@ -102,6 +102,14 @@ public override void Create() Logger.Error("连接到 go-cqhttp 服务器失败!请检查IP是否正确(需要携带端口号)或确认服务器是否启动和初始化完毕!", $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}"); } + /// + /// 创建并连接到WebSocket服务器 + /// + public override void Create(string Host = "") + { + Create(); + } + /// /// 立刻中断并释放连接注意!断开后需要重新Create /// diff --git a/AuroraNative/WebSockets/Server.cs b/AuroraNative/WebSockets/Server.cs index 3d758cd..61d5769 100644 --- a/AuroraNative/WebSockets/Server.cs +++ b/AuroraNative/WebSockets/Server.cs @@ -44,13 +44,13 @@ public int port /// /// 创建WebSocket服务器并监听端口 /// - public override void Create() + public override void Create(string Host = "localhost") { try { Logger.Debug("反向WebSocket已创建,准备监听...", $"{MethodBase.GetCurrentMethod().DeclaringType.Name}.{MethodBase.GetCurrentMethod().Name}"); Listener = new HttpListener(); - Listener.Prefixes.Add("http://*:" + Port.ToString() + "/"); + Listener.Prefixes.Add("http://" + Host + ":" + Port.ToString() + "/"); Listener.Start(); Logger.Info("开始监听来自 go-cqhttp 客户端的连接..."); Task.Run(Feedback); @@ -67,6 +67,14 @@ public override void Create() } } + /// + /// 创建WebSocket服务器并监听端口 + /// + public override void Create() + { + Create(); + } + /// /// 立刻中断并释放连接注意!断开后需要重新Create /// diff --git a/AuroraNative/WebSockets/WebSocket.cs b/AuroraNative/WebSockets/WebSocket.cs index bdbd6a0..a0bfdda 100644 --- a/AuroraNative/WebSockets/WebSocket.cs +++ b/AuroraNative/WebSockets/WebSocket.cs @@ -35,6 +35,10 @@ public abstract class WebSocket /// public abstract void Create(); /// + /// 服务端创建 抽象方法 + /// + public abstract void Create(string Host = "localhost"); + /// /// 客户端销毁 抽象方法 /// public abstract void Dispose(); diff --git a/README.md b/README.md index 5e3a272..2b8693e 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ - + @@ -76,7 +76,7 @@ 感谢以下大佬对本框架开发的帮助 -[Jie2GG](https://github.com/Jie2GG) | [Yukari316](https://github.com/Yukari316) | [bleatingsheep](https://github.com/b11p) +[Jie2GG](https://github.com/Jie2GG) | [bleatingsheep](https://github.com/b11p) ### 使用到的开源库