Skip to content

Commit 77c4d36

Browse files
committed
Prevent players who have ownership of the player from locking it
- Make sure only the 'privileged' users can lock the video player (aka at the moment the current master and the instance creator). I wasn't sure if I wanted to allow people to take exclusive control over the video player without being master or instance owner, but ended up deciding that it could be too confusing and annoying for others.
1 parent 551025b commit 77c4d36

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

Assets/USharpVideo/Scripts/USharpVideoPlayer.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,12 @@ private void Update()
448448
UpdateRenderTexture(); // Needed because AVPro can swap textures whenever
449449
}
450450

451+
/// <summary>
452+
/// Uncomment this to prevent people from taking ownership of the video player when they shouldn't be able to
453+
/// </summary>
451454
//public override bool OnOwnershipRequest(VRCPlayerApi requestingPlayer, VRCPlayerApi requestedOwner)
452455
//{
453-
// return !_isMasterOnly || requestedOwner.isMaster || requestedOwner.isInstanceOwner;
456+
// return !_isMasterOnly || IsPrivlegedUser(requestedOwner);
454457
//}
455458

456459
bool _lastMasterLocked = false;
@@ -903,17 +906,30 @@ public void _SendFinalSync()
903906
}
904907

905908
/// <summary>
906-
/// Determines if the player can control this video player. This means the player is either the master, the instance creator, or the video player is unlocked.
909+
/// Determines if the local player can control this video player. This means the player is either the master, the instance creator, or the video player is unlocked.
907910
/// </summary>
908911
/// <returns></returns>
909912
[PublicAPI]
910913
public bool CanControlVideoPlayer()
911914
{
915+
return !_isMasterOnly || IsPrivilegedUser(Networking.LocalPlayer);
916+
}
917+
918+
/// <summary>
919+
/// If the given player is allowed to take important actions on this video player such as changing the video or locking the video player.
920+
/// This is what you would extend if you want to add an access control list or something similar.
921+
/// </summary>
922+
/// <param name="player"></param>
923+
/// <returns></returns>
924+
[PublicAPI]
925+
public bool IsPrivilegedUser(VRCPlayerApi player)
926+
{
912927
#if UNITY_EDITOR
913-
return Networking.IsMaster || !_isMasterOnly;
914-
#else
915-
return Networking.IsMaster || !_isMasterOnly || (allowInstanceCreatorControl && Networking.LocalPlayer.isInstanceOwner);
928+
if (player == null)
929+
return true;
916930
#endif
931+
932+
return player.isMaster || (allowInstanceCreatorControl && player.isInstanceOwner);
917933
}
918934

919935
/// <summary>

Assets/USharpVideo/Scripts/VideoControlHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,11 @@ public void OnPlayButtonPress()
370370

371371
public void OnLockButtonPress()
372372
{
373-
targetVideoPlayer.TakeOwnership();
374-
targetVideoPlayer.SetLocked(!targetVideoPlayer.IsLocked());
373+
if (targetVideoPlayer.IsPrivilegedUser(Networking.LocalPlayer))
374+
{
375+
targetVideoPlayer.TakeOwnership();
376+
targetVideoPlayer.SetLocked(!targetVideoPlayer.IsLocked());
377+
}
375378
}
376379

377380
public void OnReloadButtonPressed()

Assets/USharpVideo/version.txt.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)