fix: kcp V1.23 - fixes #3296

This commit is contained in:
vis2k 2022-12-07 19:14:59 +01:00
parent 98e7d2f475
commit b91c7027a5
12 changed files with 59 additions and 13 deletions

View File

@ -1,5 +1,11 @@
V1.22 [2022-11-24]
- KcpPeer.RawInput: add offset parameter
V1.23 [2022-12-07]
- KcpClient: rawReceiveBuffer exposed
- fix: KcpServer RawSend uses connection.remoteEndPoint instead of the helper
'newClientEP'. fixes clients receiving the wrong messages meant for others.
https://github.com/MirrorNetworking/Mirror/issues/3296
V1.22 [2022-11-30]
- high level refactor, part two.
V1.21 [2022-11-24]
- high level refactor, part one.

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d9ce2267cb8a4a1c9632025287e8da88
timeCreated: 1669162433

View File

@ -0,0 +1 @@
// removed 2022-11-23

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 96512e74aa8214a6faa8a412a7a07877
timeCreated: 1602601237

View File

@ -0,0 +1 @@
// removed 2022-11-22

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4c1b235bbe054706bef6d092f361006e
timeCreated: 1626430539

View File

@ -0,0 +1 @@
// removed 2022-11-22

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2cf0ccf7d551480bb5af08fcbe169f84
timeCreated: 1626435264

View File

@ -0,0 +1 @@
// removed 2022-11-23

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4e1b74cc224b4c83a0f6c8d8da9090ab
timeCreated: 1626430608

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
namespace kcp2k
{
@ -203,17 +204,27 @@ protected virtual bool RawReceive(byte[] buffer, out int size, out int connectio
// io - out.
// virtual so it may be modified for relays, nonalloc workaround, etc.
// relays may need to prefix connId (and remoteEndPoint would be same for all)
protected virtual void RawSend(int connectionId, ArraySegment<byte> data, EndPoint remoteEndPoint)
protected virtual void RawSend(int connectionId, ArraySegment<byte> data)
{
socket.SendTo(data.Array, data.Offset, data.Count, SocketFlags.None, remoteEndPoint);
// get the connection's endpoint
if (!connections.TryGetValue(connectionId, out KcpServerConnection connection))
{
Debug.LogWarning($"KcpServer.RawSend: invalid connectionId={connectionId}");
return;
}
// send to the the endpoint.
// do not send to 'newClientEP', as that's always reused.
// fixes https://github.com/MirrorNetworking/Mirror/issues/3296
socket.SendTo(data.Array, data.Offset, data.Count, SocketFlags.None, connection.remoteEndPoint);
}
protected virtual KcpServerConnection CreateConnection(int connectionId)
{
// attach EndPoint EP to RawSend.
// attach connectionId to RawSend.
// kcp needs a simple RawSend(byte[]) function.
Action<ArraySegment<byte>> RawSendWrap =
data => RawSend(connectionId, data, newClientEP);
data => RawSend(connectionId, data);
KcpPeer peer = new KcpPeer(RawSendWrap, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize, Timeout, MaxRetransmits);
return new KcpServerConnection(peer, newClientEP);

View File

@ -3,6 +3,7 @@
using System;
using System.Net;
using System.Net.Sockets;
using UnityEngine;
using WhereAllocation;
namespace kcp2k
@ -58,10 +59,19 @@ protected override bool RawReceive(byte[] buffer, out int size, out int connecti
}
// make sure to pass IPEndPointNonAlloc as remoteEndPoint
protected override void RawSend(int connectionId, ArraySegment<byte> data, EndPoint remoteEndPoint)
protected override void RawSend(int connectionId, ArraySegment<byte> data)
{
// where-allocation nonalloc send
socket.SendTo_NonAlloc(data.Array, data.Offset, data.Count, SocketFlags.None, remoteEndPoint as IPEndPointNonAlloc);
// get the connection's endpoint
if (!connections.TryGetValue(connectionId, out KcpServerConnection connection))
{
Debug.LogWarning($"KcpServerNonAlloc.RawSend: invalid connectionId={connectionId}");
return;
}
// where-allocation nonalloc send to the endpoint.
// do not send to 'newClientEP', as that's always reused.
// fixes https://github.com/MirrorNetworking/Mirror/issues/3296
socket.SendTo_NonAlloc(data.Array, data.Offset, data.Count, SocketFlags.None, connection.remoteEndPoint as IPEndPointNonAlloc);
}
protected override KcpServerConnection CreateConnection(int connectionId)
@ -73,15 +83,15 @@ protected override KcpServerConnection CreateConnection(int connectionId)
// for allocation free sending, we also need another
// IPEndPointNonAlloc...
IPEndPointNonAlloc reusableSendEP = new IPEndPointNonAlloc(newClientEP.Address, newClientEP.Port);
IPEndPointNonAlloc endPointNonAlloc = new IPEndPointNonAlloc(newClientEP.Address, newClientEP.Port);
// attach reusable EP to RawSend.
// attach conectionId to RawSend.
// kcp needs a simple RawSend(byte[]) function.
Action<ArraySegment<byte>> RawSendWrap =
data => RawSend(connectionId, data, reusableSendEP);
data => RawSend(connectionId, data);
KcpPeer peer = new KcpPeer(RawSendWrap, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize, Timeout, MaxRetransmits);
return new KcpServerConnection(peer, newClientEP);
return new KcpServerConnection(peer, endPointNonAlloc);
}
}
}