From ef7f35e0fec988c5eb7e5c37404d665019276994 Mon Sep 17 00:00:00 2001 From: Matthew Collier <51029884+Squaresweets@users.noreply.github.com> Date: Wed, 14 Jul 2021 21:47:03 +0100 Subject: [PATCH] Fixed previous commit --- BubbleTransport/BubbleTransport.cs | 32 ++++++++++++++++++-------- BubbleTransport/Plugins/GCController.m | 8 +++---- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/BubbleTransport/BubbleTransport.cs b/BubbleTransport/BubbleTransport.cs index e96b1f0..08962de 100644 --- a/BubbleTransport/BubbleTransport.cs +++ b/BubbleTransport/BubbleTransport.cs @@ -97,6 +97,8 @@ public MessageBuffer(ArraySegment data, int channelId, int connId) bool connected = false; bool needToDisconnectFlag = false; + //Check if it was the transport that started the game + static bool startFlag = false; /* Structure of the transport @@ -159,8 +161,20 @@ public override bool Available() //~~~~~~~~~~ These two functions are all sorted out by game center, and these should not be called by anything other than the transport, if you want to start a game use FindMatch(); ~~~~~~~~~~ - public override void ServerStart() { } - public override void ClientConnect(string address) { } + public override void ServerStart() + { + if (startFlag) + startFlag = false; + else + Debug.LogError("BubbleTransport | Don't call ServerStart() as matchmaking is random, call FindMatch() instead :D"); + } + public override void ClientConnect(string address) + { + if (startFlag) + startFlag = false; + else + Debug.LogError("BubbleTransport | Don't call ClientConnect() as matchmaking is random, call FindMatch() instead :D"); + } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -256,8 +270,8 @@ We get a pointer back from the plugin containing the location of the array of by | 1 Byte | 1 Byte | Rest of the array | | | | | --------------------------------------------------------------- - - Objective C code splits this up into offset and count and sends it here + + Objective C code splits this up into offset and channel and sends it here */ byte[] _data = new byte[count]; Marshal.Copy(data, _data, 0, count); @@ -272,6 +286,7 @@ static void OnClientStartCallback() instance.connected = true; activeTransport = instance; instance.matchFound.Invoke(); + startFlag = true; NetworkManager.singleton.StartClient(); instance.OnClientConnected?.Invoke(); } @@ -327,12 +342,12 @@ We get a pointer back from the plugin containing the location of the array of by | | | | --------------------------------------------------------------- - Objective C code splits this up into offset and count and sends it here + Objective C code splits this up into offset and channel and sends it here */ byte[] _data = new byte[count]; Marshal.Copy(data, _data, 0, count); - clientMessageBuffer.Add(new MessageBuffer(new ArraySegment(_data, offset, count), channelId, connId)); + serverMessageBuffer.Add(new MessageBuffer(new ArraySegment(_data, offset, count), channelId, connId)); } /// @@ -352,6 +367,7 @@ static void OnServerStartCallback() instance.connected = true; activeTransport = instance; instance.matchFound?.Invoke(); + startFlag = true; Mirror.NetworkManager.singleton.StartHost(); } @@ -382,8 +398,6 @@ public override void ClientLateUpdate() //This executes any messages that were recieved in the last frame for (int i = 0; i < clientMessageBuffer.Count && i < MaxReceivesPerTick; i++) { - //Channel set as 0 because I can't work out the channel from the message - //I may want to add something that sends the channel as well later OnClientDataReceived?.Invoke(clientMessageBuffer[0].data, clientMessageBuffer[0].channelId); clientMessageBuffer.RemoveAt(0); } @@ -395,8 +409,6 @@ public override void ServerLateUpdate() //This executes any messages that were recieved in the last frame for (int i = 0; i < serverMessageBuffer.Count && i < MaxReceivesPerTick; i++) { - //Channel set as 0 because I can't work out the channel from the message - //I may want to add something that sends the channel as well later OnServerDataReceived?.Invoke(serverMessageBuffer[0].connId, serverMessageBuffer[0].data, serverMessageBuffer[0].channelId); serverMessageBuffer.RemoveAt(0); } diff --git a/BubbleTransport/Plugins/GCController.m b/BubbleTransport/Plugins/GCController.m index 10fa0a5..b4531f5 100644 --- a/BubbleTransport/Plugins/GCController.m +++ b/BubbleTransport/Plugins/GCController.m @@ -6,9 +6,9 @@ extern UIViewController *UnityGetGLViewController(); -typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId); +typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId); OnClientDidDataRecievedDelegate ClientRecievedData = NULL; -typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId); +typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId); OnServerDidDataRecievedDelegate ServerRecievedData = NULL; typedef void (*OnServerConnectedDelegate)(int connId); OnServerConnectedDelegate ServerConnected = NULL; @@ -178,7 +178,7 @@ void SendMessageToClient(int clientId, Byte data[], int offset, int count, int c [GCController sendDataToPlayer:dataToSend toPlayer:clientId datamode:channel]; } - typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId); + typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId); void RegisterClientDataRecieveCallback(OnClientDidDataRecievedDelegate callback) { if(ClientRecievedData == NULL) @@ -234,7 +234,7 @@ void RegisterOnClientDisconnectedCallback(OnClientDisconnectedDelegate callback) ClientDisconnected = callback; } } - typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId); + typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId); void RegisterServerDataRecieveCallback(OnServerDidDataRecievedDelegate callback) { if(ServerRecievedData == NULL)