1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using UnityEngine;
- using UnityEngine.Events;
- namespace Mirror
- {
- [Serializable] public class UnityEventNetworkConnection : UnityEvent<NetworkConnection> {}
-
- [HelpURL("https://mirror-networking.gitbook.io/docs/components/network-authenticators")]
- public abstract class NetworkAuthenticator : MonoBehaviour
- {
-
- [Header("Event Listeners (optional)")]
- [Tooltip("Mirror has an internal subscriber to this event. You can add your own here.")]
- public UnityEventNetworkConnection OnServerAuthenticated = new UnityEventNetworkConnection();
-
- [Tooltip("Mirror has an internal subscriber to this event. You can add your own here.")]
- public UnityEventNetworkConnection OnClientAuthenticated = new UnityEventNetworkConnection();
-
- public virtual void OnStartServer() {}
-
- public virtual void OnStopServer() {}
-
- public abstract void OnServerAuthenticate(NetworkConnection conn);
- protected void ServerAccept(NetworkConnection conn)
- {
- OnServerAuthenticated.Invoke(conn);
- }
- protected void ServerReject(NetworkConnection conn)
- {
- conn.Disconnect();
- }
-
- public virtual void OnStartClient() {}
-
- public virtual void OnStopClient() {}
-
- [Obsolete("Remove the NetworkConnection parameter from your override and use NetworkClient.connection instead")]
- public virtual void OnClientAuthenticate(NetworkConnection conn) => OnClientAuthenticate();
-
- public abstract void OnClientAuthenticate();
-
- [Obsolete("Remove the NetworkConnection parameter from your override and use NetworkClient.connection instead")]
- protected void ClientAccept(NetworkConnection conn) => ClientAccept();
- protected void ClientAccept()
- {
- OnClientAuthenticated.Invoke(NetworkClient.connection);
- }
-
- [Obsolete("Remove the NetworkConnection parameter from your override and use NetworkClient.connection instead")]
- protected void ClientReject(NetworkConnection conn) => ClientReject();
- protected void ClientReject()
- {
-
- NetworkClient.connection.isAuthenticated = false;
-
- NetworkClient.connection.Disconnect();
- }
- void OnValidate()
- {
- #if UNITY_EDITOR
-
- NetworkManager manager = GetComponent<NetworkManager>();
- if (manager != null && manager.authenticator == null)
- {
- manager.authenticator = this;
- UnityEditor.Undo.RecordObject(gameObject, "Assigned NetworkManager authenticator");
- }
- #endif
- }
- }
- }
|