2024-05-13 00:17:40 +02:00
|
|
|
|
using System.Text;
|
2024-05-25 11:16:37 +02:00
|
|
|
|
using ServicePoint.BindGen;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
|
2024-05-25 11:16:37 +02:00
|
|
|
|
namespace ServicePoint;
|
2024-05-13 00:17:40 +02:00
|
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
|
public sealed class Connection : SpNativeInstance<BindGen.Connection>
|
2024-05-13 00:17:40 +02:00
|
|
|
|
{
|
|
|
|
|
public static Connection Open(string host)
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
fixed (byte* bytePtr = Encoding.UTF8.GetBytes(host))
|
|
|
|
|
{
|
2024-10-16 21:59:35 +02:00
|
|
|
|
return new Connection(ConnectionNative.sp_connection_open(bytePtr));
|
2024-05-13 00:17:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 20:34:51 +02:00
|
|
|
|
public bool Send(Packet packet)
|
2024-05-13 00:17:40 +02:00
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-10-16 22:46:34 +02:00
|
|
|
|
return Instance->SendPacket(packet.Into());
|
2024-09-07 14:35:16 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Send(Command command)
|
|
|
|
|
{
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
2024-10-16 22:46:34 +02:00
|
|
|
|
return Instance->SendCommand(command.Into());
|
2024-05-13 00:17:40 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
|
private protected override unsafe void Free() => Instance->Free();
|
2024-05-13 00:17:40 +02:00
|
|
|
|
|
2024-10-16 22:46:34 +02:00
|
|
|
|
private unsafe Connection(BindGen.Connection* instance) : base(instance)
|
2024-05-13 00:17:40 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|