yuanshen/Yuanshen.Kcp/KcpSocketTransportForConversation.cs
wisedev fc2ac1050f 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:10:50 +03:00

45 lines
1.7 KiB
C#

using System.Net;
using System.Net.Sockets;
namespace Yuanshen.Kcp
{
/// <summary>
/// Socket transport for KCP conversation.
/// </summary>
internal sealed class KcpSocketTransportForConversation : KcpSocketTransport<KcpConversation>, IKcpTransport<KcpConversation>
{
private readonly long? _conversationId;
private readonly IPEndPoint _remoteEndPoint;
private readonly KcpConversationOptions _options;
private Func<Exception, IKcpTransport<KcpConversation>, object, bool> _exceptionHandler;
private object _exceptionHandlerState;
internal KcpSocketTransportForConversation(UdpClient listener, IPEndPoint endPoint, long? conversationId, KcpConversationOptions options)
: base(listener, options?.Mtu ?? KcpConversationOptions.MtuDefaultValue)
{
_conversationId = conversationId;
_remoteEndPoint = endPoint;
_options = options;
}
protected override KcpConversation Activate() => _conversationId.HasValue ? new KcpConversation(_remoteEndPoint, this, _conversationId.GetValueOrDefault(), _options) : new KcpConversation(_remoteEndPoint, this, _options);
protected override bool HandleException(Exception ex)
{
if (_exceptionHandler is not null)
{
return _exceptionHandler.Invoke(ex, this, _exceptionHandlerState);
}
return false;
}
public void SetExceptionHandler(Func<Exception, IKcpTransport<KcpConversation>, object, bool> handler, object state)
{
_exceptionHandler = handler;
_exceptionHandlerState = state;
}
}
}