Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ Assets/Content/Addressables/Windows/addressables_content_state.bin
Assets/Content/Addressables/Windows/addressables_content_state.bin.meta
Assets/Content/Addressables/link.xml
Assets/Content/Addressables/link.xml.meta
graphify-out/
9 changes: 9 additions & 0 deletions Assets/Scripts/SS3D/Permissions/PermissionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ public class PermissionSettings : ScriptableSettings
[SerializeField]
private bool _addServerOwnerPermissionToServerHost;

[SerializeField]
private bool _adminFunctionsForAll;

/// <summary>
/// We can define if the host will get the owner permission when he joins the game.
/// </summary>
public static bool AddServerOwnerPermissionToServerHost => GetOrFind<PermissionSettings>()._addServerOwnerPermissionToServerHost;

/// <summary>
/// If true, admin-only functions are available to all users.
/// Defaults to false, meaning only admins (host by default) can use admin functions.
/// </summary>
public static bool AdminFunctionsForAll => GetOrFind<PermissionSettings>()._adminFunctionsForAll;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using SS3D.Core;
using SS3D.Core.Behaviours;
using SS3D.Data.Management;
using SS3D.Logging;
using SS3D.Permissions;
using SS3D.Systems.Inputs;
using TMPro;
using UnityEngine;
Expand Down Expand Up @@ -128,6 +130,12 @@ protected override void OnStart()
/// </summary>
private void HandleToggleMenu(InputAction.CallbackContext context)
{
if (!_enabled && !CanAccessTilemapEditor())
{
Log.Information(this, "Player lacks permission to access the tilemap editor", Logs.ServerOnly);
return;
}

if (_enabled)
{
_inputSystem.ToggleActionMap(_controls, false, new[] { _controls.ToggleMenu });
Expand All @@ -145,6 +153,28 @@ private void HandleToggleMenu(InputAction.CallbackContext context)
ClearAllTab();
_tileMapBuildTab.Display();
}

/// <summary>
/// Checks whether the local player is allowed to use the tilemap editor.
/// </summary>
private bool CanAccessTilemapEditor()
{
if (PermissionSettings.AdminFunctionsForAll)
{
return true;
}

string ckey = Core.Settings.LocalPlayer.Ckey;
if (string.IsNullOrEmpty(ckey))
{
return false;
}

PermissionSubSystem permissionSystem = SubSystems.Get<PermissionSubSystem>();
return permissionSystem != null
&& permissionSystem.HasLoadedPermissions
&& permissionSystem.IsAtLeast(ckey, ServerRoleTypes.Administrator);
}

/// <summary>
/// Hide or show the tilemap menu.
Expand Down
Loading