@@ -19,12 +19,12 @@ public class UnetTransport : Transport
19
19
public int ServerWebsocketListenPort = 8887 ;
20
20
public bool SupportWebsocket = false ;
21
21
public List < UnetChannel > Channels = new List < UnetChannel > ( ) ;
22
-
22
+
23
23
// Relay
24
24
public bool UseMLAPIRelay = false ;
25
25
public string MLAPIRelayAddress = "184.72.104.138" ;
26
26
public int MLAPIRelayPort = 8888 ;
27
-
27
+
28
28
// Runtime / state
29
29
private byte [ ] messageBuffer ;
30
30
private WeakReference temporaryBufferReference ;
@@ -38,11 +38,11 @@ public class UnetTransport : Transport
38
38
private SocketTask connectTask ;
39
39
40
40
public override ulong ServerClientId => GetMLAPIClientId ( 0 , 0 , true ) ;
41
-
41
+
42
42
public override void Send ( ulong clientId , ArraySegment < byte > data , string channelName )
43
- {
43
+ {
44
44
GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
45
-
45
+
46
46
int channelId = channelNameToId [ channelName ] ;
47
47
48
48
byte [ ] buffer ;
@@ -67,7 +67,7 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
67
67
temporaryBufferReference = new WeakReference ( buffer ) ;
68
68
}
69
69
}
70
-
70
+
71
71
Buffer . BlockCopy ( data . Array , data . Offset , buffer , 0 , data . Count ) ;
72
72
}
73
73
else
@@ -81,17 +81,17 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
81
81
public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload , out float receiveTime )
82
82
{
83
83
NetworkEventType eventType = RelayTransport . Receive ( out int hostId , out int connectionId , out int channelId , messageBuffer , messageBuffer . Length , out int receivedSize , out byte error ) ;
84
-
84
+
85
85
clientId = GetMLAPIClientId ( ( byte ) hostId , ( ushort ) connectionId , false ) ;
86
86
87
87
receiveTime = UnityEngine . Time . realtimeSinceStartup ;
88
88
89
89
NetworkError networkError = ( NetworkError ) error ;
90
-
90
+
91
91
if ( networkError == NetworkError . MessageToLong )
92
92
{
93
93
byte [ ] tempBuffer ;
94
-
94
+
95
95
if ( temporaryBufferReference != null && temporaryBufferReference . IsAlive && ( ( byte [ ] ) temporaryBufferReference . Target ) . Length >= receivedSize )
96
96
{
97
97
tempBuffer = ( byte [ ] ) temporaryBufferReference . Target ;
@@ -101,7 +101,7 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
101
101
tempBuffer = new byte [ receivedSize ] ;
102
102
temporaryBufferReference = new WeakReference ( tempBuffer ) ;
103
103
}
104
-
104
+
105
105
eventType = RelayTransport . Receive ( out hostId , out connectionId , out channelId , tempBuffer , tempBuffer . Length , out receivedSize , out error ) ;
106
106
payload = new ArraySegment < byte > ( tempBuffer , 0 , receivedSize ) ;
107
107
}
@@ -162,7 +162,7 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
162
162
case NetworkEventType . BroadcastEvent :
163
163
return NetEventType . Nothing ;
164
164
}
165
-
165
+
166
166
return NetEventType . Nothing ;
167
167
}
168
168
@@ -190,7 +190,7 @@ public override SocketTasks StartClient()
190
190
task . Success = false ;
191
191
task . TransportCode = error ;
192
192
task . SocketError = System . Net . Sockets . SocketError . SocketError ;
193
- task . IsDone = false ;
193
+ task . IsDone = true ;
194
194
break ;
195
195
}
196
196
@@ -200,7 +200,7 @@ public override SocketTasks StartClient()
200
200
public override SocketTasks StartServer ( )
201
201
{
202
202
HostTopology topology = new HostTopology ( GetConfig ( ) , MaxConnections ) ;
203
-
203
+
204
204
if ( SupportWebsocket )
205
205
{
206
206
if ( ! UseMLAPIRelay )
@@ -211,9 +211,9 @@ public override SocketTasks StartServer()
211
211
{
212
212
if ( LogHelper . CurrentLogLevel <= LogLevel . Error ) LogHelper . LogError ( "Cannot create websocket host when using MLAPI relay" ) ;
213
213
}
214
-
214
+
215
215
}
216
-
216
+
217
217
int normalHostId = RelayTransport . AddHost ( topology , ServerListenPort , true ) ;
218
218
219
219
return SocketTask . Done . AsTasks ( ) ;
@@ -255,12 +255,12 @@ public override void Shutdown()
255
255
public override void Init ( )
256
256
{
257
257
UpdateRelay ( ) ;
258
-
258
+
259
259
messageBuffer = new byte [ MessageBufferSize ] ;
260
-
260
+
261
261
NetworkTransport . Init ( ) ;
262
262
}
263
-
263
+
264
264
public ulong GetMLAPIClientId ( byte hostId , ushort connectionId , bool isServer )
265
265
{
266
266
if ( isServer )
@@ -290,26 +290,26 @@ public void GetUnetConnectionDetails(ulong clientId, out byte hostId, out ushort
290
290
public ConnectionConfig GetConfig ( )
291
291
{
292
292
ConnectionConfig config = new ConnectionConfig ( ) ;
293
-
293
+
294
294
for ( int i = 0 ; i < MLAPI_CHANNELS . Length ; i ++ )
295
295
{
296
296
int channelId = AddMLAPIChannel ( MLAPI_CHANNELS [ i ] . Type , config ) ;
297
-
297
+
298
298
channelIdToName . Add ( channelId , MLAPI_CHANNELS [ i ] . Name ) ;
299
299
channelNameToId . Add ( MLAPI_CHANNELS [ i ] . Name , channelId ) ;
300
300
}
301
301
302
302
for ( int i = 0 ; i < Channels . Count ; i ++ )
303
303
{
304
304
int channelId = AddUNETChannel ( Channels [ i ] . Type , config ) ;
305
-
305
+
306
306
channelIdToName . Add ( channelId , Channels [ i ] . Name ) ;
307
307
channelNameToId . Add ( Channels [ i ] . Name , channelId ) ;
308
308
}
309
309
310
310
return config ;
311
311
}
312
-
312
+
313
313
public int AddMLAPIChannel ( ChannelType type , ConnectionConfig config )
314
314
{
315
315
switch ( type )
@@ -328,7 +328,7 @@ public int AddMLAPIChannel(ChannelType type, ConnectionConfig config)
328
328
329
329
return 0 ;
330
330
}
331
-
331
+
332
332
public int AddUNETChannel ( QosType type , ConnectionConfig config )
333
333
{
334
334
switch ( type )
@@ -368,4 +368,4 @@ private void UpdateRelay()
368
368
}
369
369
}
370
370
}
371
- #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
371
+ #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
0 commit comments