yuanshen/Yuanshen.Kcp/KcpSocketTransportForMultiplexConnection.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

40 lines
1.5 KiB
C#

using System.Net.Sockets;
namespace Yuanshen.Kcp
{
internal sealed class KcpSocketTransportForMultiplexConnection<T> : KcpSocketTransport<KcpMultiplexConnection<T>>, IKcpTransport<IKcpMultiplexConnection<T>>
{
private readonly Action<T?> _disposeAction;
private Func<Exception, IKcpTransport<IKcpMultiplexConnection<T>>, object, bool> _exceptionHandler;
private object _exceptionHandlerState;
internal KcpSocketTransportForMultiplexConnection(UdpClient listener, int mtu)
: base(listener, mtu)
{ }
internal KcpSocketTransportForMultiplexConnection(UdpClient listener, int mtu, Action<T?> disposeAction)
: base(listener, mtu)
{
_disposeAction = disposeAction;
}
protected override KcpMultiplexConnection<T> Activate() => new KcpMultiplexConnection<T>(this, _disposeAction);
IKcpMultiplexConnection<T> IKcpTransport<IKcpMultiplexConnection<T>>.Connection => Connection;
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<IKcpMultiplexConnection<T>>, object, bool> handler, object state)
{
_exceptionHandler = handler;
_exceptionHandlerState = state;
}
}
}