@@ -185,94 +185,29 @@ describe('WorldNetworkActionReceptors', () => {
185
185
186
186
describe ( 'destroyObject' , ( ) => { } )
187
187
188
- describe ( 'transfer ownership of object' , ( ) => {
189
- it ( 'should transfer ownership of object from host to client' , async ( ) => {
188
+ describe ( 'transfer authority of object' , ( ) => {
189
+ it ( 'should transfer authority of object (and not ownership)' , async ( ) => {
190
+ const hostUserId = 'world' as UserId
190
191
const userId = 'user id' as UserId
191
- const hostId = 'host' as UserId
192
192
const peerID = 'peer id' as PeerID
193
193
const peerID2 = 'peer id 2' as PeerID
194
194
195
195
Engine . instance . userId = userId
196
-
197
196
const network = Engine . instance . worldNetwork as Network
198
197
network . peerID = peerID
199
198
200
- NetworkPeerFunctions . createPeer ( network , peerID , 0 , hostId , 0 , 'host' )
199
+ NetworkPeerFunctions . createPeer ( network , peerID , 0 , hostUserId , 0 , 'host' )
201
200
NetworkPeerFunctions . createPeer ( network , peerID2 , 1 , userId , 1 , 'user name' )
202
201
203
202
const objNetId = 3 as NetworkId
204
203
const objPrefab = 'generic prefab'
205
204
206
205
WorldNetworkActionReceptor . receiveSpawnObject (
207
206
WorldNetworkAction . spawnObject ( {
208
- $from : hostId , // from host
207
+ $from : Engine . instance . worldNetwork . hostId , // from host
209
208
prefab : objPrefab , // generic prefab
210
209
networkId : objNetId ,
211
- $peer : network . peerID
212
- } )
213
- )
214
-
215
- const networkObjectQuery = defineQuery ( [ NetworkObjectComponent ] )
216
- const networkObjectOwnedQuery = defineQuery ( [ NetworkObjectOwnedTag ] )
217
-
218
- const networkObjectEntitiesBefore = networkObjectQuery ( )
219
- const networkObjectOwnedEntitiesBefore = networkObjectOwnedQuery ( )
220
-
221
- assert . equal ( networkObjectEntitiesBefore . length , 1 )
222
- assert . equal ( networkObjectOwnedEntitiesBefore . length , 0 )
223
-
224
- console . log ( getComponent ( networkObjectEntitiesBefore [ 0 ] , NetworkObjectComponent ) , '----' )
225
-
226
- WorldNetworkActionReceptor . receiveRequestAuthorityOverObject (
227
- WorldNetworkAction . requestAuthorityOverObject ( {
228
- $from : hostId , // from host
229
- ownerId : hostId ,
230
- networkId : objNetId ,
231
210
$topic : NetworkTopics . world ,
232
- newAuthority : peerID2
233
- } )
234
- )
235
-
236
- const system = await WorldNetworkActionSystem ( )
237
-
238
- ActionFunctions . clearOutgoingActions ( network . topic )
239
- ActionFunctions . applyIncomingActions ( )
240
-
241
- system . execute ( )
242
-
243
- const networkObjectEntitiesAfter = networkObjectQuery ( )
244
- const networkObjectOwnedEntitiesAfter = networkObjectOwnedQuery ( )
245
-
246
- assert . equal ( networkObjectEntitiesAfter . length , 1 )
247
- assert . equal ( networkObjectOwnedEntitiesAfter . length , 0 )
248
-
249
- assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . networkId , objNetId )
250
- assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . authorityPeerID , peerID2 )
251
- assert . equal ( hasComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectOwnedTag ) , false )
252
- } )
253
-
254
- it ( 'should not transfer authority of object (only host can process authority transfer)' , async ( ) => {
255
- const userId = 'user id' as UserId
256
- const hostId = 'host' as UserId
257
- const peerID = 'peer id' as PeerID
258
- const peerID2 = 'peer id 2' as PeerID
259
-
260
- Engine . instance . userId = userId
261
-
262
- const network = Engine . instance . worldNetwork as Network
263
- network . peerID = peerID
264
-
265
- NetworkPeerFunctions . createPeer ( network , peerID , 0 , hostId , 0 , 'host' )
266
- NetworkPeerFunctions . createPeer ( network , peerID2 , 1 , userId , 1 , 'user name' )
267
-
268
- const objNetId = 3 as NetworkId
269
- const objPrefab = 'generic prefab'
270
-
271
- WorldNetworkActionReceptor . receiveSpawnObject (
272
- WorldNetworkAction . spawnObject ( {
273
- $from : hostId , // from host
274
- prefab : objPrefab , // generic prefab
275
- networkId : objNetId ,
276
211
$peer : network . peerID
277
212
} )
278
213
)
@@ -286,12 +221,13 @@ describe('WorldNetworkActionReceptors', () => {
286
221
assert . equal ( networkObjectEntitiesBefore . length , 1 )
287
222
assert . equal ( networkObjectOwnedEntitiesBefore . length , 0 )
288
223
289
- console . log ( getComponent ( networkObjectEntitiesBefore [ 0 ] , NetworkObjectComponent ) , '----' )
224
+ assert . equal ( getComponent ( networkObjectEntitiesBefore [ 0 ] , NetworkObjectComponent ) . ownerId , hostUserId )
225
+ assert . equal ( getComponent ( networkObjectEntitiesBefore [ 0 ] , NetworkObjectComponent ) . authorityPeerID , peerID )
290
226
291
227
WorldNetworkActionReceptor . receiveRequestAuthorityOverObject (
292
228
WorldNetworkAction . requestAuthorityOverObject ( {
293
- $from : userId , // from user
294
- ownerId : hostId ,
229
+ $from : hostUserId , // from host
230
+ ownerId : hostUserId ,
295
231
networkId : objNetId ,
296
232
$topic : NetworkTopics . world ,
297
233
newAuthority : peerID2
@@ -311,8 +247,8 @@ describe('WorldNetworkActionReceptors', () => {
311
247
assert . equal ( networkObjectEntitiesAfter . length , 1 )
312
248
assert . equal ( networkObjectOwnedEntitiesAfter . length , 0 )
313
249
314
- assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . networkId , objNetId )
315
- assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . authorityPeerID , peerID )
250
+ assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . ownerId , hostUserId ) // owner remains same
251
+ assert . equal ( getComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectComponent ) . authorityPeerID , peerID2 ) // peer has changed
316
252
assert . equal ( hasComponent ( networkObjectEntitiesAfter [ 0 ] , NetworkObjectOwnedTag ) , false )
317
253
} )
318
254
} )
0 commit comments