Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Update to work with Mirror 7.2.x #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Mirror.LiteNetLib4Mirror
{
public static class LiteNetLib4MirrorCore
{
public const string TransportVersion = "1.2.8";
public const string TransportVersion = "1.2.9";
public static SocketError LastError { get; internal set; }
public static SocketError LastDisconnectError { get; internal set; }
public static DisconnectReason LastDisconnectReason { get; internal set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public void StartHost(string serverIPv4BindAddress, string serverIPv6BindAddress
/// <param name="maxPlayers">Connection limit</param>
#endif
#if DISABLE_IPV6
public bool StartServer(string serverIPv4BindAddress, ushort port, ushort maxPlayers)
public void StartServer(string serverIPv4BindAddress, ushort port, ushort maxPlayers)
#else
public bool StartServer(string serverIPv4BindAddress, string serverIPv6BindAddress, ushort port, ushort maxPlayers)
public void StartServer(string serverIPv4BindAddress, string serverIPv6BindAddress, ushort port, ushort maxPlayers)
#endif
{
networkAddress = serverIPv4BindAddress;
Expand All @@ -99,7 +99,7 @@ public bool StartServer(string serverIPv4BindAddress, string serverIPv6BindAddre
#endif
LiteNetLib4MirrorTransport.Singleton.port = port;
LiteNetLib4MirrorTransport.Singleton.maxConnections = maxPlayers;
return StartServer();
StartServer();
}

/// <summary>
Expand All @@ -126,7 +126,7 @@ public void StartHost(ushort port, ushort maxPlayers)
/// </summary>
/// <param name="port">Port</param>
/// <param name="maxPlayers">Connection limit</param>
public bool StartServer(ushort port, ushort maxPlayers)
public void StartServer(ushort port, ushort maxPlayers)
{
networkAddress = "127.0.0.1";
maxConnections = maxPlayers;
Expand All @@ -136,7 +136,7 @@ public bool StartServer(ushort port, ushort maxPlayers)
#endif
LiteNetLib4MirrorTransport.Singleton.port = port;
LiteNetLib4MirrorTransport.Singleton.maxConnections = maxPlayers;
return StartServer();
StartServer();
}

public void DisconnectConnection(NetworkConnection conn, string message = null)
Expand Down
6 changes: 3 additions & 3 deletions LiteNetLib4Mirror/Assets/MirrorLib/Mirror/Authenticators.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using System.Collections;

namespace Mirror.Authenticators
Expand Down Expand Up @@ -68,10 +68,10 @@ public void OnAuthRequestMessage(NetworkConnection conn, AuthRequestMessage msg)
message = "Success"
};

NetworkServer.SendToClient(conn.connectionId, authResponseMessage);
conn.Send(authResponseMessage);

// Invoke the event to complete a successful authentication
base.OnServerAuthenticated.Invoke(conn);
OnServerAuthenticated.Invoke(conn);
}
else
{
Expand All @@ -82,24 +82,30 @@ public void OnAuthRequestMessage(NetworkConnection conn, AuthRequestMessage msg)
message = "Invalid Credentials"
};

NetworkServer.SendToClient(conn.connectionId, authResponseMessage);
conn.Send(authResponseMessage);

// must set NetworkConnection isAuthenticated = false
conn.isAuthenticated = false;

// disconnect the client after 1 second so that response message gets delivered
Invoke(nameof(conn.Disconnect), 1);
StartCoroutine(DelayedDisconnect(conn, 1));
}
}

public IEnumerator DelayedDisconnect(NetworkConnection conn, float waitTime)
{
yield return new WaitForSeconds(waitTime);
conn.Disconnect();
}

public void OnAuthResponseMessage(NetworkConnection conn, AuthResponseMessage msg)
{
if (msg.code == 100)
{
Debug.LogFormat("Authentication Response: {0}", msg.message);

// Invoke the event to complete a successful authentication
base.OnClientAuthenticated.Invoke(conn);
OnClientAuthenticated.Invoke(conn);
}
else
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections;
using UnityEngine;

namespace Mirror.Authenticators
{
/// <summary>
/// An authenticator that disconnects connections if they don't
/// authenticate within a specified time limit.
/// </summary>
[AddComponentMenu("Network/Authenticators/TimeoutAuthenticator")]
public class TimeoutAuthenticator : NetworkAuthenticator
{
public NetworkAuthenticator authenticator;

[Range(0, 600), Tooltip("Timeout to auto-disconnect in seconds. Set to 0 for no timeout.")]
public float timeout = 60;

public void Awake()
{
authenticator.OnClientAuthenticated.AddListener(connection => OnClientAuthenticated.Invoke(connection));
authenticator.OnServerAuthenticated.AddListener(connection => OnServerAuthenticated.Invoke(connection));
}

public override void OnClientAuthenticate(NetworkConnection conn)
{
authenticator.OnClientAuthenticate(conn);
if (timeout > 0)
StartCoroutine(BeginAuthentication(conn));
}

public override void OnServerAuthenticate(NetworkConnection conn)
{
authenticator.OnServerAuthenticate(conn);
if (timeout > 0)
StartCoroutine(BeginAuthentication(conn));
}

IEnumerator BeginAuthentication(NetworkConnection conn)
{
if (LogFilter.Debug) Debug.Log($"Authentication countdown started {conn} {timeout}");

yield return new WaitForSecondsRealtime(timeout);

if (!conn.isAuthenticated)
{
if (LogFilter.Debug) Debug.Log($"Authentication Timeout {conn}");

conn.Disconnect();
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{
"name": "Mirror.Tests",
"references": [
"Mirror",
"Mirror.Weaver"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"name": "Mirror.CompilerSymbols",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [
"Editor"
],
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using UnityEditor;

namespace Mirror
{
static class PreprocessorDefine
{
/// <summary>
/// Add define symbols as soon as Unity gets done compiling.
/// </summary>
[InitializeOnLoadMethod]
public static void AddDefineSymbols()
{
HashSet<string> defines = new HashSet<string>(PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup).Split(';'))
{
"MIRROR",
"MIRROR_1726_OR_NEWER",
"MIRROR_3_0_OR_NEWER",
"MIRROR_3_12_OR_NEWER",
"MIRROR_4_0_OR_NEWER"
};
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, string.Join(";", defines));
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions LiteNetLib4Mirror/Assets/MirrorLib/Mirror/Components.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading