mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-12-05 08:09:02 +00:00
Update DataRequest And Socket MISC. (#24)
* Update DataRequest And Socket MISC. * Delete unused code
This commit is contained in:
parent
185fea4b40
commit
3eda4b8167
@ -1,13 +1,17 @@
|
|||||||
using System.Collections;
|
using System.Collections;
|
||||||
using Milimoe.FunGame.Core.Api.Utility;
|
|
||||||
using Milimoe.FunGame.Core.Library.Common.Architecture;
|
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;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Api.Transmittal
|
namespace Milimoe.FunGame.Core.Api.Transmittal
|
||||||
{
|
{
|
||||||
public class DataRequest
|
public class DataRequest
|
||||||
{
|
{
|
||||||
|
public bool Success => Worker.Success;
|
||||||
|
public string Error => Worker.Error;
|
||||||
|
public object? this[string key] => Worker.ResultData[key];
|
||||||
|
|
||||||
private readonly Request Worker;
|
private readonly Request Worker;
|
||||||
|
|
||||||
public DataRequest(Socket Socket, DataRequestType RequestType)
|
public DataRequest(Socket Socket, DataRequestType RequestType)
|
||||||
@ -20,13 +24,11 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
|
|||||||
Worker.RequestData.Add(key, value);
|
Worker.RequestData.Add(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendRequest()
|
public void SendRequest()
|
||||||
{
|
{
|
||||||
await Worker.SendRequest();
|
Worker.SendRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public object? this[string key] => Worker.ResultData[key];
|
|
||||||
|
|
||||||
public T? GetResult<T>(string key)
|
public T? GetResult<T>(string key)
|
||||||
{
|
{
|
||||||
object? obj = this[key];
|
object? obj = this[key];
|
||||||
@ -41,33 +43,36 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
|
|||||||
{
|
{
|
||||||
public Hashtable RequestData { get; } = new();
|
public Hashtable RequestData { get; } = new();
|
||||||
public Hashtable ResultData => _Result;
|
public Hashtable ResultData => _Result;
|
||||||
|
public bool Success => _Success;
|
||||||
|
public string Error => _Error;
|
||||||
|
|
||||||
private bool JobFinish = false;
|
|
||||||
private readonly Socket? Socket;
|
private readonly Socket? Socket;
|
||||||
private readonly DataRequestType RequestType;
|
private readonly DataRequestType RequestType;
|
||||||
|
|
||||||
|
private bool _Finish = false;
|
||||||
|
private bool _Success = false;
|
||||||
|
private string _Error = "";
|
||||||
private Hashtable _Result = new();
|
private Hashtable _Result = new();
|
||||||
|
|
||||||
public async Task<RequestResult> SendRequest()
|
public void SendRequest()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (Socket?.Send(SocketMessageType.DataRequest, RequestData) == SocketResult.Success)
|
if (Socket?.Send(SocketMessageType.DataRequest, RequestType, RequestData) == SocketResult.Success)
|
||||||
{
|
{
|
||||||
await Task.Run(() =>
|
while (true)
|
||||||
{
|
{
|
||||||
while (true)
|
if (_Finish) break;
|
||||||
{
|
Thread.Sleep(100);
|
||||||
if (JobFinish) break;
|
}
|
||||||
Thread.Sleep(100);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
return RequestResult.Fail;
|
_Finish = true;
|
||||||
|
_Success = false;
|
||||||
|
_Error = e.GetErrorInfo();
|
||||||
}
|
}
|
||||||
return RequestResult.Success;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Request(Socket? socket, DataRequestType requestType) : base(socket)
|
public Request(Socket? socket, DataRequestType requestType) : base(socket)
|
||||||
@ -78,16 +83,26 @@ namespace Milimoe.FunGame.Core.Api.Transmittal
|
|||||||
|
|
||||||
public override void SocketHandler(SocketObject SocketObject)
|
public override void SocketHandler(SocketObject SocketObject)
|
||||||
{
|
{
|
||||||
if (SocketObject.SocketType == SocketMessageType.DataRequest)
|
try
|
||||||
{
|
{
|
||||||
DataRequestType type = SocketObject.GetParam<DataRequestType>(0);
|
if (SocketObject.SocketType == SocketMessageType.DataRequest)
|
||||||
if (type == RequestType)
|
|
||||||
{
|
{
|
||||||
Dispose();
|
DataRequestType type = SocketObject.GetParam<DataRequestType>(0);
|
||||||
_Result = SocketObject.GetParam<Hashtable>(1) ?? new();
|
if (type == RequestType)
|
||||||
JobFinish = true;
|
{
|
||||||
|
Dispose();
|
||||||
|
_Result = SocketObject.GetParam<Hashtable>(1) ?? new();
|
||||||
|
_Finish = true;
|
||||||
|
_Success = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_Finish = true;
|
||||||
|
_Success = false;
|
||||||
|
_Error = e.GetErrorInfo();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
public const string Socket = "Socket";
|
public const string Socket = "Socket";
|
||||||
public const string Unknown = "Unknown";
|
public const string Unknown = "Unknown";
|
||||||
|
public const string DataRequest = "DataRequest";
|
||||||
public const string Connect = "Connect";
|
public const string Connect = "Connect";
|
||||||
public const string GetNotice = "GetNotice";
|
public const string GetNotice = "GetNotice";
|
||||||
public const string Login = "Login";
|
public const string Login = "Login";
|
||||||
|
|||||||
@ -8,7 +8,8 @@
|
|||||||
Inventory,
|
Inventory,
|
||||||
RoomSetting,
|
RoomSetting,
|
||||||
Store,
|
Store,
|
||||||
UserCenter
|
UserCenter,
|
||||||
|
ForgetPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum OpenFormType
|
public enum OpenFormType
|
||||||
@ -78,7 +79,8 @@
|
|||||||
|
|
||||||
public enum DataRequestType
|
public enum DataRequestType
|
||||||
{
|
{
|
||||||
UnKnown
|
UnKnown,
|
||||||
|
GetFindPasswordVerifyCode
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum SocketRuntimeType
|
public enum SocketRuntimeType
|
||||||
|
|||||||
@ -268,6 +268,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
{
|
{
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
|
SocketMessageType.DataRequest => SocketSet.DataRequest,
|
||||||
SocketMessageType.Connect => SocketSet.Connect,
|
SocketMessageType.Connect => SocketSet.Connect,
|
||||||
SocketMessageType.GetNotice => SocketSet.GetNotice,
|
SocketMessageType.GetNotice => SocketSet.GetNotice,
|
||||||
SocketMessageType.Login => SocketSet.Login,
|
SocketMessageType.Login => SocketSet.Login,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user