mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Mirror uses new Transport.Send version everywhere
This commit is contained in:
parent
9a0cce64cd
commit
e823de74bd
@ -91,7 +91,7 @@ internal void SendBatch(int channelId, Batch batch)
|
||||
writer.Position + segment.Count >= max)
|
||||
{
|
||||
// flush & reset writer
|
||||
Transport.activeTransport.ServerSend(connectionId, channelId, writer.ToArraySegment());
|
||||
Transport.activeTransport.ServerSend(connectionId, writer.ToArraySegment(), channelId);
|
||||
writer.SetLength(0);
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ internal void SendBatch(int channelId, Batch batch)
|
||||
// send it.
|
||||
if (writer.Position > 0)
|
||||
{
|
||||
Transport.activeTransport.ServerSend(connectionId, channelId, writer.ToArraySegment());
|
||||
Transport.activeTransport.ServerSend(connectionId, writer.ToArraySegment(), channelId);
|
||||
writer.SetLength(0);
|
||||
}
|
||||
}
|
||||
@ -144,7 +144,7 @@ internal override void Send(ArraySegment<byte> segment, int channelId = Channels
|
||||
batch.messages.Enqueue(writer);
|
||||
}
|
||||
// otherwise send directly to minimize latency
|
||||
else Transport.activeTransport.ServerSend(connectionId, channelId, segment);
|
||||
else Transport.activeTransport.ServerSend(connectionId, segment, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ internal override void Send(ArraySegment<byte> segment, int channelId = Channels
|
||||
// validate packet size first.
|
||||
if (ValidatePacketSize(segment, channelId))
|
||||
{
|
||||
Transport.activeTransport.ClientSend(channelId, segment);
|
||||
Transport.activeTransport.ClientSend(segment, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,9 +93,9 @@ public override void ClientDisconnect()
|
||||
available.ClientDisconnect();
|
||||
}
|
||||
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
available.ClientSend(channelId, segment);
|
||||
available.ClientSend(segment, channelId);
|
||||
}
|
||||
|
||||
// right now this just returns the first available uri,
|
||||
@ -117,9 +117,9 @@ public override void ServerDisconnect(int connectionId)
|
||||
available.ServerDisconnect(connectionId);
|
||||
}
|
||||
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
available.ServerSend(connectionId, channelId, segment);
|
||||
available.ServerSend(connectionId, segment, channelId);
|
||||
}
|
||||
|
||||
public override void ServerStart()
|
||||
|
@ -90,7 +90,7 @@ public override void ClientConnect(string address)
|
||||
{
|
||||
client.Connect(address, Port, NoDelay, Interval, FastResend, CongestionWindow, SendWindowSize, ReceiveWindowSize);
|
||||
}
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
// switch to kcp channel.
|
||||
// unreliable or reliable.
|
||||
@ -149,7 +149,7 @@ public override Uri ServerUri()
|
||||
}
|
||||
public override bool ServerActive() => server.IsActive();
|
||||
public override void ServerStart() => server.Start(Port);
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
// switch to kcp channel.
|
||||
// unreliable or reliable.
|
||||
|
@ -91,7 +91,7 @@ float SimulateLatency(int channeldId)
|
||||
}
|
||||
|
||||
// helper function to simulate a send with latency/loss/scramble
|
||||
void SimulateSend(int connectionId, int channelId, ArraySegment<byte> segment, float latency, List<QueuedMessage> reliableQueue, List<QueuedMessage> unreliableQueue)
|
||||
void SimulateSend(int connectionId, ArraySegment<byte> segment, int channelId, float latency, List<QueuedMessage> reliableQueue, List<QueuedMessage> unreliableQueue)
|
||||
{
|
||||
// segment is only valid after returning. copy it.
|
||||
// (allocates for now. it's only for testing anyway.)
|
||||
@ -161,10 +161,10 @@ public override void ClientDisconnect()
|
||||
unreliableClientToServer.Clear();
|
||||
}
|
||||
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
float latency = SimulateLatency(channelId);
|
||||
SimulateSend(0, channelId, segment, latency, reliableClientToServer, unreliableClientToServer);
|
||||
SimulateSend(0, segment, channelId, latency, reliableClientToServer, unreliableClientToServer);
|
||||
}
|
||||
|
||||
public override Uri ServerUri() => wrap.ServerUri();
|
||||
@ -175,10 +175,10 @@ public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
|
||||
public override void ServerDisconnect(int connectionId) => wrap.ServerDisconnect(connectionId);
|
||||
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
float latency = SimulateLatency(channelId);
|
||||
SimulateSend(connectionId, channelId, segment, latency, reliableServerToClient, unreliableServerToClient);
|
||||
SimulateSend(connectionId, segment, channelId, latency, reliableServerToClient, unreliableServerToClient);
|
||||
}
|
||||
|
||||
public override void ServerStart()
|
||||
@ -209,7 +209,7 @@ public override void ClientLateUpdate()
|
||||
if (message.time <= Time.time)
|
||||
{
|
||||
// send and eat
|
||||
wrap.ClientSend(Channels.Reliable, new ArraySegment<byte>(message.bytes));
|
||||
wrap.ClientSend(new ArraySegment<byte>(message.bytes), Channels.Reliable);
|
||||
reliableClientToServer.RemoveAt(0);
|
||||
}
|
||||
// not enough time elapsed yet
|
||||
@ -224,7 +224,7 @@ public override void ClientLateUpdate()
|
||||
if (message.time <= Time.time)
|
||||
{
|
||||
// send and eat
|
||||
wrap.ClientSend(Channels.Unreliable, new ArraySegment<byte>(message.bytes));
|
||||
wrap.ClientSend(new ArraySegment<byte>(message.bytes), Channels.Unreliable);
|
||||
unreliableClientToServer.RemoveAt(0);
|
||||
}
|
||||
// not enough time elapsed yet
|
||||
@ -244,7 +244,7 @@ public override void ServerLateUpdate()
|
||||
if (message.time <= Time.time)
|
||||
{
|
||||
// send and eat
|
||||
wrap.ServerSend(message.connectionId, Channels.Reliable, new ArraySegment<byte>(message.bytes));
|
||||
wrap.ServerSend(message.connectionId, new ArraySegment<byte>(message.bytes), Channels.Reliable);
|
||||
reliableServerToClient.RemoveAt(0);
|
||||
}
|
||||
// not enough time elapsed yet
|
||||
@ -259,7 +259,7 @@ public override void ServerLateUpdate()
|
||||
if (message.time <= Time.time)
|
||||
{
|
||||
// send and eat
|
||||
wrap.ServerSend(message.connectionId, Channels.Unreliable, new ArraySegment<byte>(message.bytes));
|
||||
wrap.ServerSend(message.connectionId, new ArraySegment<byte>(message.bytes), Channels.Unreliable);
|
||||
unreliableServerToClient.RemoveAt(0);
|
||||
}
|
||||
// not enough time elapsed yet
|
||||
|
@ -30,7 +30,7 @@ public override void ClientConnect(string address)
|
||||
|
||||
public override bool ClientConnected() => inner.ClientConnected();
|
||||
public override void ClientDisconnect() => inner.ClientDisconnect();
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment) => inner.ClientSend(channelId, segment);
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId) => inner.ClientSend(segment, channelId);
|
||||
#endregion
|
||||
|
||||
#region Server
|
||||
@ -45,7 +45,7 @@ public override void ServerStart()
|
||||
}
|
||||
|
||||
public override void ServerStop() => inner.ServerStop();
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment) => inner.ServerSend(connectionId, channelId, segment);
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) => inner.ServerSend(connectionId, segment, channelId);
|
||||
public override void ServerDisconnect(int connectionId) => inner.ServerDisconnect(connectionId);
|
||||
public override string ServerGetClientAddress(int connectionId) => inner.ServerGetClientAddress(connectionId);
|
||||
public override Uri ServerUri() => inner.ServerUri();
|
||||
|
@ -137,9 +137,9 @@ public override void ClientDisconnect()
|
||||
available.ClientDisconnect();
|
||||
}
|
||||
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
available.ClientSend(channelId, segment);
|
||||
available.ClientSend(segment, channelId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -231,7 +231,7 @@ public override void ServerDisconnect(int connectionId)
|
||||
transports[transportId].ServerDisconnect(baseConnectionId);
|
||||
}
|
||||
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
int baseConnectionId = ToBaseId(connectionId);
|
||||
int transportId = ToTransportId(connectionId);
|
||||
@ -240,7 +240,7 @@ public override void ServerSend(int connectionId, int channelId, ArraySegment<by
|
||||
{
|
||||
if (i == transportId)
|
||||
{
|
||||
transports[i].ServerSend(baseConnectionId, channelId, segment);
|
||||
transports[i].ServerSend(baseConnectionId, segment, channelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public override void ClientDisconnect()
|
||||
client?.Disconnect();
|
||||
}
|
||||
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
if (!ClientConnected())
|
||||
{
|
||||
@ -244,7 +244,7 @@ public override void ServerDisconnect(int connectionId)
|
||||
server.KickClient(connectionId);
|
||||
}
|
||||
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
if (!ServerActive())
|
||||
{
|
||||
@ -265,7 +265,6 @@ public override void ServerSend(int connectionId, int channelId, ArraySegment<by
|
||||
}
|
||||
|
||||
server.SendOne(connectionId, segment);
|
||||
return;
|
||||
}
|
||||
|
||||
public override string ServerGetClientAddress(int connectionId)
|
||||
|
@ -131,7 +131,7 @@ public override void ClientConnect(Uri uri)
|
||||
int serverPort = uri.IsDefaultPort ? port : uri.Port;
|
||||
client.Connect(uri.Host, serverPort);
|
||||
}
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment) => client.Send(segment);
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId) => client.Send(segment);
|
||||
public override void ClientDisconnect() => client.Disconnect();
|
||||
// messages should always be processed in early update
|
||||
public override void ClientEarlyUpdate()
|
||||
@ -158,7 +158,7 @@ public override Uri ServerUri()
|
||||
}
|
||||
public override bool ServerActive() => server.Active;
|
||||
public override void ServerStart() => server.Start(port);
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment) => server.Send(connectionId, segment);
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) => server.Send(connectionId, segment);
|
||||
public override void ServerDisconnect(int connectionId) => server.Disconnect(connectionId);
|
||||
public override string ServerGetClientAddress(int connectionId)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public override void ClientConnect(string address)
|
||||
clientConnected = true;
|
||||
}
|
||||
}
|
||||
public override void ClientSend(int channelId, ArraySegment<byte> segment)
|
||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
// only if client connected
|
||||
if (clientConnected)
|
||||
@ -115,7 +115,7 @@ public override void ClientEarlyUpdate()
|
||||
public override bool ServerActive() => serverActive;
|
||||
public override Uri ServerUri() => throw new NotImplementedException();
|
||||
public override void ServerStart() { serverActive = true; }
|
||||
public override void ServerSend(int connectionId, int channelId, ArraySegment<byte> segment)
|
||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||
{
|
||||
// only if server is running and client is connected
|
||||
if (serverActive && clientConnected)
|
||||
|
@ -106,14 +106,12 @@ public void TestClientSend(int channel)
|
||||
const int count = 5;
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(array, offset, count);
|
||||
|
||||
middleware.ClientSend(channel, segment);
|
||||
middleware.ClientSend(segment, channel);
|
||||
|
||||
inner.Received(1).ClientSend(channel, Arg.Is<ArraySegment<byte>>(x => x.Array == array && x.Offset == offset && x.Count == count));
|
||||
inner.Received(0).ClientSend(Arg.Is<int>(x => x != channel), Arg.Any<ArraySegment<byte>>());
|
||||
inner.Received(1).ClientSend(Arg.Is<ArraySegment<byte>>(x => x.Array == array && x.Offset == offset && x.Count == count), channel);
|
||||
inner.Received(0).ClientSend(Arg.Any<ArraySegment<byte>>(), Arg.Is<int>(x => x != channel));
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
[TestCase(true)]
|
||||
[TestCase(false)]
|
||||
@ -154,11 +152,11 @@ public void TestServerSend(int id, int channel)
|
||||
const int count = 5;
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(array, offset, count);
|
||||
|
||||
middleware.ServerSend(id, channel, segment);
|
||||
middleware.ServerSend(id, segment, channel);
|
||||
|
||||
inner.Received(1).ServerSend(id, channel, Arg.Is<ArraySegment<byte>>(x => x.Array == array && x.Offset == offset && x.Count == count));
|
||||
inner.Received(1).ServerSend(id, Arg.Is<ArraySegment<byte>>(x => x.Array == array && x.Offset == offset && x.Count == count), channel);
|
||||
// only need to check first arg,
|
||||
inner.Received(0).ServerSend(Arg.Is<int>(x => x != id), Arg.Any<int>(), Arg.Any<ArraySegment<byte>>());
|
||||
inner.Received(0).ServerSend(Arg.Is<int>(x => x != id), Arg.Any<ArraySegment<byte>>(), Arg.Any<int>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -128,9 +128,9 @@ public void TestClientSend()
|
||||
byte[] data = { 1, 2, 3 };
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(data);
|
||||
|
||||
transport.ClientSend(3, segment);
|
||||
transport.ClientSend(segment, 3);
|
||||
|
||||
transport1.Received().ClientSend(3, segment);
|
||||
transport1.Received().ClientSend(segment, 3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -175,11 +175,10 @@ public void TestServerConnected()
|
||||
byte[] data = { 1, 2, 3 };
|
||||
ArraySegment<byte> segment = new ArraySegment<byte>(data);
|
||||
|
||||
|
||||
// on connect, send a message back
|
||||
void SendMessage(int connectionId)
|
||||
{
|
||||
transport.ServerSend(connectionId, 5, segment);
|
||||
transport.ServerSend(connectionId, segment, 5);
|
||||
}
|
||||
|
||||
// set event and Start to give event to inner
|
||||
@ -188,7 +187,7 @@ void SendMessage(int connectionId)
|
||||
|
||||
transport1.OnServerConnected.Invoke(1);
|
||||
|
||||
transport1.Received().ServerSend(1, 5, segment);
|
||||
transport1.Received().ServerSend(1, segment, 5);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user