//using FishNet.Connection; //remove on v5
//using FishNet.Serializing;
//using FishNet.Transporting;
//using GameKit.Dependencies.Utilities;
//using System;
//using System.Collections.Generic;
//using System.Diagnostics;
//namespace FishNet.Broadcast.Helping
//{
// internal static class BroadcastHelper
// {
// ///
// /// Gets the key for a broadcast type.
// ///
// ///
// ///
// ///
// internal static ushort GetKey()
// {
// return typeof(T).FullName.GetStableHashU16();
// }
// }
// ///
// /// Implemented by server and client broadcast handlers.
// ///
// public abstract class BroadcastHandlerBase
// {
// ///
// /// Current index when iterating invokes.
// /// This value will be -1 when not iterating.
// ///
// protected int IteratingIndex;
// public abstract void RegisterHandler(object obj);
// public abstract void UnregisterHandler(object obj);
// public virtual void InvokeHandlers(PooledReader reader, Channel channel) { }
// public virtual void InvokeHandlers(NetworkConnection conn, PooledReader reader, Channel channel) { }
// public virtual bool RequireAuthentication => false;
// }
// ///
// /// Handles broadcasts received on server, from clients.
// ///
// internal class ClientBroadcastHandler : BroadcastHandlerBase
// {
// ///
// /// Action handlers for the broadcast.
// ///
// private List> _handlers = new List>();
// ///
// /// True to require authentication for the broadcast type.
// ///
// private bool _requireAuthentication;
// public ClientBroadcastHandler(bool requireAuthentication)
// {
// _requireAuthentication = requireAuthentication;
// }
// ///
// /// Invokes handlers after reading broadcast.
// ///
// /// True if a rebuild was required.
// public override void InvokeHandlers(NetworkConnection conn, PooledReader reader, Channel channel)
// {
// T result = reader.Read();
// for (base.IteratingIndex = 0; base.IteratingIndex < _handlers.Count; base.IteratingIndex++)
// {
// Action item = _handlers[base.IteratingIndex];
// if (item != null)
// {
// item.Invoke(conn, result, channel);
// }
// else
// {
// _handlers.RemoveAt(base.IteratingIndex);
// base.IteratingIndex--;
// }
// }
// base.IteratingIndex = -1;
// }
// ///
// /// Adds a handler for this type.
// ///
// public override void RegisterHandler(object obj)
// {
// Action handler = (Action)obj;
// _handlers.AddUnique(handler);
// }
// ///
// /// Removes a handler from this type.
// ///
// ///
// public override void UnregisterHandler(object obj)
// {
// Action handler = (Action)obj;
// int indexOf = _handlers.IndexOf(handler);
// //Not registered.
// if (indexOf == -1)
// return;
// /* Has already been iterated over, need to subtract
// * 1 from iteratingIndex to accomodate
// * for the entry about to be removed. */
// if (base.IteratingIndex >= 0 && (indexOf <= base.IteratingIndex))
// base.IteratingIndex--;
// //Remove entry.
// _handlers.RemoveAt(indexOf);
// }
// ///
// /// True to require authentication for the broadcast type.
// ///
// public override bool RequireAuthentication => _requireAuthentication;
// }
// ///
// /// Handles broadcasts received on client, from server.
// ///
// internal class ServerBroadcastHandler : BroadcastHandlerBase
// {
// ///
// /// Action handlers for the broadcast.
// /// Even though List lookups are slower this allows easy adding and removing of entries during iteration.
// ///
// private List> _handlers = new List>();
// ///
// /// Invokes handlers after reading broadcast.
// ///
// /// True if a rebuild was required.
// public override void InvokeHandlers(PooledReader reader, Channel channel)
// {
// T result = reader.Read();
// for (base.IteratingIndex = 0; base.IteratingIndex < _handlers.Count; base.IteratingIndex++)
// {
// Action item = _handlers[base.IteratingIndex];
// if (item != null)
// {
// item.Invoke(result, channel);
// }
// else
// {
// _handlers.RemoveAt(base.IteratingIndex);
// base.IteratingIndex--;
// }
// }
// base.IteratingIndex = -1;
// }
// ///
// /// Adds a handler for this type.
// ///
// public override void RegisterHandler(object obj)
// {
// Action handler = (Action)obj;
// _handlers.AddUnique(handler);
// }
// ///
// /// Removes a handler from this type.
// ///
// ///
// public override void UnregisterHandler(object obj)
// {
// Action handler = (Action)obj;
// int indexOf = _handlers.IndexOf(handler);
// //Not registered.
// if (indexOf == -1)
// return;
// /* Has already been iterated over, need to subtract
// * 1 from iteratingIndex to accomodate
// * for the entry about to be removed. */
// if (base.IteratingIndex >= 0 && (indexOf <= base.IteratingIndex))
// base.IteratingIndex--;
// //Remove entry.
// _handlers.RemoveAt(indexOf);
// }
// ///
// /// True to require authentication for the broadcast type.
// ///
// public override bool RequireAuthentication => false;
// }
//}