You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Plugins/ConsolePro/Remote/LiteNetLib/NetPeerCollection.cs

82 lines
2.0 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

#if DEBUG && !UNITY_WP_8_1 && !UNITY_WSA
using System;
using System.Collections.Generic;
namespace FlyingWormConsole3.LiteNetLib
{
internal sealed class NetPeerCollection
{
private readonly Dictionary<NetEndPoint, NetPeer> _peersDict;
private readonly NetPeer[] _peersArray;
private int _count;
public int Count
{
get { return _count; }
}
public NetPeer this[int index]
{
get { return _peersArray[index]; }
}
public NetPeerCollection(int maxPeers)
{
_peersArray = new NetPeer[maxPeers];
_peersDict = new Dictionary<NetEndPoint, NetPeer>();
}
public bool TryGetValue(NetEndPoint endPoint, out NetPeer peer)
{
return _peersDict.TryGetValue(endPoint, out peer);
}
public void Clear()
{
Array.Clear(_peersArray, 0, _count);
_peersDict.Clear();
_count = 0;
}
public void Add(NetEndPoint endPoint, NetPeer peer)
{
_peersArray[_count] = peer;
_peersDict.Add(endPoint, peer);
_count++;
}
public bool ContainsAddress(NetEndPoint endPoint)
{
return _peersDict.ContainsKey(endPoint);
}
public NetPeer[] ToArray()
{
NetPeer[] result = new NetPeer[_count];
Array.Copy(_peersArray, 0, result, 0, _count);
return result;
}
public void RemoveAt(int idx)
{
_peersDict.Remove(_peersArray[idx].EndPoint);
_peersArray[idx] = _peersArray[_count - 1];
_peersArray[_count - 1] = null;
_count--;
}
public void Remove(NetEndPoint endPoint)
{
for (int i = 0; i < _count; i++)
{
if (_peersArray[i].EndPoint.Equals(endPoint))
{
RemoveAt(i);
break;
}
}
}
}
}
#endif