This commit is contained in:
Mili 2023-03-05 00:57:54 +08:00
parent a9306d2495
commit 387714288f
15 changed files with 190 additions and 21 deletions

View File

@ -73,10 +73,10 @@ namespace Milimoe.FunGame.Core.Interface
public event SucceedEventHandler? SucceedReg;
public event FailedEventHandler? FailedReg;
public EventResult OnBeforeRegEvent(GeneralEventArgs e);
public EventResult OnAfterRegEvent(GeneralEventArgs e);
public EventResult OnSucceedRegEvent(GeneralEventArgs e);
public EventResult OnFailedRegEvent(GeneralEventArgs e);
public EventResult OnBeforeRegEvent(RegisterEventArgs e);
public EventResult OnAfterRegEvent(RegisterEventArgs e);
public EventResult OnSucceedRegEvent(RegisterEventArgs e);
public EventResult OnFailedRegEvent(RegisterEventArgs e);
}
public interface IIntoRoomEventHandler : IEventHandler

View File

@ -40,10 +40,10 @@ namespace Milimoe.FunGame.Core.Interface
public interface IRegEvent
{
public EventResult BeforeRegEvent(object sender, GeneralEventArgs e);
public EventResult AfterRegEvent(object sender, GeneralEventArgs e);
public EventResult SucceedRegEvent(object sender, GeneralEventArgs e);
public EventResult FailedRegEvent(object sender, GeneralEventArgs e);
public EventResult BeforeRegEvent(object sender, RegisterEventArgs e);
public EventResult AfterRegEvent(object sender, RegisterEventArgs e);
public EventResult SucceedRegEvent(object sender, RegisterEventArgs e);
public EventResult FailedRegEvent(object sender, RegisterEventArgs e);
}
public interface IIntoRoomEvent

View File

@ -0,0 +1,16 @@
namespace Milimoe.FunGame.Core.Library.Common.Event
{
public class RegisterEventArgs : GeneralEventArgs
{
public string Username;
public string Password;
public string Email;
public RegisterEventArgs(string username = "", string password = "", string email = "")
{
Username = username;
Password = password;
Email = email;
}
}
}

View File

@ -33,8 +33,10 @@
public const string Disconnect = "Disconnect";
public const string HeartBeat = "HeartBeat";
public const string IntoRoom = "IntoRoom";
public const string Chat = "Chat";
public const string QuitRoom = "QuitRoom";
public const string Chat = "Chat";
public const string Reg = "Reg";
public const string CheckReg = "CheckReg";
}
public class ReflectionSet

View File

@ -58,6 +58,7 @@
Disconnect,
HeartBeat,
IntoRoom,
QuitRoom,
Chat,
Reg,
CheckReg

View File

@ -52,5 +52,10 @@ namespace Milimoe.FunGame.Core.Library.SQLScript.Common
{
return $"{Constant.Command_Select} {Constant.Command_All} {Constant.Command_From} {TableName} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Email} = '{Email}' and {Column_RegVerifyCode} = '{RegVerifyCode}'";
}
public static string Delete_RegVerifyCode(string Username, string Email)
{
return $"{Constant.Command_Delete} {Constant.Command_From} {TableName} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Email} = '{Email}'";
}
}
}

View File

@ -2,7 +2,7 @@
{
public class UserQuery
{
public const string TableName= "User";
public const string TableName= "Users";
public const string Column_UID = "UID";
public const string Column_Username = "Username";
public const string Column_Password = "Password";
@ -18,6 +18,7 @@
public const string Column_Credits = "Credits";
public const string Column_Materials = "Materials";
public const string Column_GameTime = "GameTime";
public const string Column_AutoKey = "AutoKey";
public const string Select_Users = $"{Constant.Command_Select} {Constant.Command_All} {Constant.Command_From} {TableName}";
public static string Select_Users_LoginQuery(string Username, string Password)
@ -30,16 +31,21 @@
return $"{Select_Users} {Constant.Command_Where} {Where}'";
}
public static string CheckLogin(string Username, string IP)
public static string Update_CheckLogin(string Username, string IP)
{
return @$"{Constant.Command_Update} {TableName} {Constant.Command_Set} {Column_LastTime} = '{DateTime.Now}', {Column_LastIP} = '{IP}'
{Constant.Command_Where} {Column_Username} = '{Username}'";
}
public static string Register(string UserName, string Password, string Email)
public static string Insert_Register(string Username, string Password, string Email)
{
return @$"{Constant.Command_Insert} {Constant.Command_Into} {TableName} ({Column_Username}, {Column_Password}, {Column_Email}, {Column_RegTime})
{Constant.Command_Values} ('{UserName}', '{Password}', {Email}, '{DateTime.Now}')";
{Constant.Command_Values} ('{Username}', '{Password}', '{Email}', '{DateTime.Now}')";
}
public static string Select_CheckAutoKey(string Username, string AutoKey)
{
return $"{Select_Users} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_AutoKey} = '{AutoKey}'";
}
}
}

