yuanshen/Yuanshen.Gameserver/Network/Kcp/KcpNetworkUnit.cs
wisedev 61cc2055cf First working version of the server
KCP gameserver with packet dispatch, scene streaming, combat, gacha and the
shop, plus a small HTTP server for the login flow and the wish history page.

Game data under assets is pulled out of the client instead of being typed by
hand. The excel tables come from the packed bin container and the spawn points
from the compiled scene scripts.
2026-09-04 02:06:53 +03:00

35 lines
974 B
C#

using System.Net;
using Yuanshen.Kcp;
namespace Yuanshen.Gameserver.Network.Kcp;
internal class KcpNetworkUnit : INetworkUnit
{
public IPEndPoint RemoteEndPoint { get; }
private readonly KcpConversation _conversation;
public KcpNetworkUnit(KcpConversation conversation, IPEndPoint remoteEndPoint)
{
_conversation = conversation;
RemoteEndPoint = remoteEndPoint;
}
public async ValueTask<int> ReceiveAsync(Memory<byte> buffer, CancellationToken cancellationToken)
{
KcpConversationReceiveResult result = await _conversation.ReceiveAsync(buffer, cancellationToken);
if (result.TransportClosed)
return -1;
return result.BytesReceived;
}
public async ValueTask SendAsync(Memory<byte> buffer, CancellationToken cancellationToken)
{
await _conversation.SendAsync(buffer, cancellationToken);
}
public void Dispose()
{
_conversation.Dispose();
}
}