@@ -43,6 +43,8 @@ public enum ConnectionIdSpreadMethod
4343
4444 private byte _lastProcessedTransportIndex ;
4545
46+ public override bool IsSupported => true ;
47+
4648 public override void DisconnectLocalClient ( )
4749 {
4850 Transports [ GetFirstSupportedTransportIndex ( ) ] . DisconnectLocalClient ( ) ;
@@ -80,33 +82,46 @@ public override void Init()
8082 }
8183 }
8284
83- public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload )
85+ public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload , out float receiveTime )
8486 {
85- if ( _lastProcessedTransportIndex > Transports . Length )
87+ if ( _lastProcessedTransportIndex >= Transports . Length - 1 )
8688 _lastProcessedTransportIndex = 0 ;
8789
8890 for ( byte i = _lastProcessedTransportIndex ; i < Transports . Length ; i ++ )
8991 {
92+ _lastProcessedTransportIndex = i ;
93+
9094 if ( Transports [ i ] . IsSupported )
9195 {
92- _lastProcessedTransportIndex = i ;
96+ NetEventType @eventType = Transports [ i ] . PollEvent ( out ulong connectionId , out channelName , out payload , out receiveTime ) ;
97+
98+ if ( @eventType != NetEventType . Nothing )
99+ {
100+ clientId = GetMLAPIClientId ( i , connectionId , false ) ;
93101
94- return Transports [ i ] . PollEvent ( out clientId , out channelName , out payload ) ;
102+ return @eventType ;
103+ }
95104 }
96105 }
97106
98107 clientId = 0 ;
99108 channelName = null ;
100109 payload = new ArraySegment < byte > ( ) ;
110+ receiveTime = 0 ;
101111
102112 return NetEventType . Nothing ;
103113 }
104114
115+ public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload )
116+ {
117+ return PollEvent ( out clientId , out channelName , out payload , out float _ ) ;
118+ }
119+
105120 public override void Send ( ulong clientId , ArraySegment < byte > data , string channelName , bool skipQueue )
106121 {
107122 GetMultiplexTransportDetails ( clientId , out byte transportId , out ulong connectionId ) ;
108123
109- Transports [ transportId ] . Send ( clientId , data , channelName , skipQueue ) ;
124+ Transports [ transportId ] . Send ( connectionId , data , channelName , skipQueue ) ;
110125 }
111126
112127 public override void Shutdown ( )
@@ -151,9 +166,6 @@ public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServe
151166 }
152167 else
153168 {
154- // 0 Is reserved.
155- connectionId += 1 ;
156-
157169 switch ( SpreadMethod )
158170 {
159171 case ConnectionIdSpreadMethod . ReplaceFirstBits :
@@ -167,7 +179,7 @@ public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServe
167179 // Place transportId there
168180 ulong shiftedTransportId = ( ulong ) transportId << ( ( sizeof ( ulong ) * 8 ) - bits ) ;
169181
170- return clientId | shiftedTransportId ;
182+ return ( clientId | shiftedTransportId ) + 1 ;
171183 }
172184 case ConnectionIdSpreadMethod . MakeRoomFirstBits :
173185 {
@@ -180,7 +192,7 @@ public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServe
180192 // Place transportId there
181193 ulong shiftedTransportId = ( ulong ) transportId << ( ( sizeof ( ulong ) * 8 ) - bits ) ;
182194
183- return clientId | shiftedTransportId ;
195+ return ( clientId | shiftedTransportId ) + 1 ;
184196 }
185197 case ConnectionIdSpreadMethod . ReplaceLastBits :
186198 {
@@ -191,7 +203,7 @@ public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServe
191203 ulong clientId = ( ( connectionId >> bits ) << bits ) ;
192204
193205 // Return the transport inserted at the end
194- return clientId | transportId ;
206+ return ( clientId | transportId ) + 1 ;
195207 }
196208 case ConnectionIdSpreadMethod . MakeRoomLastBits :
197209 {
@@ -202,11 +214,11 @@ public ulong GetMLAPIClientId(byte transportId, ulong connectionId, bool isServe
202214 ulong clientId = ( connectionId << bits ) ;
203215
204216 // Return the transport inserted at the end
205- return clientId | transportId ;
217+ return ( clientId | transportId ) + 1 ;
206218 }
207219 case ConnectionIdSpreadMethod . Spread :
208220 {
209- return connectionId * ( ulong ) Transports . Length + ( ulong ) transportId ;
221+ return ( connectionId * ( ulong ) Transports . Length + ( ulong ) transportId ) + 1 ;
210222 }
211223 default :
212224 {
@@ -229,44 +241,59 @@ public void GetMultiplexTransportDetails(ulong clientId, out byte transportId, o
229241 {
230242 case ConnectionIdSpreadMethod . ReplaceFirstBits :
231243 {
244+ // The first clientId is reserved. Thus every clientId is always offset by 1
245+ clientId -- ;
246+
232247 // Calculate bits to store transportId
233248 byte bits = ( byte ) UnityEngine . Mathf . CeilToInt ( UnityEngine . Mathf . Log ( Transports . Length , 2 ) ) ;
234249
235250 transportId = ( byte ) ( clientId >> ( ( sizeof ( ulong ) * 8 ) - bits ) ) ;
236- connectionId = ( ( clientId << bits ) >> bits ) + 1 ;
251+ connectionId = ( ( clientId << bits ) >> bits ) ;
237252 break ;
238253 }
239254 case ConnectionIdSpreadMethod . MakeRoomFirstBits :
240255 {
256+ // The first clientId is reserved. Thus every clientId is always offset by 1
257+ clientId -- ;
258+
241259 // Calculate bits to store transportId
242260 byte bits = ( byte ) UnityEngine . Mathf . CeilToInt ( UnityEngine . Mathf . Log ( Transports . Length , 2 ) ) ;
243261
244262 transportId = ( byte ) ( clientId >> ( ( sizeof ( ulong ) * 8 ) - bits ) ) ;
245- connectionId = ( clientId << bits ) + 1 ;
263+ connectionId = ( clientId << bits ) ;
246264 break ;
247265 }
248266 case ConnectionIdSpreadMethod . ReplaceLastBits :
249267 {
268+ // The first clientId is reserved. Thus every clientId is always offset by 1
269+ clientId -- ;
270+
250271 // Calculate bits to store transportId
251272 byte bits = ( byte ) UnityEngine . Mathf . CeilToInt ( UnityEngine . Mathf . Log ( Transports . Length , 2 ) ) ;
252273
253274 transportId = ( byte ) ( ( clientId << ( ( sizeof ( ulong ) * 8 ) - bits ) ) >> ( ( sizeof ( ulong ) * 8 ) - bits ) ) ;
254- connectionId = ( ( clientId >> bits ) << bits ) + 1 ;
275+ connectionId = ( ( clientId >> bits ) << bits ) ;
255276 break ;
256277 }
257278 case ConnectionIdSpreadMethod . MakeRoomLastBits :
258279 {
280+ // The first clientId is reserved. Thus every clientId is always offset by 1
281+ clientId -- ;
282+
259283 // Calculate bits to store transportId
260284 byte bits = ( byte ) UnityEngine . Mathf . CeilToInt ( UnityEngine . Mathf . Log ( Transports . Length , 2 ) ) ;
261285
262286 transportId = ( byte ) ( ( clientId << ( ( sizeof ( ulong ) * 8 ) - bits ) ) >> ( ( sizeof ( ulong ) * 8 ) - bits ) ) ;
263- connectionId = ( clientId >> bits ) + 1 ;
287+ connectionId = ( clientId >> bits ) ;
264288 break ;
265289 }
266290 case ConnectionIdSpreadMethod . Spread :
267291 {
292+ // The first clientId is reserved. Thus every clientId is always offset by 1
293+ clientId -- ;
294+
268295 transportId = ( byte ) ( clientId % ( ulong ) Transports . Length ) ;
269- connectionId = ( clientId / ( ulong ) Transports . Length ) + 1 ;
296+ connectionId = ( clientId / ( ulong ) Transports . Length ) ;
270297 break ;
271298 }
272299 default :
0 commit comments