22using System ;
33using System . Collections . Generic ;
44using MLAPI . Logging ;
5+ using UnityEngine ;
56using UnityEngine . Networking ;
67
78namespace MLAPI . Transports . UNET
@@ -38,9 +39,7 @@ public class UnetTransport : Transport
3839 public override ulong ServerClientId => GetMLAPIClientId ( 0 , 0 , true ) ;
3940
4041 public override void Send ( ulong clientId , ArraySegment < byte > data , string channelName , bool skipQueue )
41- {
42- UpdateRelay ( ) ;
43-
42+ {
4443 GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
4544
4645 int channelId = channelNameToId [ channelName ] ;
@@ -87,19 +86,15 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
8786
8887 public override void FlushSendQueue ( ulong clientId )
8988 {
90- UpdateRelay ( ) ;
91-
9289 GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
9390
9491 RelayTransport . SendQueuedMessages ( hostId , connectionId , out byte error ) ;
9592 }
9693
9794 public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload )
98- {
99- UpdateRelay ( ) ;
100-
95+ {
10196 NetworkEventType eventType = RelayTransport . Receive ( out int hostId , out int connectionId , out int channelId , messageBuffer , messageBuffer . Length , out int receivedSize , out byte error ) ;
102-
97+
10398 clientId = GetMLAPIClientId ( ( byte ) hostId , ( ushort ) connectionId , false ) ;
10499
105100 NetworkError networkError = ( NetworkError ) error ;
@@ -128,7 +123,6 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
128123
129124 channelName = channelIdToName [ channelId ] ;
130125
131-
132126 if ( networkError == NetworkError . Timeout )
133127 {
134128 // In UNET. Timeouts are not disconnects. We have to translate that here.
@@ -154,18 +148,14 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
154148 }
155149
156150 public override void StartClient ( )
157- {
158- UpdateRelay ( ) ;
159-
151+ {
160152 serverHostId = RelayTransport . AddHost ( new HostTopology ( GetConfig ( ) , 1 ) , false ) ;
161153
162154 serverConnectionId = RelayTransport . Connect ( serverHostId , ConnectAddress , ConnectPort , 0 , out byte error ) ;
163155 }
164156
165157 public override void StartServer ( )
166158 {
167- UpdateRelay ( ) ;
168-
169159 HostTopology topology = new HostTopology ( GetConfig ( ) , MaxConnections ) ;
170160
171161 if ( SupportWebsocket )
@@ -186,17 +176,13 @@ public override void StartServer()
186176
187177 public override void DisconnectRemoteClient ( ulong clientId )
188178 {
189- UpdateRelay ( ) ;
190-
191179 GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
192180
193181 RelayTransport . Disconnect ( ( int ) hostId , ( int ) connectionId , out byte error ) ;
194182 }
195183
196184 public override void DisconnectLocalClient ( )
197185 {
198- UpdateRelay ( ) ;
199-
200186 RelayTransport . Disconnect ( serverHostId , serverConnectionId , out byte error ) ;
201187 }
202188
@@ -221,6 +207,8 @@ public override void Shutdown()
221207
222208 public override void Init ( )
223209 {
210+ UpdateRelay ( ) ;
211+
224212 messageBuffer = new byte [ MessageBufferSize ] ;
225213
226214 NetworkTransport . Init ( ) ;
0 commit comments