View File

@ -216,7 +216,10 @@ namespace Milimoe.FunGame.Core.Service
SocketMessageType.Disconnect => SocketSet.Disconnect,
SocketMessageType.HeartBeat => SocketSet.HeartBeat,
SocketMessageType.IntoRoom => SocketSet.IntoRoom,
SocketMessageType.QuitRoom => SocketSet.QuitRoom,
SocketMessageType.Chat => SocketSet.Chat,
SocketMessageType.Reg => SocketSet.Reg,
SocketMessageType.CheckReg => SocketSet.CheckReg,
_ => SocketSet.Unknown,
};
}

View File

@ -9,12 +9,24 @@ namespace Milimoe.FunGame.Desktop.Controller
{
public static bool Reg(params object[]? objs)
{
RunTime.Register?.OnBeforeRegEvent(new GeneralEventArgs());
if (RunTime.Register != null) RunTime.Register.OnBeforeRegEvent(RunTime.Register.EventArgs);
bool result = RegisterModel.Reg(objs);
if (!result)
{
ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5);
RunTime.Register?.OnFailedRegEvent(new GeneralEventArgs());
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs);
}
return result;
}
public static bool CheckReg(params object[]? objs)
{
bool result = RegisterModel.CheckReg(objs);
if (!result)
{
ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5);
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs);
}
return result;
}

View File

