mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
ChannelBuffer/ChannelPacket/PacketStat/GetStatsInOut/ChannelOption removed because ChanneLBuffer's job was to: buffer packets and only send them every now and then to save bandwidth, to handle fragmentation, and to handle resending reliable messages. NetworkTransport already takes care of all of that in the newer versions, e.g. with ConnectionConfig.SendDelay, so none of it is needed anymore.
This commit is contained in:
parent
368543b734
commit
89d45e1e1b
@ -40,8 +40,6 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\Runtime\ChannelBuffer.cs" />
|
||||
<Compile Include="..\Runtime\ChannelPacket.cs" />
|
||||
<Compile Include="..\Runtime\ClientScene.cs" />
|
||||
<Compile Include="..\Runtime\ConnectionArray.cs" />
|
||||
<Compile Include="..\Runtime\CustomAttributes.cs" />
|
||||
|
@ -1,362 +0,0 @@
|
||||
#if ENABLE_UNET
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace UnityEngine.Networking
|
||||
{
|
||||
class ChannelBuffer : IDisposable
|
||||
{
|
||||
NetworkConnection m_Connection;
|
||||
|
||||
ChannelPacket m_CurrentPacket;
|
||||
|
||||
float m_LastFlushTime;
|
||||
|
||||
byte m_ChannelId;
|
||||
int m_MaxPacketSize;
|
||||
bool m_IsReliable;
|
||||
bool m_AllowFragmentation;
|
||||
bool m_IsBroken;
|
||||
int m_MaxPendingPacketCount;
|
||||
|
||||
public const int MaxBufferedPackets = 512; // this is per connection. each is around 1400 bytes (MTU)
|
||||
|
||||
Queue<ChannelPacket> m_PendingPackets;
|
||||
static internal int pendingPacketCount; // this is across all connections. only used for profiler metrics.
|
||||
|
||||
// config
|
||||
public float maxDelay = 0.01f;
|
||||
|
||||
// stats
|
||||
float m_LastBufferedMessageCountTimer = Time.realtimeSinceStartup;
|
||||
|
||||
public int numMsgsOut { get; private set; }
|
||||
public int numBufferedMsgsOut { get; private set; }
|
||||
public int numBytesOut { get; private set; }
|
||||
|
||||
public int numMsgsIn { get; private set; }
|
||||
public int numBytesIn { get; private set; }
|
||||
|
||||
public int numBufferedPerSecond { get; private set; }
|
||||
public int lastBufferedPerSecond { get; private set; }
|
||||
|
||||
// We need to reserve some space for header information, this will be taken off the total channel buffer size
|
||||
const int k_PacketHeaderReserveSize = 100;
|
||||
|
||||
public ChannelBuffer(NetworkConnection conn, int bufferSize, byte cid, bool isReliable, bool isSequenced)
|
||||
{
|
||||
m_Connection = conn;
|
||||
m_MaxPacketSize = bufferSize - k_PacketHeaderReserveSize;
|
||||
m_CurrentPacket = new ChannelPacket(m_MaxPacketSize, isReliable);
|
||||
|
||||
m_ChannelId = cid;
|
||||
m_MaxPendingPacketCount = MaxBufferedPackets;
|
||||
m_IsReliable = isReliable;
|
||||
m_AllowFragmentation = (isReliable && isSequenced);
|
||||
if (isReliable)
|
||||
{
|
||||
m_PendingPackets = new Queue<ChannelPacket>();
|
||||
}
|
||||
}
|
||||
|
||||
// Track whether Dispose has been called.
|
||||
bool m_Disposed;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
// Take yourself off the Finalization queue
|
||||
// to prevent finalization code for this object
|
||||
// from executing a second time.
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_Disposed)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (m_PendingPackets != null)
|
||||
{
|
||||
pendingPacketCount = 0;
|
||||
m_PendingPackets.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
m_Disposed = true;
|
||||
}
|
||||
|
||||
public bool SetOption(ChannelOption option, int value)
|
||||
{
|
||||
switch (option)
|
||||
{
|
||||
case ChannelOption.MaxPendingBuffers:
|
||||
{
|
||||
if (!m_IsReliable)
|
||||
{
|
||||
// not an error
|
||||
//if (LogFilter.logError) { Debug.LogError("Cannot set MaxPendingBuffers on unreliable channel " + m_ChannelId); }
|
||||
return false;
|
||||
}
|
||||
if (value < 0 || value >= MaxBufferedPackets)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Invalid MaxPendingBuffers for channel " + m_ChannelId + ". Must be greater than zero and less than " + MaxBufferedPackets); }
|
||||
return false;
|
||||
}
|
||||
m_MaxPendingPacketCount = value;
|
||||
return true;
|
||||
}
|
||||
|
||||
case ChannelOption.AllowFragmentation:
|
||||
{
|
||||
m_AllowFragmentation = (value != 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
case ChannelOption.MaxPacketSize:
|
||||
{
|
||||
if (!m_CurrentPacket.IsEmpty() || m_PendingPackets.Count > 0)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Cannot set MaxPacketSize after sending data."); }
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value <= 0)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Cannot set MaxPacketSize less than one."); }
|
||||
return false;
|
||||
}
|
||||
|
||||
if (value > m_MaxPacketSize)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Cannot set MaxPacketSize to greater than the existing maximum (" + m_MaxPacketSize + ")."); }
|
||||
return false;
|
||||
}
|
||||
// rebuild the packet with the new size. the packets doesn't store a size variable, just has the size of the internal buffer
|
||||
m_CurrentPacket = new ChannelPacket(value, m_IsReliable);
|
||||
m_MaxPacketSize = value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void CheckInternalBuffer()
|
||||
{
|
||||
if (Time.realtimeSinceStartup - m_LastFlushTime > maxDelay && !m_CurrentPacket.IsEmpty())
|
||||
{
|
||||
SendInternalBuffer();
|
||||
m_LastFlushTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
if (Time.realtimeSinceStartup - m_LastBufferedMessageCountTimer > 1.0f)
|
||||
{
|
||||
lastBufferedPerSecond = numBufferedPerSecond;
|
||||
numBufferedPerSecond = 0;
|
||||
m_LastBufferedMessageCountTimer = Time.realtimeSinceStartup;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SendWriter(NetworkWriter writer)
|
||||
{
|
||||
// write relevant data, which is until .Position
|
||||
return SendBytes(writer.ToArray(), writer.Position);
|
||||
}
|
||||
|
||||
public bool Send(short msgType, MessageBase msg)
|
||||
{
|
||||
// build the stream
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
writer.StartMessage(msgType);
|
||||
msg.Serialize(writer);
|
||||
writer.FinishMessage();
|
||||
|
||||
numMsgsOut += 1;
|
||||
return SendWriter(writer);
|
||||
}
|
||||
|
||||
internal MemoryStream fragmentBuffer = new MemoryStream();
|
||||
bool readingFragment = false;
|
||||
|
||||
internal bool HandleFragment(NetworkReader reader)
|
||||
{
|
||||
int state = reader.ReadByte();
|
||||
if (state == 0)
|
||||
{
|
||||
if (readingFragment == false)
|
||||
{
|
||||
fragmentBuffer.Position = 0;
|
||||
readingFragment = true;
|
||||
}
|
||||
|
||||
byte[] data = reader.ReadBytesAndSize();
|
||||
fragmentBuffer.Write(data, 0, data.Length);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
readingFragment = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal bool SendFragmentBytes(byte[] bytes, int bytesToSend)
|
||||
{
|
||||
const int fragmentHeaderSize = 32;
|
||||
int pos = 0;
|
||||
while (bytesToSend > 0)
|
||||
{
|
||||
int diff = Math.Min(bytesToSend, m_MaxPacketSize - fragmentHeaderSize);
|
||||
|
||||
// send fragment
|
||||
NetworkWriter fragmentWriter = new NetworkWriter();
|
||||
fragmentWriter.StartMessage(MsgType.Fragment);
|
||||
fragmentWriter.Write((byte)0);
|
||||
fragmentWriter.WriteBytesAndSize(bytes, pos, diff);
|
||||
fragmentWriter.FinishMessage();
|
||||
SendWriter(fragmentWriter);
|
||||
|
||||
pos += diff;
|
||||
bytesToSend -= diff;
|
||||
}
|
||||
|
||||
// send finish
|
||||
NetworkWriter finishWriter = new NetworkWriter();
|
||||
finishWriter.StartMessage(MsgType.Fragment);
|
||||
finishWriter.Write((byte)1);
|
||||
finishWriter.FinishMessage();
|
||||
SendWriter(finishWriter);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal bool SendBytes(byte[] bytes, int bytesToSend)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.NetworkDetailStats.IncrementStat(
|
||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||
MsgType.HLAPIMsg, "msg", 1);
|
||||
#endif
|
||||
if (bytesToSend > UInt16.MaxValue)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytesToSend <= 0)
|
||||
{
|
||||
// zero length packets getting into the packet queues are bad.
|
||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytesToSend > m_MaxPacketSize)
|
||||
{
|
||||
if (m_AllowFragmentation)
|
||||
{
|
||||
return SendFragmentBytes(bytes, bytesToSend);
|
||||
}
|
||||
else
|
||||
{
|
||||
// cannot do HLAPI fragmentation on this channel
|
||||
if (LogFilter.logError) { Debug.LogError("Failed to send big message of " + bytesToSend + " bytes. The maximum is " + m_MaxPacketSize + " bytes on channel:" + m_ChannelId); }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_CurrentPacket.HasSpace(bytesToSend))
|
||||
{
|
||||
if (m_IsReliable)
|
||||
{
|
||||
if (m_PendingPackets.Count == 0)
|
||||
{
|
||||
// nothing in the pending queue yet, just flush and write
|
||||
if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
|
||||
{
|
||||
QueuePacket();
|
||||
}
|
||||
m_CurrentPacket.Write(bytes, bytesToSend);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (m_PendingPackets.Count >= m_MaxPendingPacketCount)
|
||||
{
|
||||
if (!m_IsBroken)
|
||||
{
|
||||
// only log this once, or it will spam the log constantly
|
||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer buffer limit of " + m_PendingPackets.Count + " packets reached."); }
|
||||
}
|
||||
m_IsBroken = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// calling SendToTransport here would write out-of-order data to the stream. just queue
|
||||
QueuePacket();
|
||||
m_CurrentPacket.Write(bytes, bytesToSend);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId))
|
||||
{
|
||||
if (LogFilter.logError) { Debug.Log("ChannelBuffer SendBytes no space on unreliable channel " + m_ChannelId); }
|
||||
return false;
|
||||
}
|
||||
|
||||
m_CurrentPacket.Write(bytes, bytesToSend);
|
||||
return true;
|
||||
}
|
||||
|
||||
m_CurrentPacket.Write(bytes, bytesToSend);
|
||||
if (maxDelay == 0.0f)
|
||||
{
|
||||
return SendInternalBuffer();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void QueuePacket()
|
||||
{
|
||||
pendingPacketCount += 1;
|
||||
m_PendingPackets.Enqueue(m_CurrentPacket);
|
||||
|
||||
// create new m_currentPacket so that the one in the queue isn't touched anymore
|
||||
// (calling .Reset would reset it in the queue too)
|
||||
m_CurrentPacket = new ChannelPacket(m_MaxPacketSize, m_IsReliable);
|
||||
}
|
||||
|
||||
public bool SendInternalBuffer()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.NetworkDetailStats.IncrementStat(
|
||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||
MsgType.LLAPIMsg, "msg", 1);
|
||||
#endif
|
||||
if (m_IsReliable && m_PendingPackets.Count > 0)
|
||||
{
|
||||
// send until transport can take no more
|
||||
while (m_PendingPackets.Count > 0)
|
||||
{
|
||||
var packet = m_PendingPackets.Dequeue();
|
||||
if (!packet.SendToTransport(m_Connection, m_ChannelId))
|
||||
{
|
||||
m_PendingPackets.Enqueue(packet);
|
||||
break;
|
||||
}
|
||||
pendingPacketCount -= 1;
|
||||
|
||||
if (m_IsBroken && m_PendingPackets.Count < (m_MaxPendingPacketCount / 2))
|
||||
{
|
||||
if (LogFilter.logWarn) { Debug.LogWarning("ChannelBuffer recovered from overflow but data was lost."); }
|
||||
m_IsBroken = false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return m_CurrentPacket.SendToTransport(m_Connection, m_ChannelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //ENABLE_UNET
|
@ -1,71 +0,0 @@
|
||||
#if ENABLE_UNET
|
||||
using System;
|
||||
|
||||
namespace UnityEngine.Networking
|
||||
{
|
||||
// This is used by the ChannelBuffer when buffering traffic.
|
||||
// Unreliable channels have a single ChannelPacket, Reliable channels have single "current" packet and a list of buffered ChannelPackets
|
||||
struct ChannelPacket
|
||||
{
|
||||
int m_Position;
|
||||
byte[] m_Buffer;
|
||||
bool m_IsReliable;
|
||||
|
||||
public ChannelPacket(int packetSize, bool isReliable)
|
||||
{
|
||||
m_Position = 0;
|
||||
m_Buffer = new byte[packetSize];
|
||||
m_IsReliable = isReliable;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
m_Position = 0;
|
||||
}
|
||||
|
||||
public bool IsEmpty()
|
||||
{
|
||||
return m_Position == 0;
|
||||
}
|
||||
|
||||
public void Write(byte[] bytes, int numBytes)
|
||||
{
|
||||
Array.Copy(bytes, 0, m_Buffer, m_Position, numBytes);
|
||||
m_Position += numBytes;
|
||||
}
|
||||
|
||||
public bool HasSpace(int numBytes)
|
||||
{
|
||||
return m_Position + numBytes <= m_Buffer.Length;
|
||||
}
|
||||
|
||||
public bool SendToTransport(NetworkConnection conn, int channelId)
|
||||
{
|
||||
byte error;
|
||||
if (conn.TransportSend(m_Buffer, (ushort)m_Position, channelId, out error))
|
||||
{
|
||||
m_Position = 0;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NoResources and reliable? Then it will be resent, so don't reset position, just return false.
|
||||
if (error == (int)NetworkError.NoResources && m_IsReliable)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.NetworkDetailStats.IncrementStat(
|
||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||
MsgType.HLAPIResend, "msg", 1);
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// otherwise something unexpected happened. log the error, reset position and return.
|
||||
if (LogFilter.logError) { Debug.LogError("SendToTransport failed. error:" + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + m_Position); }
|
||||
m_Position = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //ENABLE_UNET
|
@ -48,20 +48,6 @@ public override bool SendWriter(NetworkWriter writer, int channelId)
|
||||
m_LocalClient.InvokeBytesOnClient(writer.ToArray(), channelId);
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBufferedMsgs = 0;
|
||||
numBytes = 0;
|
||||
lastBufferedPerSecond = 0;
|
||||
}
|
||||
|
||||
public override void GetStatsIn(out int numMsgs, out int numBytes)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBytes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// a localClient's connection TO a server.
|
||||
@ -105,20 +91,6 @@ public override bool SendWriter(NetworkWriter writer, int channelId)
|
||||
// write relevant data, which is until .Position
|
||||
return NetworkServer.InvokeBytes(this, writer.ToArray(), (short)writer.Position, channelId);
|
||||
}
|
||||
|
||||
public override void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBufferedMsgs = 0;
|
||||
numBytes = 0;
|
||||
lastBufferedPerSecond = 0;
|
||||
}
|
||||
|
||||
public override void GetStatsIn(out int numMsgs, out int numBytes)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBytes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //ENABLE_UNET
|
||||
|
@ -33,8 +33,6 @@ public class NetworkClient
|
||||
int m_ClientConnectionId = -1;
|
||||
//int m_RelaySlotId = -1;
|
||||
|
||||
int m_StatResetTime;
|
||||
|
||||
EndPoint m_RemoteEndPoint;
|
||||
|
||||
NetworkMessageHandlers m_MessageHandlers = new NetworkMessageHandlers();
|
||||
@ -430,16 +428,6 @@ public bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
||||
public bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
||||
public bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
||||
|
||||
public void SetMaxDelay(float seconds)
|
||||
{
|
||||
if (m_Connection == null)
|
||||
{
|
||||
if (LogFilter.logWarn) { Debug.LogWarning("SetMaxDelay failed, not connected."); }
|
||||
return;
|
||||
}
|
||||
m_Connection.SetMaxDelay(seconds);
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
if (LogFilter.logDebug) Debug.Log("Shutting down client " + m_ClientId);
|
||||
@ -486,15 +474,6 @@ internal virtual void Update()
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Connection != null)
|
||||
{
|
||||
if ((int)Time.time != m_StatResetTime)
|
||||
{
|
||||
m_Connection.ResetStats();
|
||||
m_StatResetTime = (int)Time.time;
|
||||
}
|
||||
}
|
||||
|
||||
int numEvents = 0;
|
||||
NetworkEventType networkEvent;
|
||||
do
|
||||
@ -583,9 +562,6 @@ internal virtual void Update()
|
||||
}
|
||||
}
|
||||
while (networkEvent != NetworkEventType.Nothing);
|
||||
|
||||
if (m_Connection != null && m_AsyncConnect == ConnectState.Connected)
|
||||
m_Connection.FlushChannels();
|
||||
}
|
||||
|
||||
void GenerateConnectError(byte error)
|
||||
@ -633,46 +609,6 @@ void GenerateError(byte error)
|
||||
}
|
||||
}
|
||||
|
||||
public void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBufferedMsgs = 0;
|
||||
numBytes = 0;
|
||||
lastBufferedPerSecond = 0;
|
||||
|
||||
if (m_Connection != null)
|
||||
{
|
||||
m_Connection.GetStatsOut(out numMsgs, out numBufferedMsgs, out numBytes, out lastBufferedPerSecond);
|
||||
}
|
||||
}
|
||||
|
||||
public void GetStatsIn(out int numMsgs, out int numBytes)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBytes = 0;
|
||||
|
||||
if (m_Connection != null)
|
||||
{
|
||||
m_Connection.GetStatsIn(out numMsgs, out numBytes);
|
||||
}
|
||||
}
|
||||
|
||||
public Dictionary<short, NetworkConnection.PacketStat> GetConnectionStats()
|
||||
{
|
||||
if (m_Connection == null)
|
||||
return null;
|
||||
|
||||
return m_Connection.packetStats;
|
||||
}
|
||||
|
||||
public void ResetConnectionStats()
|
||||
{
|
||||
if (m_Connection == null)
|
||||
return;
|
||||
|
||||
m_Connection.ResetStats();
|
||||
}
|
||||
|
||||
public int GetRTT()
|
||||
{
|
||||
if (m_ClientId == -1)
|
||||
@ -685,7 +621,6 @@ public int GetRTT()
|
||||
internal void RegisterSystemHandlers(bool localClient)
|
||||
{
|
||||
ClientScene.RegisterSystemHandlers(this, localClient);
|
||||
RegisterHandlerSafe(MsgType.Fragment, NetworkConnection.OnFragment);
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
|
||||
@ -703,31 +638,6 @@ public void UnregisterHandler(short msgType)
|
||||
m_MessageHandlers.UnregisterHandler(msgType);
|
||||
}
|
||||
|
||||
static public Dictionary<short, NetworkConnection.PacketStat> GetTotalConnectionStats()
|
||||
{
|
||||
Dictionary<short, NetworkConnection.PacketStat> stats = new Dictionary<short, NetworkConnection.PacketStat>();
|
||||
for (int i = 0; i < s_Clients.Count; i++)
|
||||
{
|
||||
var client = s_Clients[i];
|
||||
var clientStats = client.GetConnectionStats();
|
||||
foreach (short k in clientStats.Keys)
|
||||
{
|
||||
if (stats.ContainsKey(k))
|
||||
{
|
||||
NetworkConnection.PacketStat s = stats[k];
|
||||
s.count += clientStats[k].count;
|
||||
s.bytes += clientStats[k].bytes;
|
||||
stats[k] = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
stats[k] = new NetworkConnection.PacketStat(clientStats[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
internal static void AddClient(NetworkClient client)
|
||||
{
|
||||
s_Clients.Add(client);
|
||||
|
@ -12,7 +12,6 @@ namespace UnityEngine.Networking
|
||||
*/
|
||||
public class NetworkConnection : IDisposable
|
||||
{
|
||||
ChannelBuffer[] m_Channels;
|
||||
List<PlayerController> m_PlayerControllers = new List<PlayerController>();
|
||||
HashSet<NetworkIdentity> m_VisList = new HashSet<NetworkIdentity>();
|
||||
internal HashSet<NetworkIdentity> visList { get { return m_VisList; } }
|
||||
@ -36,38 +35,8 @@ public class NetworkConnection : IDisposable
|
||||
public bool logNetworkMessages = false;
|
||||
public bool isConnected { get { return hostId != -1; }}
|
||||
|
||||
|
||||
public class PacketStat
|
||||
{
|
||||
public PacketStat()
|
||||
{
|
||||
msgType = 0;
|
||||
count = 0;
|
||||
bytes = 0;
|
||||
}
|
||||
|
||||
public PacketStat(PacketStat s)
|
||||
{
|
||||
msgType = s.msgType;
|
||||
count = s.count;
|
||||
bytes = s.bytes;
|
||||
}
|
||||
|
||||
public short msgType;
|
||||
public int count;
|
||||
public int bytes;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return MsgType.MsgTypeToString(msgType) + ": count=" + count + " bytes=" + bytes;
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkError lastError { get { return error; } internal set { error = value; } }
|
||||
|
||||
Dictionary<short, PacketStat> m_PacketStats = new Dictionary<short, PacketStat>();
|
||||
internal Dictionary<short, PacketStat> packetStats { get { return m_PacketStats; }}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static int s_MaxPacketStats = 255;//the same as maximum message types
|
||||
#endif
|
||||
@ -78,28 +47,10 @@ public virtual void Initialize(string networkAddress, int networkHostId, int net
|
||||
hostId = networkHostId;
|
||||
connectionId = networkConnectionId;
|
||||
|
||||
int numChannels = hostTopology.DefaultConfig.ChannelCount;
|
||||
int packetSize = hostTopology.DefaultConfig.PacketSize;
|
||||
|
||||
if ((hostTopology.DefaultConfig.UsePlatformSpecificProtocols) && (Application.platform != RuntimePlatform.PS4) && (Application.platform != RuntimePlatform.PSP2))
|
||||
throw new ArgumentOutOfRangeException("Platform specific protocols are not supported on this platform");
|
||||
|
||||
m_Channels = new ChannelBuffer[numChannels];
|
||||
for (int i = 0; i < numChannels; i++)
|
||||
{
|
||||
var qos = hostTopology.DefaultConfig.Channels[i];
|
||||
int actualPacketSize = packetSize;
|
||||
if (qos.QOS == QosType.ReliableFragmented || qos.QOS == QosType.UnreliableFragmented)
|
||||
{
|
||||
actualPacketSize = hostTopology.DefaultConfig.FragmentSize * 128;
|
||||
}
|
||||
m_Channels[i] = new ChannelBuffer(this, actualPacketSize, (byte)i, Channels.IsReliableQoS(qos.QOS), Channels.IsSequencedQoS(qos.QOS));
|
||||
}
|
||||
}
|
||||
|
||||
// Track whether Dispose has been called.
|
||||
bool m_Disposed;
|
||||
|
||||
~NetworkConnection()
|
||||
{
|
||||
Dispose(false);
|
||||
@ -116,16 +67,6 @@ public void Dispose()
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
// Check to see if Dispose has already been called.
|
||||
if (!m_Disposed && m_Channels != null)
|
||||
{
|
||||
for (int i = 0; i < m_Channels.Length; i++)
|
||||
{
|
||||
m_Channels[i].Dispose();
|
||||
}
|
||||
}
|
||||
m_Channels = null;
|
||||
|
||||
if (m_ClientOwnedObjects != null)
|
||||
{
|
||||
foreach (var netId in m_ClientOwnedObjects)
|
||||
@ -138,19 +79,6 @@ protected virtual void Dispose(bool disposing)
|
||||
}
|
||||
}
|
||||
m_ClientOwnedObjects = null;
|
||||
|
||||
m_Disposed = true;
|
||||
}
|
||||
|
||||
public bool SetChannelOption(int channelId, ChannelOption option, int value)
|
||||
{
|
||||
if (m_Channels == null)
|
||||
return false;
|
||||
|
||||
if (channelId < 0 || channelId >= m_Channels.Length)
|
||||
return false;
|
||||
|
||||
return m_Channels[channelId].SetOption(option, value);
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
@ -218,23 +146,6 @@ public bool InvokeHandler(NetworkMessage netMsg)
|
||||
return false;
|
||||
}
|
||||
|
||||
internal void HandleFragment(NetworkReader reader, int channelId)
|
||||
{
|
||||
if (channelId < 0 || channelId >= m_Channels.Length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var channel = m_Channels[channelId];
|
||||
if (channel.HandleFragment(reader))
|
||||
{
|
||||
NetworkReader msgReader = new NetworkReader(channel.fragmentBuffer.ToArray());
|
||||
msgReader.ReadInt16(); // size
|
||||
short msgType = msgReader.ReadInt16();
|
||||
InvokeHandler(msgType, msgReader, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
public void RegisterHandler(short msgType, NetworkMessageDelegate handler)
|
||||
{
|
||||
m_MessageHandlers.RegisterHandler(msgType, handler);
|
||||
@ -277,30 +188,6 @@ internal bool GetPlayerController(short playerControllerId, out PlayerController
|
||||
return playerController != null;
|
||||
}
|
||||
|
||||
public void FlushChannels()
|
||||
{
|
||||
if (m_Channels == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int channelId = 0; channelId < m_Channels.Length; channelId++)
|
||||
{
|
||||
m_Channels[channelId].CheckInternalBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMaxDelay(float seconds)
|
||||
{
|
||||
if (m_Channels == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int channelId = 0; channelId < m_Channels.Length; channelId++)
|
||||
{
|
||||
m_Channels[channelId].maxDelay = seconds;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
||||
{
|
||||
NetworkWriter writer = new NetworkWriter();
|
||||
@ -312,22 +199,39 @@ public virtual bool SendByChannel(short msgType, MessageBase msg, int channelId)
|
||||
public virtual bool Send(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultReliable); }
|
||||
public virtual bool SendUnreliable(short msgType, MessageBase msg) { return SendByChannel(msgType, msg, Channels.DefaultUnreliable); }
|
||||
|
||||
public virtual bool SendBytes(byte[] bytes, int numBytes, int channelId)
|
||||
public virtual bool SendBytes(byte[] bytes, int bytesToSend, int channelId)
|
||||
{
|
||||
if (logNetworkMessages)
|
||||
{
|
||||
LogSend(bytes);
|
||||
}
|
||||
return CheckChannel(channelId) && m_Channels[channelId].SendBytes(bytes, numBytes);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
UnityEditor.NetworkDetailStats.IncrementStat(
|
||||
UnityEditor.NetworkDetailStats.NetworkDirection.Outgoing,
|
||||
MsgType.HLAPIMsg, "msg", 1);
|
||||
#endif
|
||||
if (bytesToSend > UInt16.MaxValue)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send packet larger than " + UInt16.MaxValue + " bytes"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bytesToSend <= 0)
|
||||
{
|
||||
// zero length packets getting into the packet queues are bad.
|
||||
if (LogFilter.logError) { Debug.LogError("ChannelBuffer:SendBytes cannot send zero bytes"); }
|
||||
return false;
|
||||
}
|
||||
|
||||
byte error;
|
||||
return TransportSend(bytes, bytesToSend, channelId, out error);
|
||||
}
|
||||
|
||||
public virtual bool SendWriter(NetworkWriter writer, int channelId)
|
||||
{
|
||||
if (logNetworkMessages)
|
||||
{
|
||||
LogSend(writer.ToArray());
|
||||
}
|
||||
return CheckChannel(channelId) && m_Channels[channelId].SendWriter(writer);
|
||||
// write relevant data, which is until .Position
|
||||
return SendBytes(writer.ToArray(), writer.Position, channelId);
|
||||
}
|
||||
|
||||
void LogSend(byte[] bytes)
|
||||
@ -346,39 +250,7 @@ void LogSend(byte[] bytes)
|
||||
}
|
||||
Debug.Log("ConnectionSend con:" + connectionId + " bytes:" + msgSize + " msgId:" + msgId + " " + msg);
|
||||
}
|
||||
|
||||
bool CheckChannel(int channelId)
|
||||
{
|
||||
if (m_Channels == null)
|
||||
{
|
||||
if (LogFilter.logWarn) { Debug.LogWarning("Channels not initialized sending on id '" + channelId); }
|
||||
return false;
|
||||
}
|
||||
if (channelId < 0 || channelId >= m_Channels.Length)
|
||||
{
|
||||
if (LogFilter.logError) { Debug.LogError("Invalid channel when sending buffered data, '" + channelId + "'. Current channel count is " + m_Channels.Length); }
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ResetStats()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
for (short i = 0; i < s_MaxPacketStats; i++)
|
||||
{
|
||||
if (m_PacketStats.ContainsKey(i))
|
||||
{
|
||||
var value = m_PacketStats[i];
|
||||
value.count = 0;
|
||||
value.bytes = 0;
|
||||
NetworkTransport.SetPacketStat(0, i, 0, 0);
|
||||
NetworkTransport.SetPacketStat(1, i, 0, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
protected void HandleBytes(byte[] buffer, int receivedSize, int channelId)
|
||||
{
|
||||
// build the stream form the buffer passed in
|
||||
@ -450,23 +322,6 @@ protected void HandleReader(NetworkReader reader, int receivedSize, int channelI
|
||||
MsgType.UserMessage, msgType.ToString() + ":" + msgType.GetType().Name, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (m_PacketStats.ContainsKey(msgType))
|
||||
{
|
||||
PacketStat stat = m_PacketStats[msgType];
|
||||
stat.count += 1;
|
||||
stat.bytes += sz;
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketStat stat = new PacketStat();
|
||||
stat.msgType = msgType;
|
||||
stat.count += 1;
|
||||
stat.bytes += sz;
|
||||
m_PacketStats[msgType] = stat;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -477,39 +332,9 @@ protected void HandleReader(NetworkReader reader, int receivedSize, int channelI
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBufferedMsgs = 0;
|
||||
numBytes = 0;
|
||||
lastBufferedPerSecond = 0;
|
||||
|
||||
for (int channelId = 0; channelId < m_Channels.Length; channelId++)
|
||||
{
|
||||
var channel = m_Channels[channelId];
|
||||
numMsgs += channel.numMsgsOut;
|
||||
numBufferedMsgs += channel.numBufferedMsgsOut;
|
||||
numBytes += channel.numBytesOut;
|
||||
lastBufferedPerSecond += channel.lastBufferedPerSecond;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void GetStatsIn(out int numMsgs, out int numBytes)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBytes = 0;
|
||||
|
||||
for (int channelId = 0; channelId < m_Channels.Length; channelId++)
|
||||
{
|
||||
var channel = m_Channels[channelId];
|
||||
numMsgs += channel.numMsgsIn;
|
||||
numBytes += channel.numBytesIn;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("hostId: {0} connectionId: {1} isReady: {2} channel count: {3}", hostId, connectionId, isReady, (m_Channels != null ? m_Channels.Length : 0));
|
||||
return string.Format("hostId: {0} connectionId: {1} isReady: {2}", hostId, connectionId, isReady);
|
||||
}
|
||||
|
||||
internal void AddToVisList(NetworkIdentity uv)
|
||||
@ -547,7 +372,16 @@ public virtual void TransportReceive(byte[] bytes, int numBytes, int channelId)
|
||||
|
||||
public virtual bool TransportSend(byte[] bytes, int numBytes, int channelId, out byte error)
|
||||
{
|
||||
return NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error);
|
||||
if (NetworkTransport.Send(hostId, connectionId, channelId, bytes, numBytes, out error))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// ChannelPacket used to log errors. we do it here now.
|
||||
if (LogFilter.logError) { Debug.LogError("SendToTransport failed. error:" + (NetworkError)error + " channel:" + channelId + " bytesToSend:" + numBytes); }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddOwnedObject(NetworkIdentity obj)
|
||||
@ -568,11 +402,6 @@ internal void RemoveOwnedObject(NetworkIdentity obj)
|
||||
m_ClientOwnedObjects.Remove(obj.netId);
|
||||
}
|
||||
|
||||
internal static void OnFragment(NetworkMessage netMsg)
|
||||
{
|
||||
netMsg.conn.HandleFragment(netMsg.reader, netMsg.channelId);
|
||||
}
|
||||
|
||||
// vis2k: pause mode
|
||||
// problem: if we handle packets (calling the msgDelegates) while a scene load is in progress, then all the
|
||||
// handled data and state will be lost as soon as the scene load is finished, causing state bugs.
|
||||
|
@ -47,8 +47,8 @@ public class NetworkManager : MonoBehaviour
|
||||
[SerializeField] int m_SimulatedLatency = 1;
|
||||
[SerializeField] float m_PacketLossPercentage;
|
||||
|
||||
[SerializeField] int m_MaxBufferedPackets = ChannelBuffer.MaxBufferedPackets;
|
||||
[SerializeField] bool m_AllowFragmentation = true;
|
||||
[SerializeField] int m_MaxBufferedPackets = 0; // not used anymore, but keep it for compatibility
|
||||
[SerializeField] bool m_AllowFragmentation = true; // not used anymore, but keep it for compatibility
|
||||
|
||||
// matchmaking configuration
|
||||
[SerializeField] string m_MatchHost = "mm.unet.unity3d.com";
|
||||
@ -201,12 +201,7 @@ void OnValidate()
|
||||
m_PacketLossPercentage = Mathf.Clamp(m_PacketLossPercentage, 0, 99); // [0, 99]
|
||||
m_MaxConnections = Mathf.Clamp(m_MaxConnections, 1, 32000); // [1, 32000]
|
||||
|
||||
if (m_MaxBufferedPackets <= 0) m_MaxBufferedPackets = 0;
|
||||
if (m_MaxBufferedPackets > ChannelBuffer.MaxBufferedPackets)
|
||||
{
|
||||
m_MaxBufferedPackets = ChannelBuffer.MaxBufferedPackets;
|
||||
if (LogFilter.logError) { Debug.LogError("NetworkManager - MaxBufferedPackets cannot be more than " + ChannelBuffer.MaxBufferedPackets); }
|
||||
}
|
||||
m_MaxBufferedPackets = 0; // not used anymore, but keep it for compatibility
|
||||
|
||||
if (m_PlayerPrefab != null && m_PlayerPrefab.GetComponent<NetworkIdentity>() == null)
|
||||
{
|
||||
@ -764,24 +759,6 @@ internal void OnServerConnectInternal(NetworkMessage netMsg)
|
||||
{
|
||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnServerConnectInternal"); }
|
||||
|
||||
netMsg.conn.SetMaxDelay(m_MaxDelay);
|
||||
|
||||
if (m_MaxBufferedPackets != ChannelBuffer.MaxBufferedPackets)
|
||||
{
|
||||
for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++)
|
||||
{
|
||||
netMsg.conn.SetChannelOption(channelId, ChannelOption.MaxPendingBuffers, m_MaxBufferedPackets);
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_AllowFragmentation)
|
||||
{
|
||||
for (int channelId = 0; channelId < NetworkServer.numChannels; channelId++)
|
||||
{
|
||||
netMsg.conn.SetChannelOption(channelId, ChannelOption.AllowFragmentation, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (networkSceneName != "" && networkSceneName != m_OfflineScene)
|
||||
{
|
||||
StringMessage msg = new StringMessage(networkSceneName);
|
||||
@ -849,8 +826,6 @@ internal void OnClientConnectInternal(NetworkMessage netMsg)
|
||||
{
|
||||
if (LogFilter.logDebug) { Debug.Log("NetworkManager:OnClientConnectInternal"); }
|
||||
|
||||
netMsg.conn.SetMaxDelay(m_MaxDelay);
|
||||
|
||||
string loadedSceneName = SceneManager.GetSceneAt(0).name;
|
||||
if (string.IsNullOrEmpty(m_OnlineScene) || (m_OnlineScene == m_OfflineScene) || (loadedSceneName == m_OnlineScene))
|
||||
{
|
||||
|
@ -18,8 +18,6 @@ public sealed class NetworkServer
|
||||
static NetworkScene s_NetworkScene = new NetworkScene();
|
||||
static HashSet<int> s_ExternalConnections = new HashSet<int>();
|
||||
|
||||
static float s_MaxDelay = 0.1f;
|
||||
|
||||
static NetworkMessageHandlers s_MessageHandlers = new NetworkMessageHandlers();
|
||||
static List<NetworkConnection> s_Connections = new List<NetworkConnection>();
|
||||
|
||||
@ -53,8 +51,6 @@ public sealed class NetworkServer
|
||||
public static bool active { get { return s_Active; } }
|
||||
public static bool localClientActive { get { return s_LocalClientActive; } }
|
||||
public static int numChannels { get { return s_HostTopology.DefaultConfig.ChannelCount; } }
|
||||
public static float maxDelay { get { return s_MaxDelay; } set { InternalSetMaxDelay(value); } }
|
||||
|
||||
|
||||
static Type s_NetworkConnectionClass = typeof(NetworkConnection);
|
||||
public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } }
|
||||
@ -148,7 +144,6 @@ static internal void RegisterMessageHandlers()
|
||||
s_MessageHandlers.RegisterHandlerSafe(MsgType.Animation, NetworkAnimator.OnAnimationServerMessage);
|
||||
s_MessageHandlers.RegisterHandlerSafe(MsgType.AnimationParameters, NetworkAnimator.OnAnimationParametersServerMessage);
|
||||
s_MessageHandlers.RegisterHandlerSafe(MsgType.AnimationTrigger, NetworkAnimator.OnAnimationTriggerServerMessage);
|
||||
s_MessageHandlers.RegisterHandlerSafe(MsgType.Fragment, NetworkConnection.OnFragment);
|
||||
|
||||
// also setup max packet size.
|
||||
maxPacketSize = hostTopology.DefaultConfig.PacketSize;
|
||||
@ -228,20 +223,6 @@ static internal bool InternalListen(string ipAddress, int serverPort)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void InternalSetMaxDelay(float seconds)
|
||||
{
|
||||
// set on existing connections
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
NetworkConnection conn = connections[i];
|
||||
if (conn != null)
|
||||
conn.SetMaxDelay(seconds);
|
||||
}
|
||||
|
||||
// save for future connections
|
||||
s_MaxDelay = seconds;
|
||||
}
|
||||
|
||||
public static bool SetConnectionAtIndex(NetworkConnection conn)
|
||||
{
|
||||
while (s_Connections.Count <= conn.connectionId)
|
||||
@ -540,17 +521,6 @@ static void UpdateServerObjects()
|
||||
}
|
||||
}
|
||||
|
||||
// this can be used independantly of Update() - such as when using external connections and not listening.
|
||||
public static void UpdateConnections()
|
||||
{
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
NetworkConnection conn = connections[i];
|
||||
if (conn != null)
|
||||
conn.FlushChannels();
|
||||
}
|
||||
}
|
||||
|
||||
static internal void InternalUpdate()
|
||||
{
|
||||
if (s_ServerHostId == -1)
|
||||
@ -617,12 +587,6 @@ static internal void InternalUpdate()
|
||||
}
|
||||
while (networkEvent != NetworkEventType.Nothing);
|
||||
|
||||
UpdateConnections();
|
||||
|
||||
if (s_DontListen)
|
||||
{
|
||||
UpdateConnections();
|
||||
}
|
||||
UpdateServerObjects();
|
||||
}
|
||||
|
||||
@ -647,7 +611,6 @@ static void HandleConnect(int connectionId, byte error)
|
||||
NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass);
|
||||
conn.SetHandlers(s_MessageHandlers);
|
||||
conn.Initialize(address, s_ServerHostId, connectionId, s_HostTopology);
|
||||
conn.SetMaxDelay(s_MaxDelay);
|
||||
conn.lastError = (NetworkError)error2;
|
||||
|
||||
// add connection at correct index
|
||||
@ -663,10 +626,6 @@ static void HandleConnect(int connectionId, byte error)
|
||||
static void OnConnected(NetworkConnection conn)
|
||||
{
|
||||
if (LogFilter.logDebug) { Debug.Log("Server accepted client:" + conn.connectionId); }
|
||||
|
||||
// add player info
|
||||
conn.SetMaxDelay(s_MaxDelay);
|
||||
|
||||
conn.InvokeHandlerNoData(MsgType.Connect);
|
||||
}
|
||||
|
||||
@ -807,53 +766,6 @@ static public void ClearSpawners()
|
||||
NetworkScene.ClearSpawners();
|
||||
}
|
||||
|
||||
static public void GetStatsOut(out int numMsgs, out int numBufferedMsgs, out int numBytes, out int lastBufferedPerSecond)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBufferedMsgs = 0;
|
||||
numBytes = 0;
|
||||
lastBufferedPerSecond = 0;
|
||||
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
var conn = connections[i];
|
||||
if (conn != null)
|
||||
{
|
||||
int snumMsgs;
|
||||
int snumBufferedMsgs;
|
||||
int snumBytes;
|
||||
int slastBufferedPerSecond;
|
||||
|
||||
conn.GetStatsOut(out snumMsgs, out snumBufferedMsgs, out snumBytes, out slastBufferedPerSecond);
|
||||
|
||||
numMsgs += snumMsgs;
|
||||
numBufferedMsgs += snumBufferedMsgs;
|
||||
numBytes += snumBytes;
|
||||
lastBufferedPerSecond += slastBufferedPerSecond;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public void GetStatsIn(out int numMsgs, out int numBytes)
|
||||
{
|
||||
numMsgs = 0;
|
||||
numBytes = 0;
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
var conn = connections[i];
|
||||
if (conn != null)
|
||||
{
|
||||
int cnumMsgs;
|
||||
int cnumBytes;
|
||||
|
||||
conn.GetStatsIn(out cnumMsgs, out cnumBytes);
|
||||
|
||||
numMsgs += cnumMsgs;
|
||||
numBytes += cnumBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// send this message to the player only
|
||||
static public void SendToClientOfPlayer(GameObject player, short msgType, MessageBase msg)
|
||||
{
|
||||
@ -1640,46 +1552,6 @@ static public GameObject FindLocalObject(NetworkInstanceId netId)
|
||||
return s_NetworkScene.FindLocalObject(netId);
|
||||
}
|
||||
|
||||
static public Dictionary<short, NetworkConnection.PacketStat> GetConnectionStats()
|
||||
{
|
||||
Dictionary<short, NetworkConnection.PacketStat> stats = new Dictionary<short, NetworkConnection.PacketStat>();
|
||||
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
var conn = connections[i];
|
||||
if (conn != null)
|
||||
{
|
||||
foreach (short k in conn.packetStats.Keys)
|
||||
{
|
||||
if (stats.ContainsKey(k))
|
||||
{
|
||||
NetworkConnection.PacketStat s = stats[k];
|
||||
s.count += conn.packetStats[k].count;
|
||||
s.bytes += conn.packetStats[k].bytes;
|
||||
stats[k] = s;
|
||||
}
|
||||
else
|
||||
{
|
||||
stats[k] = new NetworkConnection.PacketStat(conn.packetStats[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return stats;
|
||||
}
|
||||
|
||||
static public void ResetConnectionStats()
|
||||
{
|
||||
for (int i = 0; i < connections.Count; i++)
|
||||
{
|
||||
var conn = connections[i];
|
||||
if (conn != null)
|
||||
{
|
||||
conn.ResetStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public bool AddExternalConnection(NetworkConnection conn)
|
||||
{
|
||||
return AddExternalConnectionInternal(conn);
|
||||
|
@ -190,14 +190,6 @@ public static bool IsUnreliableQoS(QosType qos)
|
||||
return (qos == QosType.Unreliable || qos == QosType.UnreliableFragmented || qos == QosType.UnreliableSequenced || qos == QosType.StateUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ChannelOption
|
||||
{
|
||||
MaxPendingBuffers = 1,
|
||||
AllowFragmentation = 2,
|
||||
MaxPacketSize = 3
|
||||
// maybe add an InitialCapacity for Pending Buffers list if needed in the future
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,8 +39,6 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChannelBuffer.cs" />
|
||||
<Compile Include="ChannelPacket.cs" />
|
||||
<Compile Include="ClientScene.cs" />
|
||||
<Compile Include="ConnectionArray.cs" />
|
||||
<Compile Include="CustomAttributes.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user