mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 00:06:02 +00:00
重构RegModel
This commit is contained in:
parent
bbe634b8bb
commit
15ed5152de
@ -2,15 +2,18 @@
|
|||||||
{
|
{
|
||||||
public class RegisterEventArgs : GeneralEventArgs
|
public class RegisterEventArgs : GeneralEventArgs
|
||||||
{
|
{
|
||||||
public string Username;
|
public string Username { get; set; } = "";
|
||||||
public string Password;
|
public string Password { get; set; } = "";
|
||||||
public string Email;
|
public string Email { get; set; } = "";
|
||||||
|
|
||||||
public RegisterEventArgs(string username = "", string password = "", string email = "")
|
public RegisterEventArgs(params object[]? objs)
|
||||||
{
|
{
|
||||||
Username = username;
|
if (objs != null)
|
||||||
Password = password;
|
{
|
||||||
Email = email;
|
if (objs.Length > 0) Username = (string)objs[0];
|
||||||
|
if (objs.Length > 1) Password = (string)objs[1];
|
||||||
|
if (objs.Length > 2) Email = (string)objs[2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,8 @@ 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.Core.Library.Common.Architecture;
|
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||||
|
using Milimoe.FunGame.Core.Library.Exception;
|
||||||
|
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Desktop.Controller
|
namespace Milimoe.FunGame.Desktop.Controller
|
||||||
{
|
{
|
||||||
@ -23,26 +25,26 @@ namespace Milimoe.FunGame.Desktop.Controller
|
|||||||
RegModel.Dispose();
|
RegModel.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Reg(params object[]? objs)
|
public async Task<bool> Reg(params object[]? objs)
|
||||||
{
|
{
|
||||||
if (Register.OnBeforeRegEvent(Register.EventArgs) == EventResult.Fail) return false;
|
bool result = false;
|
||||||
bool result = RegModel.Reg(objs);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
|
|
||||||
Register.OnFailedRegEvent(Register.EventArgs);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CheckReg(params object[]? objs)
|
try
|
||||||
{
|
|
||||||
bool result = RegModel.CheckReg(objs);
|
|
||||||
if (!result)
|
|
||||||
{
|
{
|
||||||
ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
|
RegisterEventArgs RegEventArgs = new (objs);
|
||||||
RunTime.Register?.OnFailedRegEvent(Register.EventArgs);
|
if (Register.OnBeforeRegEvent(RegEventArgs) == EventResult.Fail) return false;
|
||||||
|
|
||||||
|
result = await RegModel.Reg(objs);
|
||||||
|
|
||||||
|
if (result) Register.OnSucceedRegEvent(RegEventArgs);
|
||||||
|
else Register.OnFailedRegEvent(RegEventArgs);
|
||||||
|
Register.OnAfterRegEvent(RegEventArgs);
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,15 +97,12 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
{
|
{
|
||||||
if (!Working) break;
|
if (!Working) break;
|
||||||
}
|
}
|
||||||
if (Work != null)
|
// 返回一个确认登录的Key
|
||||||
|
if (Work.Length > 0) key = Work.GetParam<Guid>(0);
|
||||||
|
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
||||||
|
if (key != Guid.Empty)
|
||||||
{
|
{
|
||||||
// 返回一个确认登录的Key
|
Config.Guid_LoginKey = key;
|
||||||
if (Work.Length > 0) key = Work.GetParam<Guid>(0);
|
|
||||||
if (Work.Length > 1) msg = Work.GetParam<string>(1);
|
|
||||||
if (key != Guid.Empty)
|
|
||||||
{
|
|
||||||
Config.Guid_LoginKey = key;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -125,11 +122,8 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
{
|
{
|
||||||
if (!Working) break;
|
if (!Working) break;
|
||||||
}
|
}
|
||||||
if (Work != null)
|
// 返回构造User对象的DataSet
|
||||||
{
|
if (Work.Length > 0) ds = Work.GetParam<DataSet>(0);
|
||||||
// 返回构造User对象的DataTable
|
|
||||||
if (Work.Length > 0) ds = Work.GetParam<DataSet>(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -12,6 +12,8 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
public class RegisterModel : BaseModel
|
public class RegisterModel : BaseModel
|
||||||
{
|
{
|
||||||
private readonly Register Register;
|
private readonly Register Register;
|
||||||
|
private SocketObject Work;
|
||||||
|
private bool Working = false;
|
||||||
|
|
||||||
public RegisterModel(Register reg) : base(RunTime.Socket)
|
public RegisterModel(Register reg) : base(RunTime.Socket)
|
||||||
{
|
{
|
||||||
@ -22,21 +24,10 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SocketMessageType type = SocketObject.SocketType;
|
if (SocketObject.SocketType == SocketMessageType.Reg || SocketObject.SocketType == SocketMessageType.CheckReg)
|
||||||
object[] objs = SocketObject.Parameters;
|
|
||||||
switch (SocketObject.SocketType)
|
|
||||||
{
|
{
|
||||||
case SocketMessageType.Reg:
|
Work = SocketObject;
|
||||||
RegInvokeType invokeType = RegInvokeType.None;
|
Working = false;
|
||||||
if (objs != null && objs.Length > 0)
|
|
||||||
{
|
|
||||||
invokeType = SocketObject.GetParam<RegInvokeType>(0);
|
|
||||||
Register.UpdateUI(invokeType);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case SocketMessageType.CheckReg:
|
|
||||||
SocketHandler_CheckReg(SocketObject);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -45,51 +36,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SocketHandler_CheckReg(SocketObject SocketObject)
|
public async Task<bool> Reg(params object[]? objs)
|
||||||
{
|
|
||||||
if (SocketObject.Parameters != null && SocketObject.Parameters.Length > 1)
|
|
||||||
{
|
|
||||||
bool successful = SocketObject.GetParam<bool>(0)!;
|
|
||||||
string msg = SocketObject.GetParam<string>(1)!;
|
|
||||||
ShowMessage.Message(msg, "注册结果");
|
|
||||||
if (successful)
|
|
||||||
{
|
|
||||||
Register.OnSucceedRegEvent(Register.EventArgs);
|
|
||||||
Register.OnAfterRegEvent(Register.EventArgs);
|
|
||||||
Register.Close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Register.OnFailedRegEvent(Register.EventArgs);
|
|
||||||
Register.OnAfterRegEvent(Register.EventArgs);
|
|
||||||
Register.UpdateUI(RegInvokeType.InputVerifyCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Reg(params object[]? objs)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Socket? Socket = RunTime.Socket;
|
|
||||||
if (Socket != null && objs != null)
|
|
||||||
{
|
|
||||||
string username = "";
|
|
||||||
string email = "";
|
|
||||||
if (objs.Length > 0) username = (string)objs[0];
|
|
||||||
if (objs.Length > 1) email = (string)objs[1];
|
|
||||||
if (Socket.Send(SocketMessageType.Reg, username, email) == SocketResult.Success)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool CheckReg(params object[]? objs)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -99,15 +46,42 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
string username = "";
|
string username = "";
|
||||||
string password = "";
|
string password = "";
|
||||||
string email = "";
|
string email = "";
|
||||||
string verifycode = "";
|
|
||||||
if (objs.Length > 0) username = (string)objs[0];
|
if (objs.Length > 0) username = (string)objs[0];
|
||||||
if (objs.Length > 1) password = (string)objs[1];
|
if (objs.Length > 1) password = (string)objs[1];
|
||||||
password = password.Encrypt(username);
|
password = password.Encrypt(username);
|
||||||
if (objs.Length > 2) email = (string)objs[2];
|
if (objs.Length > 2) email = (string)objs[2];
|
||||||
if (objs.Length > 3) verifycode = (string)objs[3];
|
SetWorking();
|
||||||
if (Socket.Send(SocketMessageType.CheckReg, username, password, email, verifycode) == SocketResult.Success)
|
if (Socket.Send(SocketMessageType.Reg, username, email) == SocketResult.Success)
|
||||||
{
|
{
|
||||||
return true;
|
RegInvokeType InvokeType = await Task.Factory.StartNew(GetRegInvokeType);
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
switch (InvokeType)
|
||||||
|
{
|
||||||
|
case RegInvokeType.InputVerifyCode:
|
||||||
|
string verifycode = ShowMessage.InputMessageCancel("请输入注册邮件中的6位数字验证码", "注册验证码", out MessageResult cancel);
|
||||||
|
if (cancel != MessageResult.Cancel)
|
||||||
|
{
|
||||||
|
SetWorking();
|
||||||
|
if (Socket.Send(SocketMessageType.CheckReg, username, password, email, verifycode) == SocketResult.Success)
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
string msg = "";
|
||||||
|
(success, msg) = await Task.Factory.StartNew(GetRegResult);
|
||||||
|
ShowMessage.Message(msg, "注册结果");
|
||||||
|
if (success) return success;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else return false;
|
||||||
|
case RegInvokeType.DuplicateUserName:
|
||||||
|
ShowMessage.WarningMessage("此账号名已被注册,请使用其他账号名。");
|
||||||
|
return false;
|
||||||
|
case RegInvokeType.DuplicateEmail:
|
||||||
|
ShowMessage.WarningMessage("此邮箱已被使用,请使用其他邮箱注册。");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,5 +91,49 @@ namespace Milimoe.FunGame.Desktop.Model
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RegInvokeType GetRegInvokeType()
|
||||||
|
{
|
||||||
|
RegInvokeType type = RegInvokeType.None;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!Working) break;
|
||||||
|
}
|
||||||
|
if (Work.Length > 0) type = Work.GetParam<RegInvokeType>(0);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||||
|
}
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private (bool, string) GetRegResult()
|
||||||
|
{
|
||||||
|
bool success = false;
|
||||||
|
string? msg = "";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (!Working) break;
|
||||||
|
}
|
||||||
|
if (Work.Length > 0) success = Work.GetParam<bool>(0);
|
||||||
|
if (Work.Length > 1) msg = Work.GetParam<string>(1) ?? "";
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||||
|
}
|
||||||
|
return (success, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetWorking()
|
||||||
|
{
|
||||||
|
Working = true;
|
||||||
|
Work = default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1303,7 +1303,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
if (!Config.FunGame_isRetrying)
|
if (!Config.FunGame_isRetrying)
|
||||||
{
|
{
|
||||||
CurrentRetryTimes = -1;
|
CurrentRetryTimes = -1;
|
||||||
Config.FunGame_isAutoLogin = true;
|
Config.FunGame_isAutoRetry = true;
|
||||||
RunTime.Connector?.Connect();
|
RunTime.Connector?.Connect();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1313,7 +1313,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
if (!Config.FunGame_isConnected)
|
if (!Config.FunGame_isConnected)
|
||||||
{
|
{
|
||||||
CurrentRetryTimes = -1;
|
CurrentRetryTimes = -1;
|
||||||
Config.FunGame_isAutoLogin = true;
|
Config.FunGame_isAutoRetry = true;
|
||||||
RunTime.Connector?.GetServerConnection();
|
RunTime.Connector?.GetServerConnection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1357,7 +1357,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
Constant.Server_Address = ip;
|
Constant.Server_Address = ip;
|
||||||
Constant.Server_Port = port;
|
Constant.Server_Port = port;
|
||||||
CurrentRetryTimes = -1;
|
CurrentRetryTimes = -1;
|
||||||
Config.FunGame_isAutoLogin = true;
|
Config.FunGame_isAutoRetry = true;
|
||||||
RunTime.Connector?.Connect();
|
RunTime.Connector?.Connect();
|
||||||
}
|
}
|
||||||
else if (ErrorType == Core.Library.Constant.ErrorType.IsNotIP) ShowMessage.ErrorMessage("这不是一个IP地址!");
|
else if (ErrorType == Core.Library.Constant.ErrorType.IsNotIP) ShowMessage.ErrorMessage("这不是一个IP地址!");
|
||||||
|
|||||||
@ -12,7 +12,6 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
public partial class Register : BaseReg
|
public partial class Register : BaseReg
|
||||||
{
|
{
|
||||||
public bool CheckReg { get; set; } = false;
|
public bool CheckReg { get; set; } = false;
|
||||||
public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs();
|
|
||||||
|
|
||||||
private readonly RegisterController RegController;
|
private readonly RegisterController RegController;
|
||||||
|
|
||||||
@ -34,7 +33,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
RegController.Dispose();
|
RegController.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool Reg_Handler()
|
private async Task<bool> Reg_Handler()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -98,57 +97,13 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
EmailText.Focus();
|
EmailText.Focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EventArgs = new RegisterEventArgs(username, password, email);
|
return await RegController.Reg(username, password, email);
|
||||||
if (!RegController.Reg(username, email))
|
|
||||||
{
|
|
||||||
ShowMessage.Message("注册失败!", "注册失败");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateUI(RegInvokeType type)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
void Action()
|
|
||||||
{
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case RegInvokeType.InputVerifyCode:
|
|
||||||
string username = UsernameText.Text.Trim();
|
|
||||||
string password = PasswordText.Text.Trim();
|
|
||||||
string email = EmailText.Text.Trim();
|
|
||||||
string verifycode = ShowMessage.InputMessageCancel("请输入注册邮件中的6位数字验证码", "注册验证码", out MessageResult cancel);
|
|
||||||
if (cancel != MessageResult.Cancel) RegController.CheckReg(username, password, email, verifycode);
|
|
||||||
else RegButton.Enabled = true;
|
|
||||||
break;
|
|
||||||
case RegInvokeType.DuplicateUserName:
|
|
||||||
ShowMessage.WarningMessage("此账号名已被注册,请使用其他账号名。");
|
|
||||||
RegButton.Enabled = true;
|
|
||||||
break;
|
|
||||||
case RegInvokeType.DuplicateEmail:
|
|
||||||
ShowMessage.WarningMessage("此邮箱已被使用,请使用其他邮箱注册。");
|
|
||||||
RegButton.Enabled = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (!IsDisposed)
|
|
||||||
{
|
|
||||||
if (InvokeRequired) Invoke(Action);
|
|
||||||
else Action();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -169,10 +124,11 @@ namespace Milimoe.FunGame.Desktop.UI
|
|||||||
return EventResult.Success;
|
return EventResult.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegButton_Click(object sender, EventArgs e)
|
private async void RegButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
RegButton.Enabled = false;
|
RegButton.Enabled = false;
|
||||||
if (!Reg_Handler()) RegButton.Enabled = true;
|
if (!await Reg_Handler()) RegButton.Enabled = true;
|
||||||
|
else Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GoToLogin_Click(object sender, EventArgs e)
|
private void GoToLogin_Click(object sender, EventArgs e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user