Skip to content

Commit ef7f35e

Browse files
authored
Fixed previous commit
1 parent 27ed35f commit ef7f35e

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

BubbleTransport/BubbleTransport.cs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ public MessageBuffer(ArraySegment<byte> data, int channelId, int connId)
9797
bool connected = false;
9898

9999
bool needToDisconnectFlag = false;
100+
//Check if it was the transport that started the game
101+
static bool startFlag = false;
100102

101103
/* Structure of the transport
102104
@@ -159,8 +161,20 @@ public override bool Available()
159161

160162
//~~~~~~~~~~ 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(); ~~~~~~~~~~
161163

162-
public override void ServerStart() { }
163-
public override void ClientConnect(string address) { }
164+
public override void ServerStart()
165+
{
166+
if (startFlag)
167+
startFlag = false;
168+
else
169+
Debug.LogError("BubbleTransport | Don't call ServerStart() as matchmaking is random, call FindMatch() instead :D");
170+
}
171+
public override void ClientConnect(string address)
172+
{
173+
if (startFlag)
174+
startFlag = false;
175+
else
176+
Debug.LogError("BubbleTransport | Don't call ClientConnect() as matchmaking is random, call FindMatch() instead :D");
177+
}
164178

165179
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166180

@@ -256,8 +270,8 @@ We get a pointer back from the plugin containing the location of the array of by
256270
| 1 Byte | 1 Byte | Rest of the array |
257271
| | | |
258272
---------------------------------------------------------------
259-
260-
Objective C code splits this up into offset and count and sends it here
273+
274+
Objective C code splits this up into offset and channel and sends it here
261275
*/
262276
byte[] _data = new byte[count];
263277
Marshal.Copy(data, _data, 0, count);
@@ -272,6 +286,7 @@ static void OnClientStartCallback()
272286
instance.connected = true;
273287
activeTransport = instance;
274288
instance.matchFound.Invoke();
289+
startFlag = true;
275290
NetworkManager.singleton.StartClient();
276291
instance.OnClientConnected?.Invoke();
277292
}
@@ -327,12 +342,12 @@ We get a pointer back from the plugin containing the location of the array of by
327342
| | | |
328343
---------------------------------------------------------------
329344
330-
Objective C code splits this up into offset and count and sends it here
345+
Objective C code splits this up into offset and channel and sends it here
331346
*/
332347
byte[] _data = new byte[count];
333348
Marshal.Copy(data, _data, 0, count);
334349

335-
clientMessageBuffer.Add(new MessageBuffer(new ArraySegment<byte>(_data, offset, count), channelId, connId));
350+
serverMessageBuffer.Add(new MessageBuffer(new ArraySegment<byte>(_data, offset, count), channelId, connId));
336351
}
337352

338353
/// <summary>
@@ -352,6 +367,7 @@ static void OnServerStartCallback()
352367
instance.connected = true;
353368
activeTransport = instance;
354369
instance.matchFound?.Invoke();
370+
startFlag = true;
355371
Mirror.NetworkManager.singleton.StartHost();
356372
}
357373

@@ -382,8 +398,6 @@ public override void ClientLateUpdate()
382398
//This executes any messages that were recieved in the last frame
383399
for (int i = 0; i < clientMessageBuffer.Count && i < MaxReceivesPerTick; i++)
384400
{
385-
//Channel set as 0 because I can't work out the channel from the message
386-
//I may want to add something that sends the channel as well later
387401
OnClientDataReceived?.Invoke(clientMessageBuffer[0].data, clientMessageBuffer[0].channelId);
388402
clientMessageBuffer.RemoveAt(0);
389403
}
@@ -395,8 +409,6 @@ public override void ServerLateUpdate()
395409
//This executes any messages that were recieved in the last frame
396410
for (int i = 0; i < serverMessageBuffer.Count && i < MaxReceivesPerTick; i++)
397411
{
398-
//Channel set as 0 because I can't work out the channel from the message
399-
//I may want to add something that sends the channel as well later
400412
OnServerDataReceived?.Invoke(serverMessageBuffer[0].connId, serverMessageBuffer[0].data, serverMessageBuffer[0].channelId);
401413
serverMessageBuffer.RemoveAt(0);
402414
}

BubbleTransport/Plugins/GCController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
extern UIViewController *UnityGetGLViewController();
88

9-
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
9+
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
1010
OnClientDidDataRecievedDelegate ClientRecievedData = NULL;
11-
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
11+
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
1212
OnServerDidDataRecievedDelegate ServerRecievedData = NULL;
1313
typedef void (*OnServerConnectedDelegate)(int connId);
1414
OnServerConnectedDelegate ServerConnected = NULL;
@@ -178,7 +178,7 @@ void SendMessageToClient(int clientId, Byte data[], int offset, int count, int c
178178

179179
[GCController sendDataToPlayer:dataToSend toPlayer:clientId datamode:channel];
180180
}
181-
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
181+
typedef void (*OnClientDidDataRecievedDelegate)(intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
182182
void RegisterClientDataRecieveCallback(OnClientDidDataRecievedDelegate callback)
183183
{
184184
if(ClientRecievedData == NULL)
@@ -234,7 +234,7 @@ void RegisterOnClientDisconnectedCallback(OnClientDisconnectedDelegate callback)
234234
ClientDisconnected = callback;
235235
}
236236
}
237-
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t ChannelId);
237+
typedef void (*OnServerDidDataRecievedDelegate)(int connId, intptr_t data, uint32_t offset, uint32_t count, uint32_t channelId);
238238
void RegisterServerDataRecieveCallback(OnServerDidDataRecievedDelegate callback)
239239
{
240240
if(ServerRecievedData == NULL)

0 commit comments

Comments
 (0)