From 618f9c93c948630f7771b564d4660ae5836d4b7d Mon Sep 17 00:00:00 2001 From: Mili Date: Mon, 6 Mar 2023 21:34:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG=E5=92=8C=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=94=B9=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Desktop/Controller/LoginController.cs | 2 +- FunGame.Desktop/Controller/MainController.cs | 8 ++++---- FunGame.Desktop/Controller/RegisterController.cs | 5 +++-- FunGame.Desktop/Library/Interface/ICallBack.cs | 9 +++++++++ FunGame.Desktop/Model/MainModel.cs | 2 +- FunGame.Desktop/Model/RegisterModel.cs | 7 ++++--- FunGame.Desktop/UI/Login/Login.cs | 2 +- FunGame.Desktop/UI/Register/Register.cs | 6 +++--- 8 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 FunGame.Desktop/Library/Interface/ICallBack.cs diff --git a/FunGame.Desktop/Controller/LoginController.cs b/FunGame.Desktop/Controller/LoginController.cs index 1c76276..7ccb183 100644 --- a/FunGame.Desktop/Controller/LoginController.cs +++ b/FunGame.Desktop/Controller/LoginController.cs @@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Desktop.Controller { public static bool LoginAccount(params object[]? objs) { - RunTime.Login?.OnBeforeLoginEvent(new GeneralEventArgs()); + if (RunTime.Login?.OnBeforeLoginEvent(new GeneralEventArgs()) == Core.Library.Constant.EventResult.Fail) return false; bool result = LoginModel.LoginAccount(objs); if (!result) { diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs index 4d950cb..0848204 100644 --- a/FunGame.Desktop/Controller/MainController.cs +++ b/FunGame.Desktop/Controller/MainController.cs @@ -46,7 +46,7 @@ namespace Milimoe.FunGame.Desktop.Controller break; case MainInvokeType.Disconnect: - Main.OnBeforeDisconnectEvent(new GeneralEventArgs()); + if (Main.OnBeforeDisconnectEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result; MainModel.Disconnect(); break; @@ -72,7 +72,7 @@ namespace Milimoe.FunGame.Desktop.Controller break; case MainInvokeType.LogOut: - Main.OnBeforeLogoutEvent(new GeneralEventArgs()); + if (Main.OnBeforeLogoutEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result; result = MainModel.LogOut(); break; @@ -81,12 +81,12 @@ namespace Milimoe.FunGame.Desktop.Controller break; case MainInvokeType.IntoRoom: - Main.OnBeforeIntoRoomEvent(new GeneralEventArgs()); + if (Main.OnBeforeIntoRoomEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result; result = MainModel.IntoRoom(); break; case MainInvokeType.Chat: - Main.OnBeforeSendTalkEvent(new GeneralEventArgs()); + if (Main.OnBeforeSendTalkEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result; if (args != null && args.Length > 0) result = MainModel.Chat((string)args[0]); break; diff --git a/FunGame.Desktop/Controller/RegisterController.cs b/FunGame.Desktop/Controller/RegisterController.cs index 62999b7..1f1846e 100644 --- a/FunGame.Desktop/Controller/RegisterController.cs +++ b/FunGame.Desktop/Controller/RegisterController.cs @@ -3,10 +3,11 @@ using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Desktop.UI; +using Milimoe.FunGame.Desktop.Library.Interface; namespace Milimoe.FunGame.Desktop.Controller { - public class RegisterController + public class RegisterController : ISocketCallBack { private readonly Register Register; private readonly RegisterModel RegModel; @@ -24,7 +25,7 @@ namespace Milimoe.FunGame.Desktop.Controller public bool Reg(params object[]? objs) { - Register.OnBeforeRegEvent(Register.EventArgs); + if (Register.OnBeforeRegEvent(Register.EventArgs) == EventResult.Fail) return false; bool result = RegModel.Reg(objs); if (!result) { diff --git a/FunGame.Desktop/Library/Interface/ICallBack.cs b/FunGame.Desktop/Library/Interface/ICallBack.cs new file mode 100644 index 0000000..b6cfbb5 --- /dev/null +++ b/FunGame.Desktop/Library/Interface/ICallBack.cs @@ -0,0 +1,9 @@ +using Milimoe.FunGame.Core.Library.Constant; + +namespace Milimoe.FunGame.Desktop.Library.Interface +{ + public interface ISocketCallBack + { + public void SocketHandler(SocketMessageType type, params object[]? objs); + } +} diff --git a/FunGame.Desktop/Model/MainModel.cs b/FunGame.Desktop/Model/MainModel.cs index b4dfad1..061f37a 100644 --- a/FunGame.Desktop/Model/MainModel.cs +++ b/FunGame.Desktop/Model/MainModel.cs @@ -105,7 +105,7 @@ namespace Milimoe.FunGame.Desktop.Model public ConnectResult Connect() { - Main.OnBeforeConnectEvent(new GeneralEventArgs()); + if (Main.OnBeforeConnectEvent(new GeneralEventArgs()) == EventResult.Fail) return ConnectResult.ConnectFailed; if (Constant.Server_Address == "" || Constant.Server_Port <= 0) { ShowMessage.ErrorMessage("查找可用的服务器失败!"); diff --git a/FunGame.Desktop/Model/RegisterModel.cs b/FunGame.Desktop/Model/RegisterModel.cs index ab3d12e..8df22d4 100644 --- a/FunGame.Desktop/Model/RegisterModel.cs +++ b/FunGame.Desktop/Model/RegisterModel.cs @@ -3,11 +3,12 @@ using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Component; +using Milimoe.FunGame.Desktop.Library.Interface; using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Model { - public class RegisterModel + public class RegisterModel : ISocketCallBack { private readonly Register Register; @@ -78,7 +79,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - e.GetErrorInfo(); + RunTime.WritelnSystemInfo(e.GetErrorInfo()); } return false; } @@ -107,7 +108,7 @@ namespace Milimoe.FunGame.Desktop.Model } catch (Exception e) { - e.GetErrorInfo(); + RunTime.WritelnSystemInfo(e.GetErrorInfo()); } return false; } diff --git a/FunGame.Desktop/UI/Login/Login.cs b/FunGame.Desktop/UI/Login/Login.cs index a19407f..1561ffc 100644 --- a/FunGame.Desktop/UI/Login/Login.cs +++ b/FunGame.Desktop/UI/Login/Login.cs @@ -93,7 +93,7 @@ namespace Milimoe.FunGame.Desktop.UI private EventResult BeforeLoginEvent(object sender, GeneralEventArgs e) { - RunTime.Main?.OnBeforeLoginEvent(e); + if (RunTime.Main?.OnBeforeLoginEvent(e) == EventResult.Fail) return EventResult.Fail; return EventResult.Success; } diff --git a/FunGame.Desktop/UI/Register/Register.cs b/FunGame.Desktop/UI/Register/Register.cs index 6785e10..440c17b 100644 --- a/FunGame.Desktop/UI/Register/Register.cs +++ b/FunGame.Desktop/UI/Register/Register.cs @@ -6,11 +6,11 @@ using Milimoe.FunGame.Desktop.Controller; using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library.Base; using Milimoe.FunGame.Desktop.Library.Component; -using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel; +using Milimoe.FunGame.Desktop.Library.Interface; namespace Milimoe.FunGame.Desktop.UI { - public partial class Register : BaseReg + public partial class Register : BaseReg, ISocketCallBack { public bool CheckReg { get; set; } = false; public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs(); @@ -59,7 +59,7 @@ namespace Milimoe.FunGame.Desktop.UI if (password != "") { int length = password.Length; - if (length >= 6 && length <= 15) // 字节范围 3~12 + if (length < 6 || length > 15) // 字节范围 3~12 { ShowMessage.ErrorMessage("密码长度不符合要求:6~15个字符数"); PasswordText.Focus();