@@ -346,48 +346,52 @@ internal void NetworkedVarUpdate()
346
346
347
347
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
348
348
{
349
- //This iterates over every "channel group".
350
- for ( int j = 0 ; j < channelMappedVarIndexes . Count ; j ++ )
349
+ // Do this check here to prevent doing all the expensive dirty checks
350
+ if ( ! IsServer || this . NetworkedObject . observers . Contains ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ) )
351
351
{
352
- using ( PooledBitStream stream = PooledBitStream . Get ( ) )
352
+ //This iterates over every "channel group".
353
+ for ( int j = 0 ; j < channelMappedVarIndexes . Count ; j ++ )
353
354
{
354
- using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
355
+ using ( PooledBitStream stream = PooledBitStream . Get ( ) )
355
356
{
356
- writer . WriteUInt32Packed ( NetworkId ) ;
357
- writer . WriteUInt16Packed ( NetworkedObject . GetOrderIndex ( this ) ) ;
358
-
359
- uint clientId = NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ;
360
- bool writtenAny = false ;
361
- for ( int k = 0 ; k < networkedVarFields . Count ; k ++ )
357
+ using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
362
358
{
363
- if ( ! channelMappedVarIndexes [ j ] . Contains ( k ) )
359
+ writer . WriteUInt32Packed ( NetworkId ) ;
360
+ writer . WriteUInt16Packed ( NetworkedObject . GetOrderIndex ( this ) ) ;
361
+
362
+ uint clientId = NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ;
363
+ bool writtenAny = false ;
364
+ for ( int k = 0 ; k < networkedVarFields . Count ; k ++ )
364
365
{
365
- //This var does not belong to the currently iterating channel group.
366
- writer . WriteBool ( false ) ;
367
- continue ;
368
- }
366
+ if ( ! channelMappedVarIndexes [ j ] . Contains ( k ) )
367
+ {
368
+ //This var does not belong to the currently iterating channel group.
369
+ writer . WriteBool ( false ) ;
370
+ continue ;
371
+ }
369
372
370
- bool isDirty = networkedVarFields [ k ] . IsDirty ( ) ; //cache this here. You never know what operations users will do in the dirty methods
371
- writer . WriteBool ( isDirty ) ;
373
+ bool isDirty = networkedVarFields [ k ] . IsDirty ( ) ; //cache this here. You never know what operations users will do in the dirty methods
374
+ writer . WriteBool ( isDirty ) ;
372
375
373
- if ( isDirty && ( ! IsServer || networkedVarFields [ k ] . CanClientRead ( clientId ) ) )
374
- {
375
- writtenAny = true ;
376
- networkedVarFields [ k ] . WriteDelta ( stream ) ;
377
- if ( ! networkedVarIndexesToResetSet . Contains ( k ) )
376
+ if ( isDirty && ( ! IsServer || networkedVarFields [ k ] . CanClientRead ( clientId ) ) )
378
377
{
379
- networkedVarIndexesToResetSet . Add ( k ) ;
380
- networkedVarIndexesToReset . Add ( k ) ;
378
+ writtenAny = true ;
379
+ networkedVarFields [ k ] . WriteDelta ( stream ) ;
380
+ if ( ! networkedVarIndexesToResetSet . Contains ( k ) )
381
+ {
382
+ networkedVarIndexesToResetSet . Add ( k ) ;
383
+ networkedVarIndexesToReset . Add ( k ) ;
384
+ }
381
385
}
382
386
}
383
- }
384
-
385
- if ( writtenAny )
386
- {
387
- if ( IsServer )
388
- InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_NETWORKED_VAR_DELTA , channelsForVarGroups [ j ] , stream , SecuritySendFlags . None ) ;
389
- else
390
- InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_NETWORKED_VAR_DELTA , channelsForVarGroups [ j ] , stream , SecuritySendFlags . None ) ;
387
+
388
+ if ( writtenAny )
389
+ {
390
+ if ( IsServer )
391
+ InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_NETWORKED_VAR_DELTA , channelsForVarGroups [ j ] , stream , SecuritySendFlags . None , this . NetworkedObject ) ;
392
+ else
393
+ InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_NETWORKED_VAR_DELTA , channelsForVarGroups [ j ] , stream , SecuritySendFlags . None , null ) ;
394
+ }
391
395
}
392
396
}
393
397
}
@@ -875,7 +879,7 @@ internal void SendServerRPCPerformance(ulong hash, Stream messageStream, string
875
879
}
876
880
else
877
881
{
878
- InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_SERVER_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
882
+ InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_SERVER_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
879
883
}
880
884
}
881
885
}
@@ -932,7 +936,7 @@ internal RpcResponse<T> SendServerRPCPerformanceResponse<T>(ulong hash, Stream m
932
936
933
937
ResponseMessageManager . Add ( response . Id , response ) ;
934
938
935
- InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_SERVER_RPC_REQUEST , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
939
+ InternalMessageHandler . Send ( NetworkingManager . Singleton . ServerClientId , MLAPIConstants . MLAPI_SERVER_RPC_REQUEST , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
936
940
937
941
return response ;
938
942
}
@@ -963,29 +967,40 @@ internal void SendClientRPCPerformance(ulong hash, List<uint> clientIds, Stream
963
967
{
964
968
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
965
969
{
970
+ if ( ! this . NetworkedObject . observers . Contains ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ) )
971
+ {
972
+ continue ;
973
+ }
974
+
966
975
if ( IsHost && NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId == NetworkingManager . Singleton . LocalClientId )
967
976
{
968
977
messageStream . Position = 0 ;
969
978
InvokeClientRPCLocal ( hash , NetworkingManager . Singleton . LocalClientId , messageStream ) ;
970
979
}
971
980
else
972
981
{
973
- InternalMessageHandler . Send ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
982
+ InternalMessageHandler . Send ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
974
983
}
975
984
}
976
985
}
977
986
else
978
987
{
979
988
for ( int i = 0 ; i < clientIds . Count ; i ++ )
980
989
{
990
+ if ( ! this . NetworkedObject . observers . Contains ( clientIds [ i ] ) )
991
+ {
992
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Cannot send ClientRPC to client without visibility to the object" ) ;
993
+ continue ;
994
+ }
995
+
981
996
if ( IsHost && clientIds [ i ] == NetworkingManager . Singleton . LocalClientId )
982
997
{
983
998
messageStream . Position = 0 ;
984
999
InvokeClientRPCLocal ( hash , NetworkingManager . Singleton . LocalClientId , messageStream ) ;
985
1000
}
986
1001
else
987
1002
{
988
- InternalMessageHandler . Send ( clientIds [ i ] , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
1003
+ InternalMessageHandler . Send ( clientIds [ i ] , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
989
1004
}
990
1005
}
991
1006
}
@@ -1015,16 +1030,17 @@ internal void SendClientRPCPerformance(ulong hash, Stream messageStream, uint cl
1015
1030
1016
1031
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
1017
1032
{
1018
- if ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId == clientIdToIgnore )
1033
+ if ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId == clientIdToIgnore || ! this . NetworkedObject . observers . Contains ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ) )
1019
1034
continue ;
1035
+
1020
1036
if ( IsHost && NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId == NetworkingManager . Singleton . LocalClientId )
1021
1037
{
1022
1038
messageStream . Position = 0 ;
1023
1039
InvokeClientRPCLocal ( hash , NetworkingManager . Singleton . LocalClientId , messageStream ) ;
1024
1040
}
1025
1041
else
1026
1042
{
1027
- InternalMessageHandler . Send ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
1043
+ InternalMessageHandler . Send ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
1028
1044
}
1029
1045
}
1030
1046
}
@@ -1039,6 +1055,12 @@ internal void SendClientRPCPerformance(ulong hash, uint clientId, Stream message
1039
1055
if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Only clients and host can invoke ClientRPC" ) ;
1040
1056
return ;
1041
1057
}
1058
+
1059
+ if ( ! this . NetworkedObject . observers . Contains ( clientId ) )
1060
+ {
1061
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Cannot send ClientRPC to client without visibility to the object" ) ;
1062
+ return ;
1063
+ }
1042
1064
1043
1065
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
1044
1066
{
@@ -1057,7 +1079,7 @@ internal void SendClientRPCPerformance(ulong hash, uint clientId, Stream message
1057
1079
}
1058
1080
else
1059
1081
{
1060
- InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
1082
+ InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_CLIENT_RPC , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
1061
1083
}
1062
1084
}
1063
1085
}
@@ -1072,6 +1094,12 @@ internal RpcResponse<T> SendClientRPCPerformanceResponse<T>(ulong hash, uint cli
1072
1094
return null ;
1073
1095
}
1074
1096
1097
+ if ( ! this . NetworkedObject . observers . Contains ( clientId ) )
1098
+ {
1099
+ if ( LogHelper . CurrentLogLevel <= LogLevel . Normal ) LogHelper . LogWarning ( "Cannot send ClientRPC to client without visibility to the object" ) ;
1100
+ return null ;
1101
+ }
1102
+
1075
1103
ulong responseId = ResponseMessageManager . GenerateMessageId ( ) ;
1076
1104
1077
1105
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
@@ -1114,7 +1142,7 @@ internal RpcResponse<T> SendClientRPCPerformanceResponse<T>(ulong hash, uint cli
1114
1142
1115
1143
ResponseMessageManager . Add ( response . Id , response ) ;
1116
1144
1117
- InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_CLIENT_RPC_REQUEST , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security ) ;
1145
+ InternalMessageHandler . Send ( clientId , MLAPIConstants . MLAPI_CLIENT_RPC_REQUEST , string . IsNullOrEmpty ( channel ) ? "MLAPI_DEFAULT_MESSAGE" : channel , stream , security , null ) ;
1118
1146
1119
1147
return response ;
1120
1148
}
0 commit comments