mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
fix: kcp V1.23 - fixes #3296
This commit is contained in:
parent
98e7d2f475
commit
b91c7027a5
@ -1,5 +1,11 @@
|
|||||||
V1.22 [2022-11-24]
|
V1.23 [2022-12-07]
|
||||||
- KcpPeer.RawInput: add offset parameter
|
- 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]
|
V1.21 [2022-11-24]
|
||||||
- high level refactor, part one.
|
- high level refactor, part one.
|
||||||
|
3
Assets/Mirror/Transports/KCP/kcp2k/empty.meta
Normal file
3
Assets/Mirror/Transports/KCP/kcp2k/empty.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d9ce2267cb8a4a1c9632025287e8da88
|
||||||
|
timeCreated: 1669162433
|
@ -0,0 +1 @@
|
|||||||
|
// removed 2022-11-23
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 96512e74aa8214a6faa8a412a7a07877
|
||||||
|
timeCreated: 1602601237
|
@ -0,0 +1 @@
|
|||||||
|
// removed 2022-11-22
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4c1b235bbe054706bef6d092f361006e
|
||||||
|
timeCreated: 1626430539
|
@ -0,0 +1 @@
|
|||||||
|
// removed 2022-11-22
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2cf0ccf7d551480bb5af08fcbe169f84
|
||||||
|
timeCreated: 1626435264
|
@ -0,0 +1 @@
|
|||||||
|
// removed 2022-11-23
|
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4e1b74cc224b4c83a0f6c8d8da9090ab
|
||||||
|
timeCreated: 1626430608
|
@ -4,6 +4,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace kcp2k
|
namespace kcp2k
|
||||||
{
|
{
|
||||||
@ -203,17 +204,27 @@ protected virtual bool RawReceive(byte[] buffer, out int size, out int connectio
|
|||||||
// io - out.
|
// io - out.
|
||||||
// virtual so it may be modified for relays, nonalloc workaround, etc.
|
// virtual so it may be modified for relays, nonalloc workaround, etc.
|
||||||
// relays may need to prefix connId (and remoteEndPoint would be same for all)
|
// 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)
|
protected virtual KcpServerConnection CreateConnection(int connectionId)
|
||||||
{
|
{
|
||||||
// attach EndPoint EP to RawSend.
|
// attach connectionId to RawSend.
|
||||||
// kcp needs a simple RawSend(byte[]) function.
|
// kcp needs a simple RawSend(byte[]) function.
|
||||||
Action<ArraySegment<byte>> RawSendWrap =
|
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);
|
KcpPeer peer = new KcpPeer(RawSendWrap, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize, Timeout, MaxRetransmits);
|
||||||
return new KcpServerConnection(peer, newClientEP);
|
return new KcpServerConnection(peer, newClientEP);
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using UnityEngine;
|
||||||
using WhereAllocation;
|
using WhereAllocation;
|
||||||
|
|
||||||
namespace kcp2k
|
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
|
// 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
|
// get the connection's endpoint
|
||||||
socket.SendTo_NonAlloc(data.Array, data.Offset, data.Count, SocketFlags.None, remoteEndPoint as IPEndPointNonAlloc);
|
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)
|
protected override KcpServerConnection CreateConnection(int connectionId)
|
||||||
@ -73,15 +83,15 @@ protected override KcpServerConnection CreateConnection(int connectionId)
|
|||||||
|
|
||||||
// for allocation free sending, we also need another
|
// for allocation free sending, we also need another
|
||||||
// IPEndPointNonAlloc...
|
// 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.
|
// kcp needs a simple RawSend(byte[]) function.
|
||||||
Action<ArraySegment<byte>> RawSendWrap =
|
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);
|
KcpPeer peer = new KcpPeer(RawSendWrap, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize, Timeout, MaxRetransmits);
|
||||||
return new KcpServerConnection(peer, newClientEP);
|
return new KcpServerConnection(peer, endPointNonAlloc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user