@ -7,12 +7,17 @@ namespace Milimoe.FunGame.Desktop.Library.Base
{
public class BaseReg : GeneralForm, IRegEventHandler
{
public delegate EventResult BeforeEventHandler(object sender, RegisterEventArgs e);
public delegate EventResult AfterEventHandler(object sender, RegisterEventArgs e);
public delegate EventResult SucceedEventHandler(object sender, RegisterEventArgs e);
public delegate EventResult FailedEventHandler(object sender, RegisterEventArgs e);
public event IEventHandler.BeforeEventHandler? BeforeReg;
public event IEventHandler.AfterEventHandler? AfterReg;
public event IEventHandler.SucceedEventHandler? SucceedReg;
public event IEventHandler.FailedEventHandler? FailedReg;
public EventResult OnAfterRegEvent(GeneralEventArgs e)
public EventResult OnAfterRegEvent(RegisterEventArgs e)
{
if (AfterReg != null)
{
@ -21,7 +26,7 @@ namespace Milimoe.FunGame.Desktop.Library.Base
else return EventResult.NoEventImplement;
}
public EventResult OnBeforeRegEvent(GeneralEventArgs e)
public EventResult OnBeforeRegEvent(RegisterEventArgs e)
{
if (BeforeReg != null)
{
@ -30,7 +35,7 @@ namespace Milimoe.FunGame.Desktop.Library.Base
else return EventResult.NoEventImplement;
}
public EventResult OnFailedRegEvent(GeneralEventArgs e)
public EventResult OnFailedRegEvent(RegisterEventArgs e)
{
if (FailedReg != null)
{
@ -39,7 +44,7 @@ namespace Milimoe.FunGame.Desktop.Library.Base
else return EventResult.NoEventImplement;
}
public EventResult OnSucceedRegEvent(GeneralEventArgs e)
public EventResult OnSucceedRegEvent(RegisterEventArgs e)
{
if (SucceedReg != null)
{

View File

@ -207,6 +207,15 @@ namespace Milimoe.FunGame.Desktop.Library.Component
return result;
}
public static string InputMessageCancel(string msg, string title, out MessageResult cancel)
{
object[] objs = { title, msg, 0, MessageButtonType.Input, BUTTON_CANCEL, BUTTON_RETRY, BUTTON_CANCEL };
ShowMessage window = new ShowMessage(objs);
string result = window.InputResult;
cancel = window.MessageResult;
return result;
}
private void ChangeSecond(string msg, int s)
{
MsgText.Text = msg + "\n[ " + s + " 秒后自动关闭 ]";
@ -229,6 +238,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
private void InputButton_Click()
{
MessageResult = MessageResult.OK;
if (InputText.Text != null && !InputText.Text.Equals(""))
{
InputResult = InputText.Text;

View File

@ -8,6 +8,8 @@ using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Component;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.UI;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
namespace Milimoe.FunGame.Desktop.Model
{
@ -349,10 +351,20 @@ namespace Milimoe.FunGame.Desktop.Model
SocketHandler_IntoRoom(objs);
break;
case SocketMessageType.QuitRoom:
break;
case SocketMessageType.Chat:
SocketHandler_Chat(objs);
break;
case SocketMessageType.Reg:
break;
case SocketMessageType.CheckReg:
SocketHandler_CheckReg(objs);
break;
case SocketMessageType.Unknown:
default:
break;
@ -506,6 +518,32 @@ namespace Milimoe.FunGame.Desktop.Model
Main.OnAfterSendTalkEvent(new GeneralEventArgs());
}
private void SocketHandler_CheckReg(object[] objs)
{
if (objs != null && objs.Length > 1)
{
bool successful = NetworkUtility.ConvertJsonObject<bool>(objs[0])!;
string msg = NetworkUtility.ConvertJsonObject<string>(objs[1])!;
ShowMessage.Message(msg, "注册结果");
if (successful)
{
Main.GetMessage(msg, TimeType.None);
if (RunTime.Register != null)
{
RunTime.Register.CheckReg = true;
RunTime.Register.OnSucceedRegEvent(RunTime.Register.EventArgs);
RunTime.Register.OnAfterRegEvent(RunTime.Register.EventArgs);
}
return;
}
}
if (RunTime.Register != null)
{
RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs);
RunTime.Register.OnAfterRegEvent(RunTime.Register.EventArgs);
}
}
#endregion
}
}

View File

@ -1,4 +1,5 @@
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Api.Utility;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Library;
@ -29,5 +30,34 @@ namespace Milimoe.FunGame.Desktop.Model
}
return false;
}
public static bool CheckReg(params object[]? objs)
{
try
{
Core.Library.Common.Network.Socket? Socket = RunTime.Socket;
if (Socket != null && objs != null)
{
string username = "";
string password = "";
string email = "";
string verifycode = "";
if (objs.Length > 0) username = (string)objs[0];
if (objs.Length > 1) password = (string)objs[1];
password = password.Encrypt(username);
if (objs.Length > 2) email = (string)objs[2];
if (objs.Length > 3) verifycode = (string)objs[3];
if (Socket.Send(SocketMessageType.CheckReg, username, password, email, verifycode) == SocketResult.Success)
{
return true;
}
}
}
catch (Exception e)
{
e.GetErrorInfo();
}
return false;
}
}
}

View File

@ -86,6 +86,7 @@ namespace Milimoe.FunGame.Desktop.UI
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
{
Dispose();
RunTime.Main?.OnSucceedLoginEvent(e);
return EventResult.Success;
}

View File

@ -5,11 +5,15 @@ 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;
namespace Milimoe.FunGame.Desktop.UI
{
public partial class Register : BaseReg
{
public bool CheckReg { get; set; } = false;
public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs();
public Register()
{
InitializeComponent();
@ -19,6 +23,7 @@ namespace Milimoe.FunGame.Desktop.UI
{
base.BindEvent();
SucceedReg += SucceedRegEvent;
FailedReg += FailedRegEvent;
}
private bool Reg_Handler()
@ -47,11 +52,18 @@ namespace Milimoe.FunGame.Desktop.UI
UsernameText.Focus();
return false;
}
EventArgs = new RegisterEventArgs(username, password, email);
if (!RegisterController.Reg(username, email))
{
ShowMessage.Message("注册失败!!", "注册失败");
return false;
}
else
{
CheckReg = false;
// 成功发送注册请求后
CheckReg_Handler(username, password, email);
}
}
catch (Exception e)
{
@ -61,6 +73,20 @@ namespace Milimoe.FunGame.Desktop.UI
return true;
}
public void CheckReg_Handler(string username, string password, string email)
{
if (!CheckReg)
{
string verifycode = ShowMessage.InputMessageCancel("请输入注册邮件中的6位数字验证码", "注册验证码", out MessageResult cancel);
if (cancel == MessageResult.Cancel)
{
CheckReg = true;
RegButton.Enabled = true;
}
RegisterController.CheckReg(username, password, email, verifycode);
}
}
/// <summary>
/// 关闭窗口
/// </summary>
@ -73,12 +99,26 @@ namespace Milimoe.FunGame.Desktop.UI
private EventResult SucceedRegEvent(object sender, GeneralEventArgs e)
{
string username = ((RegisterEventArgs)e).Username;
string password = ((RegisterEventArgs)e).Password;
if (LoginController.LoginAccount(username, password))
Dispose();
return EventResult.Success;
}
private EventResult FailedRegEvent(object sender, GeneralEventArgs e)
{
string username = ((RegisterEventArgs)e).Username;
string password = ((RegisterEventArgs)e).Password;
string email = ((RegisterEventArgs)e).Email;
CheckReg_Handler(username, password, email);
return EventResult.Success;
}
private void RegButton_Click(object sender, EventArgs e)
{
Reg_Handler();
RegButton.Enabled = false;
if (!Reg_Handler()) RegButton.Enabled = true;
}
private void GoToLogin_Click(object sender, EventArgs e)