mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: #3342 InitSyncObject IsWritable/IsRecording permissions fixed for host mode and other player's objects on client
This commit is contained in:
parent
d645aad95c
commit
02218bda13
@ -229,12 +229,20 @@ protected void InitSyncObject(SyncObject syncObject)
|
||||
// InitSyncObject yet, which is called from the constructor.
|
||||
syncObject.IsWritable = () =>
|
||||
{
|
||||
// check isServer first.
|
||||
// if we check isClient first, it wouldn't work in host mode.
|
||||
// carefully check each mode separately to ensure correct results.
|
||||
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3342
|
||||
|
||||
// host mode: any ServerToClient and any local client owned
|
||||
if (isServer && isClient) return syncDirection == SyncDirection.ServerToClient || isOwned;
|
||||
|
||||
// server only: any ServerToClient
|
||||
if (isServer) return syncDirection == SyncDirection.ServerToClient;
|
||||
if (isClient) return isOwned;
|
||||
|
||||
// client only: only ClientToServer and owned
|
||||
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
|
||||
|
||||
// undefined behaviour should throw to make it very obvious
|
||||
throw new Exception("InitSyncObject: neither isServer nor isClient are true.");
|
||||
throw new Exception("InitSyncObject: IsWritable: neither isServer nor isClient are true.");
|
||||
};
|
||||
|
||||
// when do we record changes:
|
||||
@ -246,12 +254,20 @@ protected void InitSyncObject(SyncObject syncObject)
|
||||
// because OnSerialize isn't called without observers.
|
||||
syncObject.IsRecording = () =>
|
||||
{
|
||||
// check isServer first.
|
||||
// if we check isClient first, it wouldn't work in host mode.
|
||||
// carefully check each mode separately to ensure correct results.
|
||||
// fixes: https://github.com/MirrorNetworking/Mirror/issues/3342
|
||||
|
||||
// host mode: only if observed
|
||||
if (isServer && isClient) return netIdentity.observers.Count > 0;
|
||||
|
||||
// server only: only if observed
|
||||
if (isServer) return netIdentity.observers.Count > 0;
|
||||
if (isClient) return isOwned;
|
||||
|
||||
// client only: only ClientToServer and owned
|
||||
if (isClient) return syncDirection == SyncDirection.ClientToServer && isOwned;
|
||||
|
||||
// undefined behaviour should throw to make it very obvious
|
||||
throw new Exception("InitSyncObject: neither isServer nor isClient are true.");
|
||||
throw new Exception("InitSyncObject: IsRecording: neither isServer nor isClient are true.");
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user