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