完善注册功能

This commit is contained in:
Mili 2023-03-05 23:09:09 +08:00
parent 387714288f
commit 14c4cdb48f
14 changed files with 370 additions and 271 deletions

View File

@ -219,4 +219,35 @@
FourStar, FourStar,
FiveStar 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
}
} }

View File

@ -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}'"; 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) public static string Delete_RegVerifyCode(string Username, string Email)
{ {

View File

@ -25,6 +25,16 @@
{ {
return $"{Select_Users} {Constant.Command_Where} {Column_Username} = '{Username}' and {Column_Password} = '{Password}'"; 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) public static string Select_Users_Where(string Where)
{ {
@ -33,14 +43,12 @@
public static string Update_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}' return $"{Constant.Command_Update} {TableName} {Constant.Command_Set} {Column_LastTime} = '{DateTime.Now}', {Column_LastIP} = '{IP}' {Constant.Command_Where} {Column_Username} = '{Username}'";
{Constant.Command_Where} {Column_Username} = '{Username}'";
} }
public static string Insert_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}) 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) public static string Select_CheckAutoKey(string Username, string AutoKey)

View File

@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Desktop.Controller
{ {
public class MainController : IMain public class MainController : IMain
{ {
public bool Connected => Do<bool>(MainSet.Connected); public bool Connected => Do<bool>(MainInvokeType.Connected);
private MainModel MainModel { get; } private MainModel MainModel { get; }
private Main Main { get; } private Main Main { get; }
@ -23,16 +23,16 @@ namespace Milimoe.FunGame.Desktop.Controller
/** /**
* Model的方法 * Model的方法
*/ */
private T Do<T>(string DoType, params object[] args) private T Do<T>(MainInvokeType DoType, params object[] args)
{ {
object result = new(); object result = new();
switch(DoType) switch(DoType)
{ {
case MainSet.GetServerConnection: case MainInvokeType.GetServerConnection:
result = MainModel.GetServerConnection(); result = MainModel.GetServerConnection();
break; break;
case MainSet.Connect: case MainInvokeType.Connect:
result = MainModel.Connect(); result = MainModel.Connect();
if ((ConnectResult)result != ConnectResult.Success) if ((ConnectResult)result != ConnectResult.Success)
{ {
@ -41,51 +41,51 @@ namespace Milimoe.FunGame.Desktop.Controller
} }
break; break;
case MainSet.Connected: case MainInvokeType.Connected:
result = MainModel.Connected; result = MainModel.Connected;
break; break;
case MainSet.Disconnect: case MainInvokeType.Disconnect:
Main.OnBeforeDisconnectEvent(new GeneralEventArgs()); Main.OnBeforeDisconnectEvent(new GeneralEventArgs());
MainModel.Disconnect(); MainModel.Disconnect();
break; break;
case MainSet.Disconnected: case MainInvokeType.Disconnected:
break; break;
case MainSet.WaitConnectAndSetYellow: case MainInvokeType.WaitConnectAndSetYellow:
break; break;
case MainSet.WaitLoginAndSetYellow: case MainInvokeType.WaitLoginAndSetYellow:
break; break;
case MainSet.SetGreenAndPing: case MainInvokeType.SetGreenAndPing:
break; break;
case MainSet.SetGreen: case MainInvokeType.SetGreen:
break; break;
case MainSet.SetYellow: case MainInvokeType.SetYellow:
break; break;
case MainSet.SetRed: case MainInvokeType.SetRed:
break; break;
case MainSet.LogOut: case MainInvokeType.LogOut:
Main.OnBeforeLogoutEvent(new GeneralEventArgs()); Main.OnBeforeLogoutEvent(new GeneralEventArgs());
result = MainModel.LogOut(); result = MainModel.LogOut();
break; break;
case MainSet.Close: case MainInvokeType.Close:
result = MainModel.Close(); result = MainModel.Close();
break; break;
case MainSet.IntoRoom: case MainInvokeType.IntoRoom:
Main.OnBeforeIntoRoomEvent(new GeneralEventArgs()); Main.OnBeforeIntoRoomEvent(new GeneralEventArgs());
result = MainModel.IntoRoom(); result = MainModel.IntoRoom();
break; break;
case MainSet.Chat: case MainInvokeType.Chat:
Main.OnBeforeSendTalkEvent(new GeneralEventArgs()); Main.OnBeforeSendTalkEvent(new GeneralEventArgs());
if (args != null && args.Length > 0) if (args != null && args.Length > 0)
result = MainModel.Chat((string)args[0]); result = MainModel.Chat((string)args[0]);
@ -99,22 +99,22 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool GetServerConnection() public bool GetServerConnection()
{ {
return Do<bool>(MainSet.GetServerConnection); return Do<bool>(MainInvokeType.GetServerConnection);
} }
public ConnectResult Connect() public ConnectResult Connect()
{ {
return Do<ConnectResult>(MainSet.Connect); return Do<ConnectResult>(MainInvokeType.Connect);
} }
public void Disconnect() public void Disconnect()
{ {
Do<object>(MainSet.Disconnect); Do<object>(MainInvokeType.Disconnect);
} }
public void Disconnected() public void Disconnected()
{ {
Do<object>(MainSet.Disconnected); Do<object>(MainInvokeType.Disconnected);
} }
public void SetWaitConnectAndSetYellow() public void SetWaitConnectAndSetYellow()
@ -149,22 +149,22 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool LogOut() public bool LogOut()
{ {
return Do<bool>(MainSet.LogOut); return Do<bool>(MainInvokeType.LogOut);
} }
public bool Close() public bool Close()
{ {
return Do<bool>(MainSet.Close); return Do<bool>(MainInvokeType.Close);
} }
public bool IntoRoom() public bool IntoRoom()
{ {
return Do<bool>(MainSet.IntoRoom); return Do<bool>(MainInvokeType.IntoRoom);
} }
public bool Chat(string msg) public bool Chat(string msg)
{ {
return Do<bool>(MainSet.Chat, msg); return Do<bool>(MainInvokeType.Chat, msg);
} }
} }
} }

View File

@ -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.Library;
using Milimoe.FunGame.Desktop.Model; using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.UI;
namespace Milimoe.FunGame.Desktop.Controller namespace Milimoe.FunGame.Desktop.Controller
{ {
public class RegisterController 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); public RegisterController(Register reg)
bool result = RegisterModel.Reg(objs); {
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) if (!result)
{ {
ShowMessage.ErrorMessage("注册失败!!", "注册失败", 5); ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs); Register.OnFailedRegEvent(Register.EventArgs);
} }
return result; 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) if (!result)
{ {
ShowMessage.ErrorMessage("注册失败!", "注册失败", 5); ShowMessage.ErrorMessage("注册失败!", "注册失败", 5);
if (RunTime.Register != null) RunTime.Register.OnFailedRegEvent(RunTime.Register.EventArgs); RunTime.Register?.OnFailedRegEvent(Register.EventArgs);
} }
return result; return result;
} }

View File

@ -56,6 +56,7 @@ namespace Milimoe.FunGame.Desktop.Library.Component
/// </summary> /// </summary>
protected virtual void FormClosedEvent(object? sender, FormClosedEventArgs e) protected virtual void FormClosedEvent(object? sender, FormClosedEventArgs e)
{ {
Dispose();
if (GetType() == typeof(ShowMessage)) if (GetType() == typeof(ShowMessage))
{ {
return; return;

View File

@ -160,21 +160,21 @@ namespace Milimoe.FunGame.Desktop.Library.Component
public static MessageResult TipMessage(string msg, string? title = null, int autoclose = 0) 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; MessageResult result = new ShowMessage(objs).MessageResult;
return result; return result;
} }
public static MessageResult WarningMessage(string msg, string? title = null, int autoclose = 0) 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; MessageResult result = new ShowMessage(objs).MessageResult;
return result; return result;
} }
public static MessageResult ErrorMessage(string msg, string? title = null, int autoclose = 0) 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; MessageResult result = new ShowMessage(objs).MessageResult;
return result; return result;
} }
@ -202,14 +202,14 @@ namespace Milimoe.FunGame.Desktop.Library.Component
public static string InputMessage(string msg, string title) 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; string result = new ShowMessage(objs).InputResult;
return result; return result;
} }
public static string InputMessageCancel(string msg, string title, out MessageResult cancel) 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); ShowMessage window = new ShowMessage(objs);
string result = window.InputResult; string result = window.InputResult;
cancel = window.MessageResult; cancel = window.MessageResult;

