milimoe b73b37c45e
DataRequest、GameModule相关优化 (#82)
* 使基于HTTPClient的DataRequest能够收到回复;添加了适用于Gaming的DataRequest;优化了加载器的加载逻辑;依赖集合的优化

* 执行代理清理;优化模组模板

* 删除GamingEvent无用的事件;删除result哈希表;删除无用的Item/Skill类;GameModuleLoader优化
2024-08-03 04:10:34 +08:00

83 lines
2.5 KiB
C#

using Milimoe.FunGame.Core.Interface.Sockets;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Library.Common.Network
{
public class ClientSocket(System.Net.Sockets.Socket Instance, int ServerPort, string ClientIP, string ClientName, Guid Token) : IClientSocket
{
public System.Net.Sockets.Socket Instance { get; } = Instance;
public SocketRuntimeType Runtime => SocketRuntimeType.Server;
public Guid Token { get; } = Token;
public string ServerAddress { get; } = "";
public int ServerPort { get; } = ServerPort;
public string ServerName { get; } = "";
public string ServerNotice { get; } = "";
public string ClientIP { get; } = ClientIP;
public string ClientName => _ClientName;
public bool Connected => Instance != null && Instance.Connected;
public bool Receiving => _Receiving;
private Task? ReceivingTask;
private bool _Receiving;
private readonly string _ClientName = ClientName;
public void Close()
{
StopReceiving();
Instance?.Close();
}
public SocketObject[] Receive()
{
try
{
return SocketManager.Receive(Instance);
}
catch
{
throw new SocketWrongInfoException();
}
}
public SocketResult Send(SocketMessageType type, params object[] objs)
{
if (Instance != null)
{
if (SocketManager.Send(Instance, new(type, Token, objs)) == SocketResult.Success)
{
return SocketResult.Success;
}
else return SocketResult.Fail;
}
return SocketResult.NotSent;
}
public void BindEvent(Delegate method, bool remove = false)
{
if (!remove)
{
SocketManager.SocketReceive += (SocketManager.SocketReceiveHandler)method;
}
else
{
SocketManager.SocketReceive -= (SocketManager.SocketReceiveHandler)method;
}
}
public void StartReceiving(Task t)
{
_Receiving = true;
ReceivingTask = t;
}
public void StopReceiving()
{
_Receiving = false;
ReceivingTask?.Wait(1);
ReceivingTask = null;
}
}
}