From 9748f3138a36d04a502432b62f3978515d79eb2f Mon Sep 17 00:00:00 2001 From: Mili Date: Fri, 25 Nov 2022 20:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E5=91=BD=E5=90=8D=E5=92=8C=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Core/Library/Constant/ConstantSet.cs | 8 +++--- .../Library/Exception/ExceptionHelper.cs | 11 ++------ FunGame.Core/Library/Exception/SystemError.cs | 4 +-- FunGame.Core/Service/ThreadManager.cs | 14 +++++----- FunGame.Desktop/Model/MainModel.cs | 16 +++++------ FunGame.Desktop/UI/Main/Main.cs | 28 +++++++++++-------- 6 files changed, 39 insertions(+), 42 deletions(-) diff --git a/FunGame.Core/Library/Constant/ConstantSet.cs b/FunGame.Core/Library/Constant/ConstantSet.cs index a29c289..57385ce 100644 --- a/FunGame.Core/Library/Constant/ConstantSet.cs +++ b/FunGame.Core/Library/Constant/ConstantSet.cs @@ -24,10 +24,10 @@ namespace Milimoe.FunGame.Core.Library.Constant public class SocketSet { - public static int MaxRetryTimes { get; } = 20; - public static int MaxConnection_1C2G { get; } = 10; - public static int MaxConnection_General { get; } = 20; - public static int MaxConnection_4C4G { get; } = 40; + public const int MaxRetryTimes = 20; + public const int MaxConnection_1C2G = 10; + public const int MaxConnection_General = 20; + public const int MaxConnection_4C4G = 40; public const string Unknown = "Unknown"; public const string Connect = "Connect"; diff --git a/FunGame.Core/Library/Exception/ExceptionHelper.cs b/FunGame.Core/Library/Exception/ExceptionHelper.cs index 7abb131..031b072 100644 --- a/FunGame.Core/Library/Exception/ExceptionHelper.cs +++ b/FunGame.Core/Library/Exception/ExceptionHelper.cs @@ -9,16 +9,9 @@ namespace Milimoe.FunGame.Core.Library.Exception { public static class ExceptionHelper { - public static string GetStackTrace(this System.Exception e) + public static string GetErrorInfo(this System.Exception e) { - if (e.Message != null && e.Message != "") - { - return $"ERROR: {e.Message}\n{e.StackTrace}"; - } - else - { - return $"ERROR: \n{e.StackTrace}"; - } + return (e.InnerException != null) ? $"InnerExceoption: {e.InnerException}\n{e}" : e.ToString(); } } } diff --git a/FunGame.Core/Library/Exception/SystemError.cs b/FunGame.Core/Library/Exception/SystemError.cs index ec7e5a4..6371ede 100644 --- a/FunGame.Core/Library/Exception/SystemError.cs +++ b/FunGame.Core/Library/Exception/SystemError.cs @@ -26,9 +26,9 @@ namespace Milimoe.FunGame.Core.Library.Exception e = new System.Exception(Name); } - public string GetStackTrace() + public string GetErrorInfo() { - return e.GetStackTrace(); + return e.GetErrorInfo(); } } } diff --git a/FunGame.Core/Service/ThreadManager.cs b/FunGame.Core/Service/ThreadManager.cs index aafdfa6..b0d4180 100644 --- a/FunGame.Core/Service/ThreadManager.cs +++ b/FunGame.Core/Service/ThreadManager.cs @@ -12,7 +12,7 @@ namespace Milimoe.FunGame.Core.Service /// /// 最大接受的线程数量 /// - private int MaxConnection { get; } + private int MaxTask { get; } /// /// 可参与高并发的字典,但添加效率较低 @@ -22,14 +22,14 @@ namespace Milimoe.FunGame.Core.Service /// /// Init ThreadManager /// - /// MaxConnection - internal ThreadManager(int MaxConnection = 0) + /// MaxTask + internal ThreadManager(int MaxTask = 0) { - if (MaxConnection <= 0) - this.MaxConnection = Library.Constant.General.MaxTask_General; + if (MaxTask <= 0) + this.MaxTask = Library.Constant.General.MaxTask_General; else { - this.MaxConnection = MaxConnection; + this.MaxTask = MaxTask; } } @@ -54,7 +54,7 @@ namespace Milimoe.FunGame.Core.Service /// True:操作成功 internal bool Add(string name, Task t) { - if (Threads.Count + 1 > MaxConnection) return false; + if (Threads.Count + 1 > MaxTask) return false; return Threads.TryAdd(name, t); } diff --git a/FunGame.Desktop/Model/MainModel.cs b/FunGame.Desktop/Model/MainModel.cs index c25764d..e90867e 100644 --- a/FunGame.Desktop/Model/MainModel.cs +++ b/FunGame.Desktop/Model/MainModel.cs @@ -38,7 +38,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main?.GetMessage(e.GetStackTrace()); + Main?.GetMessage(e.GetErrorInfo()); } return false; } @@ -51,7 +51,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main?.GetMessage(e.GetStackTrace()); + Main?.GetMessage(e.GetErrorInfo()); } return false; } @@ -64,7 +64,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main?.GetMessage(e.GetStackTrace()); + Main?.GetMessage(e.GetErrorInfo()); } } @@ -92,7 +92,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main?.GetMessage(e.GetStackTrace(), false); + Main?.GetMessage(e.GetErrorInfo(), false); } return false; @@ -160,7 +160,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main?.GetMessage(e.GetStackTrace(), false); + Main?.GetMessage(e.GetErrorInfo(), false); } return ConnectResult.ConnectFailed; @@ -183,7 +183,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - Main.GetMessage(e.GetStackTrace(), false); + Main.GetMessage(e.GetErrorInfo(), false); return false; } return true; @@ -259,7 +259,7 @@ namespace Milimoe.FunGame.Desktop.Model catch (Exception e) { // 报错中断服务器连接 - Main?.GetMessage(e.GetStackTrace(), false); + Main?.GetMessage(e.GetErrorInfo(), false); Main?.UpdateUI(MainControllerSet.Disconnected); Close(); } @@ -292,7 +292,7 @@ namespace Milimoe.FunGame.Desktop.Model // 返回的objs是该Login的User对象的各个属性 if (objs.Length > 0) msg = (string)objs[0]; Main?.GetMessage(msg); - Main?.UpdateUI(MainControllerSet.SetUser, true, TimeType.TimeOnly, new object[] { Factory.New(msg) }); + Main?.UpdateUI(MainControllerSet.SetUser, new object[] { Factory.New(msg) }); } private void SocketHandle_Disconnect(object[] objs) diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index df2fb9f..f96ccc7 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -90,7 +90,7 @@ namespace Milimoe.FunGame.Desktop.UI /// /// /// - public void UpdateUI(string? updatetype, bool time = true, TimeType timetype = TimeType.TimeOnly, object[]? objs = null) + public void UpdateUI(string? updatetype, object[]? objs = null) { void action() { @@ -164,16 +164,10 @@ namespace Milimoe.FunGame.Desktop.UI Thread.Sleep(5000); if (Others.Config.FunGame_isAutoRetry) MainController?.Do(MainControllerSet.Connect); // 再次判断是否开启自动重连 }); - if (time) - WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + "\n连接服务器失败,5秒后自动尝试重连。"); - else - WritelnGameInfo("连接服务器失败,5秒后自动尝试重连。"); + WritelnSystemInfo("连接服务器失败,5秒后自动尝试重连。"); } else - if (time) - WritelnGameInfo(DateTimeUtility.GetDateTimeToString(timetype) + "\n无法连接至服务器,请检查你的网络连接。"); - else - WritelnGameInfo("无法连接至服务器,请检查你的网络连接。"); + WritelnSystemInfo("无法连接至服务器,请检查你的网络连接。"); break; case Others.MainControllerSet.Disconnect: @@ -235,7 +229,7 @@ namespace Milimoe.FunGame.Desktop.UI } catch (Exception e) { - WritelnGameInfo(e.GetStackTrace()); + WritelnGameInfo(e.GetErrorInfo()); UpdateUI(Others.MainControllerSet.SetRed); } } @@ -260,7 +254,7 @@ namespace Milimoe.FunGame.Desktop.UI } catch (Exception e) { - WritelnGameInfo(e.GetStackTrace()); + WritelnGameInfo(e.GetErrorInfo()); } }; InvokeUpdateUI(action); @@ -307,7 +301,7 @@ namespace Milimoe.FunGame.Desktop.UI } catch (Exception e) { - WritelnGameInfo(e.GetStackTrace()); + WritelnGameInfo(e.GetErrorInfo()); } } @@ -377,6 +371,16 @@ namespace Milimoe.FunGame.Desktop.UI GameInfo.ScrollToCaret(); } } + + /// + /// 向消息队列输出一行系统信息 + /// + /// + private void WritelnSystemInfo(string msg) + { + msg = DateTimeUtility.GetDateTimeToString(TimeType.TimeOnly) + " >> " + msg; + WritelnGameInfo(msg); + } /// /// 在大厅中,设置按钮的显示和隐藏