mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
feature: Transport.OnClient/ServerDataSent events += (prepares for NetworkStatistics) (#3117)
* feature: Transport.OnClient/ServerDataSent events += (prepares for NetworkStatistics) * comments
This commit is contained in:
parent
dc5162099e
commit
b100307929
@ -42,6 +42,13 @@ public abstract class Transport : MonoBehaviour
|
|||||||
/// <summary>Called by Transport when the client received a message from the server.</summary>
|
/// <summary>Called by Transport when the client received a message from the server.</summary>
|
||||||
public Action<ArraySegment<byte>, int> OnClientDataReceived;
|
public Action<ArraySegment<byte>, int> OnClientDataReceived;
|
||||||
|
|
||||||
|
/// <summary>Called by Transport when the client sent a message to the server.</summary>
|
||||||
|
// Transports are responsible for calling it because:
|
||||||
|
// - groups it together with OnReceived responsibility
|
||||||
|
// - allows transports to decide if anything was sent or not
|
||||||
|
// - allows transports to decide the actual used channel (i.e. tcp always sending reliable)
|
||||||
|
public Action<ArraySegment<byte>, int> OnClientDataSent;
|
||||||
|
|
||||||
/// <summary>Called by Transport when the client encountered an error.</summary>
|
/// <summary>Called by Transport when the client encountered an error.</summary>
|
||||||
public Action<Exception> OnClientError;
|
public Action<Exception> OnClientError;
|
||||||
|
|
||||||
@ -79,6 +86,13 @@ public virtual void ClientConnect(Uri uri)
|
|||||||
/// <summary>Called by Transport when the server received a message from a client.</summary>
|
/// <summary>Called by Transport when the server received a message from a client.</summary>
|
||||||
public Action<int, ArraySegment<byte>, int> OnServerDataReceived;
|
public Action<int, ArraySegment<byte>, int> OnServerDataReceived;
|
||||||
|
|
||||||
|
/// <summary>Called by Transport when the server sent a message to a client.</summary>
|
||||||
|
// Transports are responsible for calling it because:
|
||||||
|
// - groups it together with OnReceived responsibility
|
||||||
|
// - allows transports to decide if anything was sent or not
|
||||||
|
// - allows transports to decide the actual used channel (i.e. tcp always sending reliable)
|
||||||
|
public Action<int, ArraySegment<byte>, int> OnServerDataSent;
|
||||||
|
|
||||||
/// <summary>Called by Transport when a server's connection encountered a problem.</summary>
|
/// <summary>Called by Transport when a server's connection encountered a problem.</summary>
|
||||||
/// If a Disconnect will also be raised, raise the Error first.
|
/// If a Disconnect will also be raised, raise the Error first.
|
||||||
public Action<int, Exception> OnServerError;
|
public Action<int, Exception> OnServerError;
|
||||||
|
@ -161,6 +161,9 @@ public override void ClientConnect(Uri uri)
|
|||||||
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||||
{
|
{
|
||||||
client.Send(segment, ToKcpChannel(channelId));
|
client.Send(segment, ToKcpChannel(channelId));
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnClientDataSent?.Invoke(segment, channelId);
|
||||||
}
|
}
|
||||||
public override void ClientDisconnect() => client.Disconnect();
|
public override void ClientDisconnect() => client.Disconnect();
|
||||||
// process incoming in early update
|
// process incoming in early update
|
||||||
@ -188,6 +191,9 @@ public override Uri ServerUri()
|
|||||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||||
{
|
{
|
||||||
server.Send(connectionId, segment, ToKcpChannel(channelId));
|
server.Send(connectionId, segment, ToKcpChannel(channelId));
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnServerDataSent?.Invoke(connectionId, segment, channelId);
|
||||||
}
|
}
|
||||||
public override void ServerDisconnect(int connectionId) => server.Disconnect(connectionId);
|
public override void ServerDisconnect(int connectionId) => server.Disconnect(connectionId);
|
||||||
public override string ServerGetClientAddress(int connectionId) => server.GetClientAddress(connectionId);
|
public override string ServerGetClientAddress(int connectionId) => server.GetClientAddress(connectionId);
|
||||||
|
@ -181,6 +181,9 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
|||||||
}
|
}
|
||||||
|
|
||||||
client.Send(segment);
|
client.Send(segment);
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnClientDataSent?.Invoke(segment, Channels.Reliable);
|
||||||
}
|
}
|
||||||
|
|
||||||
// messages should always be processed in early update
|
// messages should always be processed in early update
|
||||||
@ -259,6 +262,9 @@ public override void ServerSend(int connectionId, ArraySegment<byte> segment, in
|
|||||||
}
|
}
|
||||||
|
|
||||||
server.SendOne(connectionId, segment);
|
server.SendOne(connectionId, segment);
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnServerDataSent?.Invoke(connectionId, segment, Channels.Reliable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ServerGetClientAddress(int connectionId)
|
public override string ServerGetClientAddress(int connectionId)
|
||||||
|
@ -119,7 +119,13 @@ public override void ClientConnect(Uri uri)
|
|||||||
int serverPort = uri.IsDefaultPort ? port : uri.Port;
|
int serverPort = uri.IsDefaultPort ? port : uri.Port;
|
||||||
client.Connect(uri.Host, serverPort);
|
client.Connect(uri.Host, serverPort);
|
||||||
}
|
}
|
||||||
public override void ClientSend(ArraySegment<byte> segment, int channelId) => client?.Send(segment);
|
public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
||||||
|
{
|
||||||
|
client?.Send(segment);
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnClientDataSent?.Invoke(segment, Channels.Reliable);
|
||||||
|
}
|
||||||
public override void ClientDisconnect()
|
public override void ClientDisconnect()
|
||||||
{
|
{
|
||||||
client?.Disconnect();
|
client?.Disconnect();
|
||||||
@ -176,7 +182,13 @@ public override void ServerStart()
|
|||||||
server.Start(port);
|
server.Start(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId) => server?.Send(connectionId, segment);
|
public override void ServerSend(int connectionId, ArraySegment<byte> segment, int channelId)
|
||||||
|
{
|
||||||
|
server?.Send(connectionId, segment);
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnServerDataSent?.Invoke(connectionId, segment, Channels.Reliable);
|
||||||
|
}
|
||||||
public override void ServerDisconnect(int connectionId) => server?.Disconnect(connectionId);
|
public override void ServerDisconnect(int connectionId) => server?.Disconnect(connectionId);
|
||||||
public override string ServerGetClientAddress(int connectionId)
|
public override string ServerGetClientAddress(int connectionId)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +72,9 @@ public override void ClientSend(ArraySegment<byte> segment, int channelId)
|
|||||||
|
|
||||||
// add server data message with connId=1 because 0 is reserved
|
// add server data message with connId=1 because 0 is reserved
|
||||||
serverIncoming.Enqueue(new Message(1, EventType.Data, data));
|
serverIncoming.Enqueue(new Message(1, EventType.Data, data));
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnClientDataSent?.Invoke(segment, channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public override void ClientDisconnect()
|
public override void ClientDisconnect()
|
||||||
@ -147,6 +150,9 @@ public override void ServerSend(int connectionId, ArraySegment<byte> segment, in
|
|||||||
|
|
||||||
// add client data message
|
// add client data message
|
||||||
clientIncoming.Enqueue(new Message(0, EventType.Data, data));
|
clientIncoming.Enqueue(new Message(0, EventType.Data, data));
|
||||||
|
|
||||||
|
// call event. might be null if no statistics are listening etc.
|
||||||
|
OnServerDataSent?.Invoke(connectionId, segment, channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user