Revert "feat: Add Timeout to NetworkAuthenticator (#1091)"

This reverts commit e8cc9ba27b.
This commit is contained in:
vis2k 2019-10-20 20:12:14 +02:00
parent e8fac8aba5
commit 12c5a8fdc3
4 changed files with 1 additions and 55 deletions

2
.gitignore vendored
View File

@ -60,4 +60,4 @@ docs/.sass-cache
.Trashes
ehthumbs.db
Thumbs.db
*.txt
/VisRepo.txt

View File

@ -1,5 +1,4 @@
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
@ -16,11 +15,6 @@ namespace Mirror
[HelpURL("https://mirror-networking.com/docs/Guides/Authentication.html")]
public abstract class NetworkAuthenticator : MonoBehaviour
{
[Header("Configuration")]
[Range(0, 255), Tooltip("Timeout to auto-disconnect in seconds. Set to 0 for no timeout.")]
public byte timeout;
[Header("Event Listeners (optional)")]
/// <summary>
@ -46,9 +40,6 @@ public virtual void OnStartServer() {}
// This will get more code in the near future
internal void OnServerAuthenticateInternal(NetworkConnection conn)
{
// Start the countdown for Authentication
if (timeout > 0) StartCoroutine(AuthenticationTimer(conn, true));
OnServerAuthenticate(conn);
}
@ -58,16 +49,6 @@ internal void OnServerAuthenticateInternal(NetworkConnection conn)
/// <param name="conn">Connection to client.</param>
public abstract void OnServerAuthenticate(NetworkConnection conn);
/// <summary>
/// Called on server when the timeout expires without being authenticated
/// </summary>
/// <param name="conn">Connection to client.</param>
public virtual void OnServerAuthenticationTimeout(NetworkConnection conn)
{
Debug.LogErrorFormat("OnServerAuthenticationTimeout: {0}", conn);
conn.Disconnect();
}
#endregion
#region client
@ -81,9 +62,6 @@ public virtual void OnStartClient() {}
// This will get more code in the near future
internal void OnClientAuthenticateInternal(NetworkConnection conn)
{
// Start the countdown for Authentication
if (timeout > 0) StartCoroutine(AuthenticationTimer(conn, false));
OnClientAuthenticate(conn);
}
@ -93,39 +71,8 @@ internal void OnClientAuthenticateInternal(NetworkConnection conn)
/// <param name="conn">Connection of the client.</param>
public abstract void OnClientAuthenticate(NetworkConnection conn);
/// <summary>
/// Called on client when the timeout expires without being authenticated
/// </summary>
/// <param name="conn">Connection of the client.</param>
public virtual void OnClientAuthenticationTimeout(NetworkConnection conn)
{
Debug.LogErrorFormat("OnClientAuthenticationTimeout: {0}", conn);
conn.Disconnect();
}
#endregion
/// <summary>
/// This is called on both client and server if timeout > 0
/// </summary>
/// <param name="conn">Connection of the client.</param>
public IEnumerator AuthenticationTimer(NetworkConnection conn, bool isServer)
{
if (LogFilter.Debug) Debug.LogFormat("Authentication countdown started {0} {1}", conn.connectionId, timeout);
yield return new WaitForSecondsRealtime(timeout);
if (conn != null && !conn.isAuthenticated)
{
if (LogFilter.Debug) Debug.LogFormat("Authentication Timeout {0}", conn.connectionId);
if (isServer)
OnServerAuthenticationTimeout(conn);
else
OnClientAuthenticationTimeout(conn);
}
}
void OnValidate()
{
#if UNITY_EDITOR

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 57 KiB

View File

@ -49,7 +49,6 @@ To make your own custom Authenticator, you can just create a new script in your
Here are some tips for custom Authenticators:
- `OnStartServer` and `OnStartClient` are the appropriate methods to register server and client messages and their handlers. They're called from StartServer/StartHost, and StartClient, respectively.
- The base Authenticator includes a timeout feature so you can prevent rogue clients from locking up your connections.
- Send a message to the client if authentication fails, especially if there's some issue they can resolve.
- Call the `Disconnect()` method of the `NetworkConnection` on the server and client when authentication fails. If you want to give the user a few tries to get their credentials right, you certainly can, but Mirror will not do the disconnect for you.
- Remember to put a small delay on the Disconnect call on the server if you send a failure message so that it has a chance to be delivered before the connection is dropped.