2
2
using System ;
3
3
using System . Collections . Generic ;
4
4
using MLAPI . Logging ;
5
+ using UnityEngine ;
5
6
using UnityEngine . Networking ;
6
7
7
8
namespace MLAPI . Transports . UNET
@@ -38,9 +39,7 @@ public class UnetTransport : Transport
38
39
public override ulong ServerClientId => GetMLAPIClientId ( 0 , 0 , true ) ;
39
40
40
41
public override void Send ( ulong clientId , ArraySegment < byte > data , string channelName , bool skipQueue )
41
- {
42
- UpdateRelay ( ) ;
43
-
42
+ {
44
43
GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
45
44
46
45
int channelId = channelNameToId [ channelName ] ;
@@ -87,19 +86,15 @@ public override void Send(ulong clientId, ArraySegment<byte> data, string channe
87
86
88
87
public override void FlushSendQueue ( ulong clientId )
89
88
{
90
- UpdateRelay ( ) ;
91
-
92
89
GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
93
90
94
91
RelayTransport . SendQueuedMessages ( hostId , connectionId , out byte error ) ;
95
92
}
96
93
97
94
public override NetEventType PollEvent ( out ulong clientId , out string channelName , out ArraySegment < byte > payload )
98
- {
99
- UpdateRelay ( ) ;
100
-
95
+ {
101
96
NetworkEventType eventType = RelayTransport . Receive ( out int hostId , out int connectionId , out int channelId , messageBuffer , messageBuffer . Length , out int receivedSize , out byte error ) ;
102
-
97
+
103
98
clientId = GetMLAPIClientId ( ( byte ) hostId , ( ushort ) connectionId , false ) ;
104
99
105
100
NetworkError networkError = ( NetworkError ) error ;
@@ -128,7 +123,6 @@ public override NetEventType PollEvent(out ulong clientId, out string channelNam
128
123
129
124
channelName = channelIdToName [ channelId ] ;
130
125
131
-
132
126
if ( networkError == NetworkError . Timeout )
133
127
{
134
128
// 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
154
148
}
155
149
156
150
public override void StartClient ( )
157
- {
158
- UpdateRelay ( ) ;
159
-
151
+ {
160
152
serverHostId = RelayTransport . AddHost ( new HostTopology ( GetConfig ( ) , 1 ) , false ) ;
161
153
162
154
serverConnectionId = RelayTransport . Connect ( serverHostId , ConnectAddress , ConnectPort , 0 , out byte error ) ;
163
155
}
164
156
165
157
public override void StartServer ( )
166
158
{
167
- UpdateRelay ( ) ;
168
-
169
159
HostTopology topology = new HostTopology ( GetConfig ( ) , MaxConnections ) ;
170
160
171
161
if ( SupportWebsocket )
@@ -186,17 +176,13 @@ public override void StartServer()
186
176
187
177
public override void DisconnectRemoteClient ( ulong clientId )
188
178
{
189
- UpdateRelay ( ) ;
190
-
191
179
GetUnetConnectionDetails ( clientId , out byte hostId , out ushort connectionId ) ;
192
180
193
181
RelayTransport . Disconnect ( ( int ) hostId , ( int ) connectionId , out byte error ) ;
194
182
}
195
183
196
184
public override void DisconnectLocalClient ( )
197
185
{
198
- UpdateRelay ( ) ;
199
-
200
186
RelayTransport . Disconnect ( serverHostId , serverConnectionId , out byte error ) ;
201
187
}
202
188
@@ -221,6 +207,8 @@ public override void Shutdown()
221
207
222
208
public override void Init ( )
223
209
{
210
+ UpdateRelay ( ) ;
211
+
224
212
messageBuffer = new byte [ MessageBufferSize ] ;
225
213
226
214
NetworkTransport . Init ( ) ;
0 commit comments