修复BUG和事件改进

This commit is contained in:
Mili 2023-03-06 21:34:26 +08:00
parent 14c4cdb48f
commit 618f9c93c9
8 changed files with 26 additions and 15 deletions

View File

@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Desktop.Controller
{ {
public static bool LoginAccount(params object[]? objs) 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); bool result = LoginModel.LoginAccount(objs);
if (!result) if (!result)
{ {

View File

@ -46,7 +46,7 @@ namespace Milimoe.FunGame.Desktop.Controller
break; break;
case MainInvokeType.Disconnect: case MainInvokeType.Disconnect:
Main.OnBeforeDisconnectEvent(new GeneralEventArgs()); if (Main.OnBeforeDisconnectEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result;
MainModel.Disconnect(); MainModel.Disconnect();
break; break;
@ -72,7 +72,7 @@ namespace Milimoe.FunGame.Desktop.Controller
break; break;
case MainInvokeType.LogOut: case MainInvokeType.LogOut:
Main.OnBeforeLogoutEvent(new GeneralEventArgs()); if (Main.OnBeforeLogoutEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result;
result = MainModel.LogOut(); result = MainModel.LogOut();
break; break;
@ -81,12 +81,12 @@ namespace Milimoe.FunGame.Desktop.Controller
break; break;
case MainInvokeType.IntoRoom: case MainInvokeType.IntoRoom:
Main.OnBeforeIntoRoomEvent(new GeneralEventArgs()); if (Main.OnBeforeIntoRoomEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result;
result = MainModel.IntoRoom(); result = MainModel.IntoRoom();
break; break;
case MainInvokeType.Chat: case MainInvokeType.Chat:
Main.OnBeforeSendTalkEvent(new GeneralEventArgs()); if (Main.OnBeforeSendTalkEvent(new GeneralEventArgs()) == EventResult.Fail) return (T)result;
if (args != null && args.Length > 0) if (args != null && args.Length > 0)
result = MainModel.Chat((string)args[0]); result = MainModel.Chat((string)args[0]);
break; break;

View File

@ -3,10 +3,11 @@ using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.UI; using Milimoe.FunGame.Desktop.UI;
using Milimoe.FunGame.Desktop.Library.Interface;
namespace Milimoe.FunGame.Desktop.Controller namespace Milimoe.FunGame.Desktop.Controller
{ {
public class RegisterController public class RegisterController : ISocketCallBack
{ {
private readonly Register Register; private readonly Register Register;
private readonly RegisterModel RegModel; private readonly RegisterModel RegModel;
@ -24,7 +25,7 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool Reg(params object[]? objs) public bool Reg(params object[]? objs)
{ {
Register.OnBeforeRegEvent(Register.EventArgs); if (Register.OnBeforeRegEvent(Register.EventArgs) == EventResult.Fail) return false;
bool result = RegModel.Reg(objs); bool result = RegModel.Reg(objs);
if (!result) if (!result)
{ {

View File

@ -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);
}
}

View File

@ -105,7 +105,7 @@ namespace Milimoe.FunGame.Desktop.Model
public ConnectResult Connect() 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) if (Constant.Server_Address == "" || Constant.Server_Port <= 0)
{ {
ShowMessage.ErrorMessage("查找可用的服务器失败!"); ShowMessage.ErrorMessage("查找可用的服务器失败!");

View File

@ -3,11 +3,12 @@ using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Component; using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.UI; using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Model namespace Milimoe.FunGame.Desktop.Model
{ {
public class RegisterModel public class RegisterModel : ISocketCallBack
{ {
private readonly Register Register; private readonly Register Register;
@ -78,7 +79,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
e.GetErrorInfo(); RunTime.WritelnSystemInfo(e.GetErrorInfo());
} }
return false; return false;
} }
@ -107,7 +108,7 @@ namespace Milimoe.FunGame.Desktop.Model
} }
catch (Exception e) catch (Exception e)
{ {
e.GetErrorInfo(); RunTime.WritelnSystemInfo(e.GetErrorInfo());
} }
return false; return false;
} }

View File

@ -93,7 +93,7 @@ namespace Milimoe.FunGame.Desktop.UI
private EventResult BeforeLoginEvent(object sender, GeneralEventArgs e) private EventResult BeforeLoginEvent(object sender, GeneralEventArgs e)
{ {
RunTime.Main?.OnBeforeLoginEvent(e); if (RunTime.Main?.OnBeforeLoginEvent(e) == EventResult.Fail) return EventResult.Fail;
return EventResult.Success; return EventResult.Success;
} }

View File

@ -6,11 +6,11 @@ using Milimoe.FunGame.Desktop.Controller;
using Milimoe.FunGame.Desktop.Library; using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Base; using Milimoe.FunGame.Desktop.Library.Base;
using Milimoe.FunGame.Desktop.Library.Component; 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 namespace Milimoe.FunGame.Desktop.UI
{ {
public partial class Register : BaseReg public partial class Register : BaseReg, ISocketCallBack
{ {
public bool CheckReg { get; set; } = false; public bool CheckReg { get; set; } = false;
public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs(); public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs();
@ -59,7 +59,7 @@ namespace Milimoe.FunGame.Desktop.UI
if (password != "") if (password != "")
{ {
int length = password.Length; int length = password.Length;
if (length >= 6 && length <= 15) // 字节范围 3~12 if (length < 6 || length > 15) // 字节范围 3~12
{ {
ShowMessage.ErrorMessage("密码长度不符合要求6~15个字符数"); ShowMessage.ErrorMessage("密码长度不符合要求6~15个字符数");
PasswordText.Focus(); PasswordText.Focus();