using FishNet.Object;
using FishNet.Transporting;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace FishNet.Managing.Server
{
public sealed partial class ServerManager : MonoBehaviour
{
#region Internal
///
/// Current RPCLinks.
///
internal Dictionary RpcLinks = new Dictionary();
///
/// RPCLink indexes which can be used.
///
private Queue _availableRpcLinkIndexes = new Queue();
#endregion
///
/// Initializes RPC Links for NetworkBehaviours.
///
private void InitializeRpcLinks()
{
/* Brute force enum values.
* Linq Last/Max lookup throws for IL2CPP. */
ushort highestValue = 0;
Array pidValues = Enum.GetValues(typeof(PacketId));
foreach (PacketId pid in pidValues)
highestValue = Math.Max(highestValue, (ushort)pid);
highestValue += 1;
for (ushort i = highestValue; i < ushort.MaxValue; i++)
_availableRpcLinkIndexes.Enqueue(i);
}
///
/// Sets the next RPC Link to use.
///
/// True if a link was available and set.
internal bool GetRpcLink(out ushort value)
{
if (_availableRpcLinkIndexes.Count > 0)
{
value = _availableRpcLinkIndexes.Dequeue();
return true;
}
else
{
value = 0;
return false;
}
}
///
/// Sets data to RpcLinks for linkIndex.
///
internal void SetRpcLink(ushort linkIndex, RpcLink data)
{
RpcLinks[linkIndex] = data;
}
///
/// Returns RPCLinks to availableRpcLinkIndexes.
///
internal void StoreRpcLinks(Dictionary links)
{
foreach (RpcLinkType rlt in links.Values)
_availableRpcLinkIndexes.Enqueue(rlt.LinkIndex);
}
}
}