From a57b48105bd2877f5532eb7d5147feba66ac8bf6 Mon Sep 17 00:00:00 2001 From: Derek Date: Tue, 16 Feb 2021 18:26:16 -0600 Subject: [PATCH] Update v6 --- README.md | 3 --- UnityTransport/LightReflectiveMirrorTransport.cs | 9 ++++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f1883e9..39326f5 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,6 @@ Light Reflective Mirror has a built in room/server list if you would like to use To request the server list you need a reference to the LightReflectiveMirrorTransport from your script and call 'RequestServerList()'. This will invoke a request to the server to update our server list. Once the response is recieved the field 'relayServerList' will be populated and you can get all the servers from there. -#### Free Relay -Note: If you would like to test without creating a server, feel free to use my test server with IP: 34.67.125.123. Which is in there by default :) - #### Server Setup Download the latest Server release from: [Releases](https://github.com/Derek-R-S/Light-Reflective-Mirror/releases) Make sure you have .NET Core 3.1 diff --git a/UnityTransport/LightReflectiveMirrorTransport.cs b/UnityTransport/LightReflectiveMirrorTransport.cs index ea33aed..21e2c20 100644 --- a/UnityTransport/LightReflectiveMirrorTransport.cs +++ b/UnityTransport/LightReflectiveMirrorTransport.cs @@ -34,6 +34,7 @@ namespace LightReflectiveMirror private bool _isServer = false; private bool _isAuthenticated = false; private int _currentMemberId; + private bool _callbacksInitialized = false; private BiDictionary _connectedRelayClients = new BiDictionary(); public bool IsAuthenticated() => _isAuthenticated; @@ -44,14 +45,20 @@ namespace LightReflectiveMirror throw new Exception("Haha real funny... Use a different transport."); } + SetupCallbacks(); + if (connectOnAwake) ConnectToRelay(); InvokeRepeating(nameof(SendHeartbeat), heartBeatInterval, heartBeatInterval); } - private void OnEnable() + private void SetupCallbacks() { + if (_callbacksInitialized) + return; + + _callbacksInitialized = true; clientToServerTransport.OnClientConnected = ConnectedToRelay; clientToServerTransport.OnClientDataReceived = DataReceived; clientToServerTransport.OnClientDisconnected = Disconnected;