forked from project-redbud/FunGame-Core
等待修复
This commit is contained in:
parent
03c579e88d
commit
5a8a34a68e
@ -2,35 +2,30 @@
|
||||
{
|
||||
public class ConcurrentQueue<T>
|
||||
{
|
||||
public bool Lock { get; set; }
|
||||
private bool Lock { get; set; }
|
||||
|
||||
private System.Collections.Concurrent.ConcurrentQueue<T> Instance { get; }
|
||||
private System.Collections.Concurrent.ConcurrentQueue<T> Instance { get; } = new();
|
||||
|
||||
public ConcurrentQueue()
|
||||
{
|
||||
Instance = new System.Collections.Concurrent.ConcurrentQueue<T>();
|
||||
}
|
||||
|
||||
public void Add(T obj)
|
||||
public async void AddAsync(T obj)
|
||||
{
|
||||
if (Lock)
|
||||
{
|
||||
return;
|
||||
await Task.Run(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Lock) break;
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
});
|
||||
}
|
||||
Lock = true;
|
||||
lock (Instance)
|
||||
{
|
||||
Instance.Enqueue(obj);
|
||||
}
|
||||
Instance.Enqueue(obj);
|
||||
}
|
||||
|
||||
public bool Delete()
|
||||
{
|
||||
bool result = false;
|
||||
lock (Instance)
|
||||
{
|
||||
result = Instance.TryDequeue(out _);
|
||||
}
|
||||
bool result = Instance.TryDequeue(out _);
|
||||
Lock = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
||||
|
||||
public async Task SendRequest()
|
||||
{
|
||||
Queue.Add(Worker);
|
||||
Queue.AddAsync(Worker);
|
||||
if (await Worker.SendRequest() == RequestResult.Success)
|
||||
{
|
||||
Queue.Delete();
|
||||
@ -83,13 +83,17 @@ namespace Milimoe.FunGame.Core.Library.Common.Architecture
|
||||
{
|
||||
if (SocketObject.SocketType == SocketMessageType.DataRequest)
|
||||
{
|
||||
Dispose();
|
||||
switch (RequestType)
|
||||
DataRequestType type = SocketObject.GetParam<DataRequestType>(0);
|
||||
if (type == RequestType)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
Dispose();
|
||||
switch (RequestType)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
JobFinish = true;
|
||||
}
|
||||
JobFinish = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,13 +2,18 @@
|
||||
{
|
||||
public class LoginEventArgs : GeneralEventArgs
|
||||
{
|
||||
public string Username;
|
||||
public string Password;
|
||||
public string Username { get; set; } = "";
|
||||
public string Password { get; set; } = "";
|
||||
public string AutoKey { get; set; } = "";
|
||||
|
||||
public LoginEventArgs(string username = "", string password = "")
|
||||
public LoginEventArgs(params object[]? objs)
|
||||
{
|
||||
Username = username;
|
||||
Password = password;
|
||||
if (objs != null)
|
||||
{
|
||||
if (objs.Length > 0) Username = (string)objs[0];
|
||||
if (objs.Length > 1) Password = (string)objs[1];
|
||||
if (objs.Length > 2) AutoKey = (string)objs[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
using Milimoe.FunGame.Core.Library.Common.Event;
|
||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.Model;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
@ -23,24 +21,12 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
|
||||
public static bool LoginAccount(params object[]? objs)
|
||||
{
|
||||
if (RunTime.Login?.OnBeforeLoginEvent(Login.EventArgs) == Core.Library.Constant.EventResult.Fail) return false;
|
||||
bool result = LoginModel.LoginAccount(objs);
|
||||
if (!result)
|
||||
{
|
||||
ShowMessage.ErrorMessage("登录失败!!", "登录失败", 5);
|
||||
RunTime.Login?.OnFailedLoginEvent(Login.EventArgs);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool CheckLogin(params object[]? objs)
|
||||
{
|
||||
bool result = LoginModel.CheckLogin(objs);
|
||||
if (!result)
|
||||
{
|
||||
ShowMessage.ErrorMessage("登录失败!!", "登录失败", 5);
|
||||
RunTime.Login?.OnFailedLoginEvent(Login.EventArgs);
|
||||
}
|
||||
LoginEventArgs LoginEventArgs = new(objs);
|
||||
if (RunTime.Login?.OnBeforeLoginEvent(LoginEventArgs) == Core.Library.Constant.EventResult.Fail) return false;
|
||||
bool result = LoginModel.LoginAccountAsync(objs).Result;
|
||||
if (result) RunTime.Login?.OnSucceedLoginEvent(LoginEventArgs);
|
||||
else RunTime.Login?.OnFailedLoginEvent(LoginEventArgs);
|
||||
RunTime.Login?.OnAfterLoginEvent(LoginEventArgs);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,10 +5,8 @@ using Milimoe.FunGame.Core.Library.Common.Architecture;
|
||||
using Milimoe.FunGame.Core.Library.Common.Network;
|
||||
using Milimoe.FunGame.Core.Library.Constant;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Milimoe.FunGame.Desktop.Controller;
|
||||
using Milimoe.FunGame.Desktop.Library;
|
||||
using Milimoe.FunGame.Desktop.Library.Component;
|
||||
using Milimoe.FunGame.Desktop.UI;
|
||||
|
||||
namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
@ -17,6 +15,10 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
/// </summary>
|
||||
public class LoginModel : BaseModel
|
||||
{
|
||||
private static SocketObject Work;
|
||||
private static bool Working = false;
|
||||
private static bool Success = false;
|
||||
|
||||
public LoginModel() : base(RunTime.Socket)
|
||||
{
|
||||
|
||||
@ -26,18 +28,9 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
{
|
||||
try
|
||||
{
|
||||
SocketMessageType type = SocketObject.SocketType;
|
||||
object[] objs = SocketObject.Parameters;
|
||||
switch (SocketObject.SocketType)
|
||||
{
|
||||
case SocketMessageType.Login:
|
||||
SocketHandler_Login(SocketObject);
|
||||
break;
|
||||
|
||||
case SocketMessageType.CheckLogin:
|
||||
SocketHandler_CheckLogin(SocketObject);
|
||||
break;
|
||||
}
|
||||
Work = SocketObject;
|
||||
Success = true;
|
||||
Working = false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -45,7 +38,7 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LoginAccount(params object[]? objs)
|
||||
public static async Task<bool> LoginAccountAsync(params object[]? objs)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -61,14 +54,26 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
password = password.Encrypt(username);
|
||||
if (Socket.Send(SocketMessageType.Login, username, password, autokey) == SocketResult.Success)
|
||||
{
|
||||
return true;
|
||||
SetWorking();
|
||||
await Task.Factory.StartNew(async() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
if (Success)
|
||||
{
|
||||
await CheckLoginAsync(Work);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.GetErrorInfo();
|
||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -89,12 +94,12 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.GetErrorInfo();
|
||||
RunTime.WritelnSystemInfo(e.GetErrorInfo());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void SocketHandler_Login(SocketObject SocketObject)
|
||||
private static async Task<bool> CheckLoginAsync(SocketObject SocketObject)
|
||||
{
|
||||
Guid key = Guid.Empty;
|
||||
string? msg = "";
|
||||
@ -105,26 +110,41 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
if (msg != null && msg.Trim() != "")
|
||||
{
|
||||
ShowMessage.ErrorMessage(msg, "登录失败");
|
||||
RunTime.Login?.OnFailedLoginEvent(Login.EventArgs);
|
||||
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (key != Guid.Empty)
|
||||
{
|
||||
Config.Guid_LoginKey = key;
|
||||
LoginController.CheckLogin(key);
|
||||
Socket Socket = RunTime.Socket!;
|
||||
if (Socket.Send(SocketMessageType.CheckLogin, key) == SocketResult.Success)
|
||||
{
|
||||
SetWorking();
|
||||
await Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (!Working) break;
|
||||
}
|
||||
if (Success)
|
||||
{
|
||||
SocketHandler_CheckLogin(Work);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ShowMessage.ErrorMessage("登录失败!!", "登录失败", 5);
|
||||
RunTime.Login?.OnFailedLoginEvent(Login.EventArgs);
|
||||
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void SocketHandler_CheckLogin(SocketObject SocketObject)
|
||||
private static bool SocketHandler_CheckLogin(SocketObject SocketObject)
|
||||
{
|
||||
// 返回构造User对象的DataTable
|
||||
object[] objs = SocketObject.Parameters;
|
||||
@ -133,14 +153,17 @@ namespace Milimoe.FunGame.Desktop.Model
|
||||
DataSet? DataSet = SocketObject.GetParam<DataSet>(0);
|
||||
// 创建User对象并返回到Main
|
||||
RunTime.Main?.UpdateUI(MainInvokeType.SetUser, new object[] { Factory.GetInstance<User>(DataSet) });
|
||||
RunTime.Login?.OnSucceedLoginEvent(Login.EventArgs);
|
||||
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
ShowMessage.ErrorMessage("登录失败!!", "登录失败", 5);
|
||||
RunTime.Login?.OnFailedLoginEvent(Login.EventArgs);
|
||||
RunTime.Login?.OnAfterLoginEvent(Login.EventArgs);
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void SetWorking()
|
||||
{
|
||||
Working = true;
|
||||
Success = false;
|
||||
Work = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,8 +11,6 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
{
|
||||
public partial class Login : BaseLogin
|
||||
{
|
||||
public static LoginEventArgs EventArgs { get; set; } = new LoginEventArgs();
|
||||
|
||||
private readonly LoginController LoginController;
|
||||
|
||||
public Login()
|
||||
@ -48,7 +46,6 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
UsernameText.Focus();
|
||||
return false;
|
||||
}
|
||||
EventArgs = new LoginEventArgs(username, password);
|
||||
if (!LoginController.LoginAccount(username, password))
|
||||
{
|
||||
ShowMessage.Message("登录失败!!", "登录失败");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user