mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
完善注册功能
This commit is contained in:
parent
387714288f
commit
14c4cdb48f
@ -219,4 +219,35 @@
|
||||
FourStar,
|
||||
FiveStar
|
||||
}
|
||||
|
||||
public enum MainInvokeType
|
||||
{
|
||||
None,
|
||||
SetGreen,
|
||||
SetGreenAndPing,
|
||||
SetRed,
|
||||
SetYellow,
|
||||
WaitConnectAndSetYellow,
|
||||
WaitLoginAndSetYellow,
|
||||
Disconnect,
|
||||
Disconnected,
|
||||
LogOut,
|
||||
LogIn,
|
||||
SetUser,
|
||||
Connected,
|
||||
Connect,
|
||||
GetServerConnection,
|
||||
Close,
|
||||
IntoRoom,
|
||||
Chat,
|
||||
QuitRoom
|
||||
}
|
||||
|
||||
public enum RegInvokeType
|
||||
{
|
||||
None,
|
||||
DuplicateUserName,
|
||||
DuplicateEmail,
|
||||
InputVerifyCode
|
||||
}
|
||||
}
|
||||
|
||||
@ -52,6 +52,11 @@ 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 Select_HasSentRegVerifyCode(string Username, string Email)
|
||||
{
|
||||
return $"{Constant.Command_Select} {Constant.Command_All} {Constant.Command_From} {TableName} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Email} = '{Email}'";
|
||||
}
|
||||
|
||||
public static string Delete_RegVerifyCode(string Username, string Email)
|
||||
{
|
||||
|
||||
@ -25,6 +25,16 @@
|
||||
{
|
||||
return $"{Select_Users} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Password} = '{Password}'";
|
||||
}
|
||||
|
||||
public static string Select_DuplicateEmail(string Email)
|
||||
{
|
||||
return $"{Select_Users} {Constant.Command_Where} {Column_Email} = '{Email}'";
|
||||
}
|
||||
|
||||
public static string Select_DuplicateUsername(string Username)
|
||||
{
|
||||
return $"{Select_Users} {Constant.Command_Where} {Column_Username} = '{Username}'";
|
||||
}
|
||||
|
||||
public static string Select_Users_Where(string Where)
|
||||
{
|
||||
@ -33,14 +43,12 @@
|
||||
|
||||
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}'";
|
||||
return $"{Constant.Command_Update} {TableName} {Constant.Command_Set} {Column_LastTime} = '{DateTime.Now}', {Column_LastIP} = '{IP}' {Constant.Command_Where} {Column_Username} = '{Username}'";
|
||||
}
|
||||
|
||||
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}')";
|
||||
return $"{Constant.Command_Insert} {Constant.Command_Into} {TableName} ({Column_Username}, {Column_Password}, {Column_Email}, {Column_RegTime}) {Constant.Command_Values} ('{Username}', '{Password}', '{Email}', '{DateTime.Now}')";
|
||||
}
|
||||
|
||||
public static string Select_CheckAutoKey(string Username, string AutoKey)
|
||||
|
||||
@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
public class MainController : IMain
|
||||
{
|
||||
public bool Connected => Do<bool>(MainSet.Connected);
|
||||
public bool Connected => Do<bool>(MainInvokeType.Connected);
|
||||
|
||||
private MainModel MainModel { get; }
|
||||
private Main Main { get; }
|
||||
@ -23,16 +23,16 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
/**
|
||||
* 从内部去调用Model的方法,并记录日志。
|
||||
*/
|
||||
private T Do<T>(string DoType, params object[] args)
|
||||
private T Do<T>(MainInvokeType DoType, params object[] args)
|
||||
{
|
||||
object result = new();
|
||||
switch(DoType)
|
||||
{
|
||||
case MainSet.GetServerConnection:
|
||||
case MainInvokeType.GetServerConnection:
|
||||
result = MainModel.GetServerConnection();
|
||||
break;
|
||||
|
||||
case MainSet.Connect:
|
||||
case MainInvokeType.Connect:
|
||||
result = MainModel.Connect();
|
||||
if ((ConnectResult)result != ConnectResult.Success)
|
||||
{
|
||||
@ -41,51 +41,51 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
}
|
||||
break;
|
||||
|
||||
case MainSet.Connected:
|
||||
case MainInvokeType.Connected:
|
||||
result = MainModel.Connected;
|
||||
break;
|
||||
|
||||
case MainSet.Disconnect:
|
||||
case MainInvokeType.Disconnect:
|
||||
Main.OnBeforeDisconnectEvent(new GeneralEventArgs());
|
||||
MainModel.Disconnect();
|
||||
break;
|
||||
|
||||
case MainSet.Disconnected:
|
||||
case MainInvokeType.Disconnected:
|
||||
break;
|
||||
|
||||
case MainSet.WaitConnectAndSetYellow:
|
||||
case MainInvokeType.WaitConnectAndSetYellow:
|
||||
break;
|
||||
|
||||
case MainSet.WaitLoginAndSetYellow:
|
||||
case MainInvokeType.WaitLoginAndSetYellow:
|
||||
break;
|
||||
|
||||
case MainSet.SetGreenAndPing:
|
||||
case MainInvokeType.SetGreenAndPing:
|
||||
break;
|
||||
|
||||
case MainSet.SetGreen:
|
||||
case MainInvokeType.SetGreen:
|
||||
break;
|
||||
|
||||
case MainSet.SetYellow:
|
||||
case MainInvokeType.SetYellow:
|
||||
break;
|
||||
|
||||
case MainSet.SetRed:
|
||||
case MainInvokeType.SetRed:
|
||||
break;
|
||||
|
||||
case MainSet.LogOut:
|
||||
case MainInvokeType.LogOut:
|
||||
Main.OnBeforeLogoutEvent(new GeneralEventArgs());
|
||||
result = MainModel.LogOut();
|
||||
break;
|
||||
|
||||
case MainSet.Close:
|
||||
case MainInvokeType.Close:
|
||||
result = MainModel.Close();
|
||||
break;
|
||||
|
||||
case MainSet.IntoRoom:
|
||||
case MainInvokeType.IntoRoom:
|
||||
Main.OnBeforeIntoRoomEvent(new GeneralEventArgs());
|
||||
result = MainModel.IntoRoom();
|
||||
break;
|
||||
|
||||
case MainSet.Chat:
|
||||
case MainInvokeType.Chat:
|
||||
Main.OnBeforeSendTalkEvent(new GeneralEventArgs());
|
||||
if (args != null && args.Length > 0)
|
||||
result = MainModel.Chat((string)args[0]);
|
||||
@ -99,22 +99,22 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
|
||||
public bool GetServerConnection()
|
||||
{
|
||||
return Do<bool>(MainSet.GetServerConnection);
|
||||
return Do<bool>(MainInvokeType.GetServerConnection);
|
||||
}
|
||||
|
||||
public ConnectResult Connect()
|
||||
{
|
||||
return Do<ConnectResult>(MainSet.Connect);
|
||||
return Do<ConnectResult>(MainInvokeType.Connect);
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
Do<object>(MainSet.Disconnect);
|
||||
Do<object>(MainInvokeType.Disconnect);
|
||||
}
|
||||
|
||||
public void Disconnected()
|
||||
{
|
||||
Do<object>(MainSet.Disconnected);
|
||||
Do<object>(MainInvokeType.Disconnected);
|
||||
}
|
||||
|
||||
public void SetWaitConnectAndSetYellow()
|
||||
@ -149,22 +149,22 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
|
||||
public bool LogOut()
|
||||
{
|
||||
return Do<bool>(MainSet.LogOut);
|
||||
return Do<bool>(MainInvokeType.LogOut);
|
||||
}
|
||||
|
||||
public bool Close()
|
||||
{
|
||||
return Do<bool>(MainSet.Close);
|
||||
return Do<bool>(MainInvokeType.Close);
|
||||
}
|
||||
|
||||
public bool IntoRoom()
|
||||
{
|
||||
return Do<bool>(MainSet.IntoRoom);
|
||||
return Do<bool>(MainInvokeType.IntoRoom);
|
||||
}
|
||||
|
||||
public bool Chat(string msg)
|
||||
{
|
||||
return Do<bool>(MainSet.Chat, msg);
|
||||
return Do<bool>(MainInvokeType.Chat, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,32 +1,46 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
public class RegisterController
|
||||
{
|
||||
public static bool Reg(params object[]? objs)
|
||||
{
|
||||
private readonly Register Register;
|
||||
private readonly RegisterModel RegModel;
|
||||
|
||||
if (RunTime.Register != null) RunTime.Register.OnBeforeRegEvent(RunTime.Register.EventArgs);
|
||||
bool result = RegisterModel.Reg(objs);
|
||||
public RegisterController(Register reg)
|
||||
{
|
||||
Register = reg;
|
||||
RegModel = new RegisterModel(reg);
|
||||
}
|
||||
|
||||
public void SocketHandler(SocketMessageType type, params object[]? objs)
|
||||
{
|
||||
RegModel.SocketHandler(type, objs);
|
||||
}
|
||||
|
||||
public bool Reg(params object[]? objs)
|
||||
{
|
||||
Register.OnBeforeRegEvent(Register.EventArgs);
|
||||
bool result = RegModel.Reg(objs);
|
||||
if (!result)
|
||||
{
|
||||
ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5);
|
||||
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs);
|
||||
ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
|
||||
Register.OnFailedRegEvent(Register.EventArgs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool CheckReg(params object[]? objs)
|
||||
public bool CheckReg(params object[]? objs)
|
||||
{
|
||||
bool result = RegisterModel.CheckReg(objs);
|
||||
bool result = RegModel.CheckReg(objs);
|
||||
if (!result)
|
||||
{
|
||||
ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5);
|
||||
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs);
|
||||
ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
|
||||
RunTime.Register?.OnFailedRegEvent(Register.EventArgs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -56,6 +56,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
|
||||
/// </summary>
|
||||
protected virtual void FormClosedEvent(object? sender, FormClosedEventArgs e)
|
||||
{
|
||||
Dispose();
|
||||
if (GetType() == typeof(ShowMessage))
|
||||
{
|
||||
return;
|
||||
|
||||
@ -160,21 +160,21 @@ namespace Milimoe.FunGame.Desktop.Library.Component
|
||||
|
||||
public static MessageResult TipMessage(string msg, string? title = null, int autoclose = 0)
|
||||
{
|
||||
object[] objs = { (title != null) ? title : TITLE_TIP, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
object[] objs = { title ?? TITLE_TIP, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
MessageResult result = new ShowMessage(objs).MessageResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static MessageResult WarningMessage(string msg, string? title = null, int autoclose = 0)
|
||||
{
|
||||
object[] objs = { (title != null) ? title : TITLE_WARNING, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
object[] objs = { title ?? TITLE_WARNING, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
MessageResult result = new ShowMessage(objs).MessageResult;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static MessageResult ErrorMessage(string msg, string? title = null, int autoclose = 0)
|
||||
{
|
||||
object[] objs = { (title != null) ? title : TITLE_ERROR, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
object[] objs = { title ?? TITLE_ERROR, msg, autoclose, MessageButtonType.OK, BUTTON_OK };
|
||||
MessageResult result = new ShowMessage(objs).MessageResult;
|
||||
return result;
|
||||
}
|
||||
@ -202,14 +202,14 @@ namespace Milimoe.FunGame.Desktop.Library.Component
|
||||
|
||||
public static string InputMessage(string msg, string title)
|
||||
{
|
||||
object[] objs = { title, msg, 0, MessageButtonType.Input, BUTTON_CANCEL, BUTTON_RETRY, BUTTON_CANCEL };
|
||||
object[] objs = { title, msg, 0, MessageButtonType.Input };
|
||||
string result = new ShowMessage(objs).InputResult;
|
||||
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 };
|
||||
object[] objs = { title, msg, 0, MessageButtonType.Input };
|
||||
ShowMessage window = new ShowMessage(objs);
|
||||
string result = window.InputResult;
|
||||
cancel = window.MessageResult;
|
||||
|
||||
@ -3,49 +3,6 @@ using Milimoe.FunGame.Core.Library.Constant;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Library
|
||||
{
|
||||
public class MainSet
|
||||
{
|
||||
public const string SetGreen = ".set green";
|
||||
public const string SetGreenAndPing = ".set greenandping";
|
||||
public const string SetRed = ".set red";
|
||||
public const string SetYellow = ".set yellow";
|
||||
public const string WaitConnectAndSetYellow = ".waitconnect .set yellow";
|
||||
public const string WaitLoginAndSetYellow = ".waitlogin .set yellow";
|
||||
public const string Disconnect = ".disconnect";
|
||||
public const string Disconnected = ".disconnected";
|
||||
public const string LogOut = ".logout";
|
||||
public const string LogIn = ".login";
|
||||
public const string SetUser = ".set user";
|
||||
public const string Connected = ".connected";
|
||||
public const string Connect = ".connect";
|
||||
public const string GetServerConnection = ".getserverconnection";
|
||||
public const string Close = ".close";
|
||||
public const string IntoRoom = ".intoroom";
|
||||
public const string Chat = ".chat";
|
||||
public const string QuitRoom = ".quitroom";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行时单例
|
||||
/// 插件接口可以从这里拿Socket和窗体
|
||||
/// </summary>
|
||||
public class RunTime
|
||||
{
|
||||
public static Core.Library.Common.Network.Socket? Socket { get; set; } = null;
|
||||
public static UI.Main? Main { get; set; } = null;
|
||||
public static UI.Login? Login { get; set; } = null;
|
||||
public static UI.Register? Register { get; set; } = null;
|
||||
public static UI.StoreUI? Store { get; set; } = null;
|
||||
public static UI.InventoryUI? Inventory { get; set; } = null;
|
||||
public static UI.RoomSetting? RoomSetting { get; set; } = null;
|
||||
public static UI.UserCenter? UserCenter { get; set; } = null;
|
||||
|
||||
public static void WritelnSystemInfo(string msg)
|
||||
{
|
||||
Main?.GetMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public class Constant
|
||||
{
|
||||
/**
|
||||
|
||||
23
FunGame.Desktop/Library/Config/RunTime.cs
Normal file
23
FunGame.Desktop/Library/Config/RunTime.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace Milimoe.FunGame.Desktop.Library
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行时单例
|
||||
/// 插件接口可以从这里拿Socket和窗体
|
||||
/// </summary>
|
||||
public class RunTime
|
||||
{
|
||||
public static Core.Library.Common.Network.Socket? Socket { get; set; } = null;
|
||||
public static UI.Main? Main { get; set; } = null;
|
||||
public static UI.Login? Login { get; set; } = null;
|
||||
public static UI.Register? Register { get; set; } = null;
|
||||
public static UI.StoreUI? Store { get; set; } = null;
|
||||
public static UI.InventoryUI? Inventory { get; set; } = null;
|
||||
public static UI.RoomSetting? RoomSetting { get; set; } = null;
|
||||
public static UI.UserCenter? UserCenter { get; set; } = null;
|
||||
|
||||
public static void WritelnSystemInfo(string msg)
|
||||
{
|
||||
Main?.GetMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -149,7 +149,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
if (Receiving() == SocketMessageType.Connect)
|
||||
{
|
||||
Main.GetMessage("连接服务器成功,请登录账号以体验FunGame。");
|
||||
Main.UpdateUI(MainSet.Connected);
|
||||
Main.UpdateUI(MainInvokeType.Connected);
|
||||
StartReceiving();
|
||||
while (true)
|
||||
{
|
||||
@ -178,7 +178,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
catch (Exception e)
|
||||
{
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
Main.UpdateUI(MainSet.SetRed);
|
||||
Main.UpdateUI(MainInvokeType.SetRed);
|
||||
Config.FunGame_isRetrying = false;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
@ -344,7 +344,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
|
||||
case SocketMessageType.HeartBeat:
|
||||
if (Socket.Connected && Usercfg.LoginUser != null)
|
||||
Main.UpdateUI(MainSet.SetGreenAndPing);
|
||||
Main.UpdateUI(MainInvokeType.SetGreenAndPing);
|
||||
break;
|
||||
|
||||
case SocketMessageType.IntoRoom:
|
||||
@ -359,10 +359,8 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
break;
|
||||
|
||||
case SocketMessageType.Reg:
|
||||
break;
|
||||
|
||||
case SocketMessageType.CheckReg:
|
||||
SocketHandler_CheckReg(objs);
|
||||
RunTime.Register?.SocketHandler(type, objs);
|
||||
break;
|
||||
|
||||
case SocketMessageType.Unknown:
|
||||
@ -374,7 +372,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
// 报错中断服务器连接
|
||||
Main.GetMessage(e.GetErrorInfo(), TimeType.None);
|
||||
Main.UpdateUI(MainSet.Disconnected);
|
||||
Main.UpdateUI(MainInvokeType.Disconnected);
|
||||
Main.OnFailedConnectEvent(new GeneralEventArgs());
|
||||
Close();
|
||||
}
|
||||
@ -400,7 +398,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
Config.Guid_Socket = token;
|
||||
Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
|
||||
// 设置等待登录的黄灯
|
||||
Main.UpdateUI(MainSet.WaitLoginAndSetYellow);
|
||||
Main.UpdateUI(MainInvokeType.WaitLoginAndSetYellow);
|
||||
}
|
||||
|
||||
private void SocketHandler_GetNotice(object[] objs)
|
||||
@ -448,7 +446,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
if (key != Guid.Empty)
|
||||
{
|
||||
Config.Guid_LoginKey = Guid.Empty;
|
||||
Main.UpdateUI(MainSet.LogOut, msg ?? "");
|
||||
Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
|
||||
Main.OnSucceedLogoutEvent(new GeneralEventArgs());
|
||||
}
|
||||
else
|
||||
@ -465,7 +463,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
// 创建User对象并返回到Main
|
||||
Main.UpdateUI(MainSet.SetUser, new object[] { Factory.New<User>(objs) });
|
||||
Main.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.New<User>(objs) });
|
||||
RunTime.Login?.OnSucceedLoginEvent(new GeneralEventArgs());
|
||||
return;
|
||||
}
|
||||
@ -478,7 +476,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
string msg = "";
|
||||
if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!;
|
||||
Main.GetMessage(msg);
|
||||
Main.UpdateUI(MainSet.Disconnect);
|
||||
Main.UpdateUI(MainInvokeType.Disconnect);
|
||||
Close();
|
||||
Main.OnSucceedDisconnectEvent(new GeneralEventArgs());
|
||||
Main.OnAfterDisconnectEvent(new GeneralEventArgs());
|
||||
@ -518,32 +516,6 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,12 +2,64 @@
|
||||
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.UI;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
public class RegisterModel
|
||||
{
|
||||
public static bool Reg(params object[]? objs)
|
||||
private readonly Register Register;
|
||||
|
||||
public RegisterModel(Register reg)
|
||||
{
|
||||
Register = reg;
|
||||
}
|
||||
|
||||
public void SocketHandler(SocketMessageType type, params object[]? objs)
|
||||
{
|
||||
try
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SocketMessageType.Reg:
|
||||
RegInvokeType invokeType = RegInvokeType.None;
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
invokeType = NetworkUtility.ConvertJsonObject<RegInvokeType>(objs[0]);
|
||||
Register.UpdateUI(invokeType);
|
||||
}
|
||||
break;
|
||||
case SocketMessageType.CheckReg:
|
||||
SocketHandler_CheckReg(objs);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private void SocketHandler_CheckReg(params 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)
|
||||
{
|
||||
Register.OnSucceedRegEvent(Register.EventArgs);
|
||||
Register.OnAfterRegEvent(Register.EventArgs);
|
||||
}
|
||||
}
|
||||
Register.OnFailedRegEvent(Register.EventArgs);
|
||||
Register.OnAfterRegEvent(Register.EventArgs);
|
||||
Register.UpdateUI(RegInvokeType.InputVerifyCode);
|
||||
}
|
||||
|
||||
public bool Reg(params object[]? objs)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -31,7 +83,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool CheckReg(params object[]? objs)
|
||||
public bool CheckReg(params object[]? objs)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@ -86,7 +86,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
|
||||
private EventResult SucceedLoginEvent(object sender, GeneralEventArgs e)
|
||||
{
|
||||
Dispose();
|
||||
Close();
|
||||
RunTime.Main?.OnSucceedLoginEvent(e);
|
||||
return EventResult.Success;
|
||||
}
|
||||
|
||||
@ -93,129 +93,123 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// </summary>
|
||||
/// <param name="updatetype">string?</param>
|
||||
/// <param name="objs">object[]?</param>
|
||||
public void UpdateUI(string? updatetype, params object[]? objs)
|
||||
public void UpdateUI(MainInvokeType type, params object[]? objs)
|
||||
{
|
||||
void action()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updatetype != null)
|
||||
switch (type)
|
||||
{
|
||||
switch (updatetype)
|
||||
{
|
||||
case MainSet.SetGreen:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Green);
|
||||
SetButtonEnableIfLogon(true, ClientState.Online);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
case MainInvokeType.SetGreen:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Green);
|
||||
SetButtonEnableIfLogon(true, ClientState.Online);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
|
||||
case MainSet.SetGreenAndPing:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
|
||||
SetButtonEnableIfLogon(true, ClientState.Online);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
case MainInvokeType.SetGreenAndPing:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
|
||||
SetButtonEnableIfLogon(true, ClientState.Online);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
|
||||
case MainSet.SetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
case MainInvokeType.SetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
|
||||
case MainSet.WaitConnectAndSetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
if (MainController != null && Config.FunGame_isAutoConnect)
|
||||
case MainInvokeType.WaitConnectAndSetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
if (MainController != null && Config.FunGame_isAutoConnect)
|
||||
{
|
||||
// 自动连接服务器
|
||||
MainController.Connect();
|
||||
}
|
||||
break;
|
||||
|
||||
case MainInvokeType.WaitLoginAndSetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow, true);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitLogin);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
|
||||
case MainInvokeType.SetRed:
|
||||
SetServerStatusLight((int)LightType.Red);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = false;
|
||||
break;
|
||||
|
||||
case MainInvokeType.Disconnected:
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isConnected = false;
|
||||
SetServerStatusLight((int)LightType.Red);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
LogoutAccount();
|
||||
CloseConnectedWindows();
|
||||
break;
|
||||
|
||||
case MainInvokeType.Disconnect:
|
||||
Config.FunGame_isAutoRetry = false;
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isAutoConnect = false;
|
||||
Config.FunGame_isAutoLogin = false;
|
||||
Config.FunGame_isConnected = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
LogoutAccount();
|
||||
break;
|
||||
|
||||
case MainInvokeType.LogIn:
|
||||
break;
|
||||
|
||||
case MainInvokeType.LogOut:
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isAutoLogin = false;
|
||||
SetServerStatusLight((int)LightType.Yellow, true);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitLogin);
|
||||
LogoutAccount();
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
if (objs[0].GetType() == typeof(string))
|
||||
{
|
||||
// 自动连接服务器
|
||||
MainController.Connect();
|
||||
WritelnSystemInfo((string)objs[0]);
|
||||
ShowMessage.Message((string)objs[0], "退出登录", 5);
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case MainSet.WaitLoginAndSetYellow:
|
||||
Config.FunGame_isRetrying = false;
|
||||
SetServerStatusLight((int)LightType.Yellow, true);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitLogin);
|
||||
Config.FunGame_isConnected = true;
|
||||
CurrentRetryTimes = 0;
|
||||
break;
|
||||
case MainInvokeType.SetUser:
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
SetLoginUser(objs);
|
||||
}
|
||||
break;
|
||||
|
||||
case MainSet.SetRed:
|
||||
SetServerStatusLight((int)LightType.Red);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
Config.FunGame_isConnected = false;
|
||||
break;
|
||||
case MainInvokeType.Connected:
|
||||
NoticeText.Text = Config.FunGame_Notice;
|
||||
break;
|
||||
|
||||
case MainSet.Disconnected:
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isConnected = false;
|
||||
SetServerStatusLight((int)LightType.Red);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
LogoutAccount();
|
||||
CloseConnectedWindows();
|
||||
break;
|
||||
|
||||
case MainSet.Disconnect:
|
||||
Config.FunGame_isAutoRetry = false;
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isAutoConnect = false;
|
||||
Config.FunGame_isAutoLogin = false;
|
||||
Config.FunGame_isConnected = false;
|
||||
SetServerStatusLight((int)LightType.Yellow);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitConnect);
|
||||
LogoutAccount();
|
||||
break;
|
||||
|
||||
case MainSet.LogIn:
|
||||
break;
|
||||
|
||||
case MainSet.LogOut:
|
||||
Config.FunGame_isRetrying = false;
|
||||
Config.FunGame_isAutoLogin = false;
|
||||
SetServerStatusLight((int)LightType.Yellow, true);
|
||||
SetButtonEnableIfLogon(false, ClientState.WaitLogin);
|
||||
LogoutAccount();
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
if (objs[0].GetType() == typeof(string))
|
||||
{
|
||||
WritelnSystemInfo((string)objs[0]);
|
||||
ShowMessage.Message((string)objs[0], "退出登录", 5);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MainSet.SetUser:
|
||||
if (objs != null && objs.Length > 0)
|
||||
{
|
||||
SetLoginUser(objs);
|
||||
}
|
||||
break;
|
||||
|
||||
case MainSet.Connected:
|
||||
NoticeText.Text = Config.FunGame_Notice;
|
||||
break;
|
||||
|
||||
default:
|
||||
// 直接调用UpdateUI(string)相当于调用GetMessage(string),输出该string到控制台。
|
||||
// 尽量避免使用除MainSet之外的string调用此方法
|
||||
WritelnSystemInfo(updatetype);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
WritelnGameInfo(e.GetErrorInfo());
|
||||
UpdateUI(MainSet.SetRed);
|
||||
UpdateUI(MainInvokeType.SetRed);
|
||||
}
|
||||
}
|
||||
InvokeUpdateUI(action);
|
||||
@ -635,7 +629,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
|
||||
Login.Visible = false;
|
||||
Logout.Visible = true;
|
||||
UpdateUI(MainSet.SetGreenAndPing);
|
||||
UpdateUI(MainInvokeType.SetGreenAndPing);
|
||||
RunTime.Login?.Close();
|
||||
Thread.Sleep(100);
|
||||
string welcome = $"欢迎回来, {Usercfg.LoginUserName}!";
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Core.Api.Utility;
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Milimoe.FunGame.Desktop.Controller;
|
||||
@ -14,16 +15,18 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
public bool CheckReg { get; set; } = false;
|
||||
public RegisterEventArgs EventArgs { get; set; } = new RegisterEventArgs();
|
||||
|
||||
private readonly RegisterController RegController;
|
||||
|
||||
public Register()
|
||||
{
|
||||
InitializeComponent();
|
||||
RegController = new RegisterController(this);
|
||||
}
|
||||
|
||||
protected override void BindEvent()
|
||||
{
|
||||
base.BindEvent();
|
||||
SucceedReg += SucceedRegEvent;
|
||||
FailedReg += FailedRegEvent;
|
||||
}
|
||||
|
||||
private bool Reg_Handler()
|
||||
@ -34,36 +37,59 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
string password = PasswordText.Text.Trim();
|
||||
string checkpassword = CheckPasswordText.Text.Trim();
|
||||
string email = EmailText.Text.Trim();
|
||||
if (username != "")
|
||||
{
|
||||
int length = General.DefaultEncoding.GetBytes(username).Length;
|
||||
if (length >= 3 && length <= 12) // 字节范围 3~12
|
||||
{
|
||||
if (password != checkpassword)
|
||||
{
|
||||
ShowMessage.ErrorMessage("两个密码不相同,请重新输入!");
|
||||
CheckPasswordText.Focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMessage.ErrorMessage("账号名长度不符合要求:2~6个字符数");
|
||||
UsernameText.Focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (password != "")
|
||||
{
|
||||
int length = password.Length;
|
||||
if (length >= 6 && length <= 15) // 字节范围 3~12
|
||||
{
|
||||
ShowMessage.ErrorMessage("密码长度不符合要求:6~15个字符数");
|
||||
PasswordText.Focus();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (username == "" || password == "" || checkpassword == "")
|
||||
{
|
||||
ShowMessage.ErrorMessage("账号或密码不能为空!");
|
||||
ShowMessage.ErrorMessage("请将账号和密码填写完整!");
|
||||
UsernameText.Focus();
|
||||
return false;
|
||||
}
|
||||
if (password != checkpassword)
|
||||
{
|
||||
ShowMessage.ErrorMessage("两个密码不相同,请重新输入!");
|
||||
CheckPasswordText.Focus();
|
||||
return false;
|
||||
}
|
||||
if (email == "")
|
||||
{
|
||||
ShowMessage.ErrorMessage("邮箱不能为空!");
|
||||
UsernameText.Focus();
|
||||
EmailText.Focus();
|
||||
return false;
|
||||
}
|
||||
if (!NetworkUtility.IsEmail(email))
|
||||
{
|
||||
ShowMessage.ErrorMessage("这不是一个邮箱地址!");
|
||||
EmailText.Focus();
|
||||
return false;
|
||||
}
|
||||
EventArgs = new RegisterEventArgs(username, password, email);
|
||||
if (!RegisterController.Reg(username, email))
|
||||
if (!RegController.Reg(username, email))
|
||||
{
|
||||
ShowMessage.Message("注册失败!!", "注册失败");
|
||||
ShowMessage.Message("注册失败!", "注册失败");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckReg = false;
|
||||
// 成功发送注册请求后
|
||||
CheckReg_Handler(username, password, email);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -73,17 +99,43 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckReg_Handler(string username, string password, string email)
|
||||
public void SocketHandler(SocketMessageType type, params object[]? objs)
|
||||
{
|
||||
if (!CheckReg)
|
||||
RegController.SocketHandler(type, objs);
|
||||
}
|
||||
|
||||
public void UpdateUI(RegInvokeType type)
|
||||
{
|
||||
try
|
||||
{
|
||||
string verifycode = ShowMessage.InputMessageCancel("请输入注册邮件中的6位数字验证码", "注册验证码", out MessageResult cancel);
|
||||
if (cancel == MessageResult.Cancel)
|
||||
void Action()
|
||||
{
|
||||
CheckReg = true;
|
||||
RegButton.Enabled = true;
|
||||
}
|
||||
RegisterController.CheckReg(username, password, email, verifycode);
|
||||
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 (InvokeRequired) Invoke(Action);
|
||||
else Action();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,17 +153,7 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
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);
|
||||
if (LoginController.LoginAccount(username, password)) Close();
|
||||
return EventResult.Success;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user