diff --git a/FunGame.Core/Api/Utility/General.cs b/FunGame.Core/Api/Utility/General.cs
index 031d1c8..d5fa8bd 100644
--- a/FunGame.Core/Api/Utility/General.cs
+++ b/FunGame.Core/Api/Utility/General.cs
@@ -1,8 +1,9 @@
-using Milimoe.FunGame.Core.Library.Constant;
-using System.Net.NetworkInformation;
+using System.Net.NetworkInformation;
+using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
+using Milimoe.FunGame.Core.Library.Constant;
// 通用工具类,客户端和服务器端都可以直接调用的工具方法都可以写在这里
namespace Milimoe.FunGame.Core.Api.Utility
@@ -215,4 +216,31 @@ namespace Milimoe.FunGame.Core.Api.Utility
}
#endregion
+
+ #region 加密服务
+
+ ///
+ /// 使用HMACSHA512算法加密
+ ///
+ public class Encryption
+ {
+ ///
+ /// 使用HMACSHA512算法加密
+ ///
+ /// 需要加密的值
+ /// 秘钥
+ ///
+ public static string HmacSha512(string Message, string Key)
+ {
+ byte[] MessageBytes = General.DefaultEncoding.GetBytes(Message);
+ Key = Convert.ToBase64String(General.DefaultEncoding.GetBytes(Key));
+ byte[] KeyBytes = General.DefaultEncoding.GetBytes(Key);
+ HMACSHA512 Hmacsha512 = new(KeyBytes);
+ byte[] Hash = Hmacsha512.ComputeHash(MessageBytes);
+ string Hamc = BitConverter.ToString(Hash).Replace("-", "");
+ return Hamc.ToLower();
+ }
+ }
+
+ #endregion
}
diff --git a/FunGame.Core/Entity/User/User.cs b/FunGame.Core/Entity/User/User.cs
index 622a0f6..4cf8e0f 100644
--- a/FunGame.Core/Entity/User/User.cs
+++ b/FunGame.Core/Entity/User/User.cs
@@ -3,7 +3,7 @@ namespace Milimoe.FunGame.Core.Entity
public class User
{
public int Id { get; set; }
- public string Userame { get; set; } = "";
+ public string Username { get; set; } = "";
public string Password { get; set; } = "";
public DateTime RegTime { get; set; }
public DateTime LastTime { get; set; }
@@ -27,12 +27,12 @@ namespace Milimoe.FunGame.Core.Entity
internal User(string username)
{
- Userame = username;
+ Username = username;
}
internal User(string username, string password)
{
- Userame = username;
+ Username = username;
Password = password;
}
}
diff --git a/FunGame.Core/Library/Constant/TypeEnum.cs b/FunGame.Core/Library/Constant/TypeEnum.cs
index 5372a9c..657f829 100644
--- a/FunGame.Core/Library/Constant/TypeEnum.cs
+++ b/FunGame.Core/Library/Constant/TypeEnum.cs
@@ -130,6 +130,7 @@
public enum TimeType
{
+ None,
General,
DateOnly,
TimeOnly,
diff --git a/FunGame.Desktop/Controller/LoginController.cs b/FunGame.Desktop/Controller/LoginController.cs
index 0cfcf0c..3d6a4f9 100644
--- a/FunGame.Desktop/Controller/LoginController.cs
+++ b/FunGame.Desktop/Controller/LoginController.cs
@@ -1,4 +1,5 @@
-using Milimoe.FunGame.Desktop.Library.Interface;
+using Milimoe.FunGame.Core.Library.Common.Event;
+using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model;
using Milimoe.FunGame.Desktop.UI;
@@ -6,16 +7,34 @@ namespace Milimoe.FunGame.Desktop.Controller
{
public class LoginController : ILogin
{
- LoginModel LoginModel { get; }
+ private LoginModel LoginModel { get; }
+ private Login Login { get; }
public LoginController(Login Login)
{
+ this.Login = Login;
LoginModel = new LoginModel(Login);
}
- public bool LoginAccount()
+ public static bool LoginAccount(params object[]? objs)
{
- return LoginModel.LoginAccount();
+ return LoginModel.LoginAccount(objs);
+ }
+
+ public bool LoginAccount(string username, string password)
+ {
+ Login.OnBeforeLoginEvent(new GeneralEventArgs());
+ bool result = LoginModel.LoginAccount(username, password);
+ if (result)
+ {
+ Login.OnSucceedLoginEvent(new GeneralEventArgs());
+ }
+ else
+ {
+ Login.OnFailedLoginEvent(new GeneralEventArgs());
+ }
+ Login.OnAfterLoginEvent(new GeneralEventArgs());
+ return result;
}
}
}
diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs
index 50233e3..703ad10 100644
--- a/FunGame.Desktop/Controller/MainController.cs
+++ b/FunGame.Desktop/Controller/MainController.cs
@@ -1,4 +1,5 @@
-using Milimoe.FunGame.Core.Library.Constant;
+using Milimoe.FunGame.Core.Library.Common.Event;
+using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Desktop.Library;
using Milimoe.FunGame.Desktop.Library.Interface;
using Milimoe.FunGame.Desktop.Model;
@@ -8,12 +9,14 @@ namespace Milimoe.FunGame.Desktop.Controller
{
public class MainController : IMain
{
- private MainModel MainModel { get; }
+ public bool Connected => Do(MainSet.Connected);
- public bool Connected => Do(MainControllerSet.Connected);
+ private MainModel MainModel { get; }
+ private Main Main { get; }
public MainController(Main Main)
{
+ this.Main = Main;
MainModel = new MainModel(Main);
}
@@ -25,41 +28,67 @@ namespace Milimoe.FunGame.Desktop.Controller
object result = new();
switch(DoType)
{
- case MainControllerSet.GetServerConnection:
+ case MainSet.GetServerConnection:
result = MainModel.GetServerConnection();
break;
- case MainControllerSet.Connect:
+
+ case MainSet.Connect:
+ Main.OnBeforeConnectEvent(new GeneralEventArgs());
result = MainModel.Connect();
+ if ((ConnectResult)result == ConnectResult.Success)
+ {
+ Main.OnSucceedConnectEvent(new GeneralEventArgs());
+ }
+ else if ((ConnectResult)result == ConnectResult.ConnectFailed)
+ {
+ Main.OnFailedConnectEvent(new GeneralEventArgs());
+ }
+ Main.OnAfterConnectEvent(new GeneralEventArgs());
break;
- case MainControllerSet.Connected:
+
+ case MainSet.Connected:
result = MainModel.Connected;
break;
- case MainControllerSet.Disconnect:
+
+ case MainSet.Disconnect:
+ Main.OnBeforeDisconnectEvent(new GeneralEventArgs());
+ MainModel.Disconnect();
+ Main.OnAfterDisconnectEvent(new GeneralEventArgs());
+ break;
+
+ case MainSet.Disconnected:
MainModel.Disconnect();
break;
- case MainControllerSet.Disconnected:
- MainModel.Disconnect();
+
+ case MainSet.WaitConnectAndSetYellow:
break;
- case MainControllerSet.WaitConnectAndSetYellow:
+
+ case MainSet.WaitLoginAndSetYellow:
break;
- case MainControllerSet.WaitLoginAndSetYellow:
+
+ case MainSet.SetGreenAndPing:
break;
- case MainControllerSet.SetGreenAndPing:
+
+ case MainSet.SetGreen:
break;
- case MainControllerSet.SetGreen:
+
+ case MainSet.SetYellow:
break;
- case MainControllerSet.SetYellow:
+
+ case MainSet.SetRed:
break;
- case MainControllerSet.SetRed:
+
+ case MainSet.SetUser:
break;
- case MainControllerSet.SetUser:
- break;
- case MainControllerSet.LogOut:
+
+ case MainSet.LogOut:
result = MainModel.Logout();
break;
- case MainControllerSet.Close:
+
+ case MainSet.Close:
result = MainModel.Close();
break;
+
default:
break;
}
@@ -68,22 +97,22 @@ namespace Milimoe.FunGame.Desktop.Controller
public bool GetServerConnection()
{
- return Do(MainControllerSet.GetServerConnection);
+ return Do(MainSet.GetServerConnection);
}
public ConnectResult Connect()
{
- return Do(MainControllerSet.Connect);
+ return Do(MainSet.Connect);
}
public void Disconnect()
{
- Do