using FishNet.Connection;
using FishNet.Managing;
using System;
using UnityEngine;
namespace FishNet.Authenticating
{
    /// 
    /// When inherited from this can be used to create a custom authentication process before clients may communicate with the server.
    /// 
    public abstract class Authenticator : MonoBehaviour
    {
        #region Public.
        /// 
        /// True if this authenticator has been intiialzied.
        /// 
        public bool Initialized { get; private set; }
        #endregion
        #region Protected.
        /// 
        /// NetworkManager for this Authenticator.
        /// 
        protected NetworkManager NetworkManager { get; private set; }
        #endregion
         
        /// 
        /// Called when authenticator has concluded a result for a connection. Boolean is true if authentication passed, false if failed.
        /// Server listens for this event automatically.
        /// 
        public abstract event Action OnAuthenticationResult;
        /// 
        /// Initializes this script for use.
        /// 
        /// 
        public virtual void InitializeOnce(NetworkManager networkManager)
        {
            NetworkManager = networkManager;
            Initialized = true;
        }
        /// 
        /// Called on the server immediately after a client connects. Can be used to send data to the client for authentication.
        /// 
        /// Connection which is not yet authenticated.
        public virtual void OnRemoteConnection(NetworkConnection connection) { }
    }
}