using FishNet.Managing; using FishNet.Managing.Logging; using FishNet.Managing.Server; using FishNet.Serializing; using System; using UnityEngine; namespace FishNet.Connection { /// /// A container for a connected client used to perform actions on and gather information for the declared client. /// public partial class NetworkConnection { #region Public. /// /// Returns true if this connection is a clientHost. /// public bool IsHost => (NetworkManager == null) ? false : (NetworkManager.IsServerStarted && (this == NetworkManager.ClientManager.Connection)); /// /// Returns if this connection is for the local client. /// public bool IsLocalClient => (NetworkManager == null) ? false : (NetworkManager.ClientManager.Connection == this); #endregion /// /// Returns the address of this connection. /// /// public string GetAddress() { if (!IsValid) return string.Empty; if (NetworkManager == null) return string.Empty; return NetworkManager.TransportManager.Transport.GetConnectionAddress(ClientId); } /// /// Kicks a connection immediately while invoking OnClientKick. /// /// Reason client is being kicked. /// How to print logging as. /// Optional message to be debug logged. public void Kick(KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "") { if (CanKick()) NetworkManager.ServerManager.Kick(this, kickReason, loggingType, log); } /// /// Kicks a connection immediately while invoking OnClientKick. /// /// Reader to clear before kicking. /// Reason client is being kicked. /// How to print logging as. /// Optional message to be debug logged. public void Kick(Reader reader, KickReason kickReason, LoggingType loggingType = LoggingType.Common, string log = "") { if (CanKick()) NetworkManager.ServerManager.Kick(this, reader, kickReason, loggingType, log); } private bool CanKick() { //Connection isn't valid, calling kick on an empty connection. if (!IsValid) return false; //Should never happen. if (NetworkManager == null) { NetworkManager = InstanceFinder.NetworkManager; NetworkManager.LogError($"NetworkManager was not set for connection {this.ToString()}. InstanceFinder has been used."); } return true; } } }