View File

@ -3,49 +3,6 @@ using Milimoe.FunGame.Core.Library.Constant;
namespace Milimoe.FunGame.Desktop.Library 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 public class Constant
{ {
/** /**

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

View File

@ -149,7 +149,7 @@ namespace Milimoe.FunGame.Desktop.Model
if (Receiving() == SocketMessageType.Connect) if (Receiving() == SocketMessageType.Connect)
{ {
Main.GetMessage("连接服务器成功请登录账号以体验FunGame。"); Main.GetMessage("连接服务器成功请登录账号以体验FunGame。");
Main.UpdateUI(MainSet.Connected); Main.UpdateUI(MainInvokeType.Connected);
StartReceiving(); StartReceiving();
while (true) while (true)
{ {
@ -178,7 +178,7 @@ namespace Milimoe.FunGame.Desktop.Model
catch (Exception e) catch (Exception e)
{ {
Main.GetMessage(e.GetErrorInfo(), TimeType.None); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
Main.UpdateUI(MainSet.SetRed); Main.UpdateUI(MainInvokeType.SetRed);
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
Task.Factory.StartNew(() => Task.Factory.StartNew(() =>
{ {
@ -344,7 +344,7 @@ namespace Milimoe.FunGame.Desktop.Model
case SocketMessageType.HeartBeat: case SocketMessageType.HeartBeat:
if (Socket.Connected && Usercfg.LoginUser != null) if (Socket.Connected && Usercfg.LoginUser != null)
Main.UpdateUI(MainSet.SetGreenAndPing); Main.UpdateUI(MainInvokeType.SetGreenAndPing);
break; break;
case SocketMessageType.IntoRoom: case SocketMessageType.IntoRoom:
@ -359,10 +359,8 @@ namespace Milimoe.FunGame.Desktop.Model
break; break;
case SocketMessageType.Reg: case SocketMessageType.Reg:
break;
case SocketMessageType.CheckReg: case SocketMessageType.CheckReg:
SocketHandler_CheckReg(objs); RunTime.Register?.SocketHandler(type, objs);
break; break;
case SocketMessageType.Unknown: case SocketMessageType.Unknown:
@ -374,7 +372,7 @@ namespace Milimoe.FunGame.Desktop.Model
{ {
// 报错中断服务器连接 // 报错中断服务器连接
Main.GetMessage(e.GetErrorInfo(), TimeType.None); Main.GetMessage(e.GetErrorInfo(), TimeType.None);
Main.UpdateUI(MainSet.Disconnected); Main.UpdateUI(MainInvokeType.Disconnected);
Main.OnFailedConnectEvent(new GeneralEventArgs()); Main.OnFailedConnectEvent(new GeneralEventArgs());
Close(); Close();
} }
@ -400,7 +398,7 @@ namespace Milimoe.FunGame.Desktop.Model
Config.Guid_Socket = token; Config.Guid_Socket = token;
Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n"); Main.GetMessage($"已连接服务器:{ServerName}。\n\n********** 服务器公告 **********\n\n{ServerNotice}\n\n");
// 设置等待登录的黄灯 // 设置等待登录的黄灯
Main.UpdateUI(MainSet.WaitLoginAndSetYellow); Main.UpdateUI(MainInvokeType.WaitLoginAndSetYellow);
} }
private void SocketHandler_GetNotice(object[] objs) private void SocketHandler_GetNotice(object[] objs)
@ -448,7 +446,7 @@ namespace Milimoe.FunGame.Desktop.Model
if (key != Guid.Empty) if (key != Guid.Empty)
{ {
Config.Guid_LoginKey = Guid.Empty; Config.Guid_LoginKey = Guid.Empty;
Main.UpdateUI(MainSet.LogOut, msg ?? ""); Main.UpdateUI(MainInvokeType.LogOut, msg ?? "");
Main.OnSucceedLogoutEvent(new GeneralEventArgs()); Main.OnSucceedLogoutEvent(new GeneralEventArgs());
} }
else else
@ -465,7 +463,7 @@ namespace Milimoe.FunGame.Desktop.Model
if (objs != null && objs.Length > 0) if (objs != null && objs.Length > 0)
{ {
// 创建User对象并返回到Main // 创建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()); RunTime.Login?.OnSucceedLoginEvent(new GeneralEventArgs());
return; return;
} }
@ -478,7 +476,7 @@ namespace Milimoe.FunGame.Desktop.Model
string msg = ""; string msg = "";
if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!; if (objs.Length > 0) msg = NetworkUtility.ConvertJsonObject<string>(objs[0])!;
Main.GetMessage(msg); Main.GetMessage(msg);
Main.UpdateUI(MainSet.Disconnect); Main.UpdateUI(MainInvokeType.Disconnect);
Close(); Close();
Main.OnSucceedDisconnectEvent(new GeneralEventArgs()); Main.OnSucceedDisconnectEvent(new GeneralEventArgs());
Main.OnAfterDisconnectEvent(new GeneralEventArgs()); Main.OnAfterDisconnectEvent(new GeneralEventArgs());
@ -518,32 +516,6 @@ namespace Milimoe.FunGame.Desktop.Model
Main.OnAfterSendTalkEvent(new GeneralEventArgs()); 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 #endregion
} }
} }

View File

@ -2,12 +2,64 @@
using Milimoe.FunGame.Core.Library.Constant; 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.UI;
namespace Milimoe.FunGame.Desktop.Model namespace Milimoe.FunGame.Desktop.Model
{ {
public class RegisterModel 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 try
{ {
@ -31,7 +83,7 @@ namespace Milimoe.FunGame.Desktop.Model
return false; return false;
} }
public static bool CheckReg(params object[]? objs) public bool CheckReg(params object[]? objs)
{ {
try try
{ {

View File

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

View File

@ -93,129 +93,123 @@ namespace Milimoe.FunGame.Desktop.UI
/// </summary> /// </summary>
/// <param name="updatetype">string?</param> /// <param name="updatetype">string?</param>
/// <param name="objs">object[]?</param> /// <param name="objs">object[]?</param>
public void UpdateUI(string? updatetype, params object[]? objs) public void UpdateUI(MainInvokeType type, params object[]? objs)
{ {
void action() void action()
{ {
try try
{ {
if (updatetype != null) switch (type)
{ {
switch (updatetype) case MainInvokeType.SetGreen:
{ Config.FunGame_isRetrying = false;
case MainSet.SetGreen: SetServerStatusLight((int)LightType.Green);
Config.FunGame_isRetrying = false; SetButtonEnableIfLogon(true, ClientState.Online);
SetServerStatusLight((int)LightType.Green); Config.FunGame_isConnected = true;
SetButtonEnableIfLogon(true, ClientState.Online); CurrentRetryTimes = 0;
Config.FunGame_isConnected = true; break;
CurrentRetryTimes = 0;
break;
case MainSet.SetGreenAndPing: case MainInvokeType.SetGreenAndPing:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address)); SetServerStatusLight((int)LightType.Green, ping: NetworkUtility.GetServerPing(Constant.Server_Address));
SetButtonEnableIfLogon(true, ClientState.Online); SetButtonEnableIfLogon(true, ClientState.Online);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainSet.SetYellow: case MainInvokeType.SetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
break; break;
case MainSet.WaitConnectAndSetYellow: case MainInvokeType.WaitConnectAndSetYellow:
Config.FunGame_isRetrying = false; Config.FunGame_isRetrying = false;
SetServerStatusLight((int)LightType.Yellow); SetServerStatusLight((int)LightType.Yellow);
SetButtonEnableIfLogon(false, ClientState.WaitConnect); SetButtonEnableIfLogon(false, ClientState.WaitConnect);
Config.FunGame_isConnected = true; Config.FunGame_isConnected = true;
CurrentRetryTimes = 0; CurrentRetryTimes = 0;
if (MainController != null && Config.FunGame_isAutoConnect) 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))
{ {
// 自动连接服务器 WritelnSystemInfo((string)objs[0]);
MainController.Connect(); ShowMessage.Message((string)objs[0], "退出登录", 5);
} }
break; }
break;
case MainSet.WaitLoginAndSetYellow: case MainInvokeType.SetUser:
Config.FunGame_isRetrying = false; if (objs != null && objs.Length > 0)
SetServerStatusLight((int)LightType.Yellow, true); {
SetButtonEnableIfLogon(false, ClientState.WaitLogin); SetLoginUser(objs);
Config.FunGame_isConnected = true; }
CurrentRetryTimes = 0; break;
break;
case MainSet.SetRed: case MainInvokeType.Connected:
SetServerStatusLight((int)LightType.Red); NoticeText.Text = Config.FunGame_Notice;
SetButtonEnableIfLogon(false, ClientState.WaitConnect); break;
Config.FunGame_isConnected = false;
break;
case MainSet.Disconnected: default:
Config.FunGame_isRetrying = false; break;
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;
}
} }
} }
catch (Exception e) catch (Exception e)
{ {
WritelnGameInfo(e.GetErrorInfo()); WritelnGameInfo(e.GetErrorInfo());
UpdateUI(MainSet.SetRed); UpdateUI(MainInvokeType.SetRed);
} }
} }
InvokeUpdateUI(action); InvokeUpdateUI(action);
@ -635,7 +629,7 @@ namespace Milimoe.FunGame.Desktop.UI
NowAccount.Text = "[ID] " + Usercfg.LoginUserName; NowAccount.Text = "[ID] " + Usercfg.LoginUserName;
Login.Visible = false; Login.Visible = false;
Logout.Visible = true; Logout.Visible = true;
UpdateUI(MainSet.SetGreenAndPing); UpdateUI(MainInvokeType.SetGreenAndPing);
RunTime.Login?.Close(); RunTime.Login?.Close();
Thread.Sleep(100); Thread.Sleep(100);
string welcome = $"欢迎回来, {Usercfg.LoginUserName}"; string welcome = $"欢迎回来, {Usercfg.LoginUserName}";

View File

@ -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.Constant;
using Milimoe.FunGame.Core.Library.Exception; using Milimoe.FunGame.Core.Library.Exception;
using Milimoe.FunGame.Desktop.Controller; using Milimoe.FunGame.Desktop.Controller;
@ -14,16 +15,18 @@ namespace Milimoe.FunGame.Desktop.UI
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();
private readonly RegisterController RegController;
public Register() public Register()
{ {
InitializeComponent(); InitializeComponent();
RegController = new RegisterController(this);
} }
protected override void BindEvent() protected override void BindEvent()
{ {
base.BindEvent(); base.BindEvent();
SucceedReg += SucceedRegEvent; SucceedReg += SucceedRegEvent;
FailedReg += FailedRegEvent;
} }
private bool Reg_Handler() private bool Reg_Handler()
@ -34,36 +37,59 @@ namespace Milimoe.FunGame.Desktop.UI
string password = PasswordText.Text.Trim(); string password = PasswordText.Text.Trim();
string checkpassword = CheckPasswordText.Text.Trim(); string checkpassword = CheckPasswordText.Text.Trim();
string email = EmailText.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 == "") if (username == "" || password == "" || checkpassword == "")
{ {
ShowMessage.ErrorMessage("账号或密码不能为空!"); ShowMessage.ErrorMessage("请将账号和密码填写完整");
UsernameText.Focus(); UsernameText.Focus();
return false; return false;
} }
if (password != checkpassword)
{
ShowMessage.ErrorMessage("两个密码不相同,请重新输入!");
CheckPasswordText.Focus();
return false;
}
if (email == "") if (email == "")
{ {
ShowMessage.ErrorMessage("邮箱不能为空!"); ShowMessage.ErrorMessage("邮箱不能为空!");
UsernameText.Focus(); EmailText.Focus();
return false;
}
if (!NetworkUtility.IsEmail(email))
{
ShowMessage.ErrorMessage("这不是一个邮箱地址!");
EmailText.Focus();
return false; return false;
} }
EventArgs = new RegisterEventArgs(username, password, email); EventArgs = new RegisterEventArgs(username, password, email);
if (!RegisterController.Reg(username, email)) if (!RegController.Reg(username, email))
{ {
ShowMessage.Message("注册失败!!", "注册失败"); ShowMessage.Message("注册失败!", "注册失败");
return false; return false;
} }
else
{
CheckReg = false;
// 成功发送注册请求后
CheckReg_Handler(username, password, email);
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -73,17 +99,43 @@ namespace Milimoe.FunGame.Desktop.UI
return true; 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); void Action()
if (cancel == MessageResult.Cancel)
{ {
CheckReg = true; switch (type)
RegButton.Enabled = true; {
} case RegInvokeType.InputVerifyCode:
RegisterController.CheckReg(username, password, email, verifycode); 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 username = ((RegisterEventArgs)e).Username;
string password = ((RegisterEventArgs)e).Password; string password = ((RegisterEventArgs)e).Password;
if (LoginController.LoginAccount(username, password)) if (LoginController.LoginAccount(username, password)) Close();
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; return EventResult.Success;
} }