Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand permissions system #1267

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System.Collections.Generic;
using System.Linq;
using Coimbra;
using Coimbra.Services.Events;
using Cysharp.Threading.Tasks;
using SS3D.Core;
using SS3D.Core.Behaviours;
using SS3D.Core.Settings;
using SS3D.Core.Utils;
using SS3D.Systems.Permissions.Events;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UserPermissionsChangedEvent = SS3D.Permissions.Events.UserPermissionsChangedEvent;

namespace SS3D.Systems.Permissions
namespace SS3D.Permissions
{
public class DisableIfNotAdmin : NetworkActor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using Coimbra.Services.Events;
using Coimbra.Services.Events;
using System.Collections.Generic;

namespace SS3D.Systems.Permissions.Events
namespace SS3D.Permissions.Events
{
public partial struct UserPermissionsChangedEvent : IEvent
{
Expand Down
20 changes: 20 additions & 0 deletions Assets/Scripts/SS3D/Permissions/PermissionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Coimbra;
using UnityEngine;

namespace SS3D.Permissions
{
/// <summary>
/// This settings has general options for the permission system, so if we add a database/SQL/API support we can set stuff here.
/// </summary>
[ProjectSettings("SS3D/Server")]
public class PermissionSettings : ScriptableSettings
stilnat marked this conversation as resolved.
Show resolved Hide resolved
{
[SerializeField]
private bool _addServerOwnerPermissionToServerHost;

/// <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;
}
}
3 changes: 3 additions & 0 deletions Assets/Scripts/SS3D/Permissions/PermissionSettings.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using FishNet.Object;
using FishNet.Object;
using FishNet.Object.Synchronizing;
using SS3D.Core.Behaviours;
using SS3D.Data;
using SS3D.Logging;
using SS3D.Systems.Permissions.Events;
using SS3D.Permissions.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using File = System.IO.File;
using UserPermissionsChangedEvent = SS3D.Permissions.Events.UserPermissionsChangedEvent;

namespace SS3D.Systems.Permissions
namespace SS3D.Permissions
{
/// <summary>
/// Handles user permission on what he can do and can't.
Expand Down Expand Up @@ -87,15 +88,33 @@ public bool TryGetUserRole(string ckey, out ServerRoleTypes userPermission)
/// <summary>
/// Updates a user permission.
/// </summary>
/// <param name="ckey">The desired user to update the permission.</param>
/// <param name="ckey">The desired user to update the permission.</param>|
/// <param name="role">The new user role.</param>
[Server]
public void ChangeUserPermission(string ckey, ServerRoleTypes role)
{
throw new NotImplementedException();
// TODO: This
// Add new user permission to list
// Add new user permission to text file
ServerRoleTypes previousRole = _userPermissions.TryGetValue(ckey, out ServerRoleTypes permission) ? permission : ServerRoleTypes.None;

Log.Information(this, $"Updating user {ckey} role from {previousRole} to {role}");

_userPermissions[ckey] = role;

SaveUserPermissions();
}

/// <summary>
/// Saves the permissions text file with the updated permissions list.
/// </summary>
public void SaveUserPermissions()
{
stilnat marked this conversation as resolved.
Show resolved Hide resolved
string fileContent = string.Empty;

foreach (KeyValuePair<string,ServerRoleTypes> userPermission in _userPermissions)
{
fileContent += $"{userPermission.Key} {userPermission.Value.ToString()}\n";
}

File.WriteAllText(PermissionsPath, fileContent);
}

/// <summary>
Expand Down Expand Up @@ -164,6 +183,12 @@ private void SyncHandleUserPermissionsChanged(SyncDictionaryOperation op, string
SyncUserPermissions();
}

/// <summary>
/// Returns if the user is at least at a level of access.
/// </summary>
/// <param name="ckey">The user to check permission for</param>
/// <param name="permissionLevelCheck">The lowest required permission to perform the action.</param>
/// <returns></returns>
public bool IsAtLeast(string ckey, ServerRoleTypes permissionLevelCheck)
{
TryGetUserRole(ckey, out ServerRoleTypes userPermission);
Expand Down
22 changes: 22 additions & 0 deletions Assets/Scripts/SS3D/Permissions/SS3D.Permissions.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "SS3D.Permissions",
"rootNamespace": "",
"references": [
"GUID:7c88a4a7926ee5145ad2dfa06f454c67",
"GUID:eb124556ba20d60469be9771eb1f0360",
"GUID:eb242eaf9f292954eb8c6fbd63c46deb",
"GUID:6e00473804df0f0468c07310fbce5737",
"GUID:6aabbee860c32c64d9bbd52d0704ed2c",
"GUID:d2bbca7254de5e746857b04cfb560876",
"GUID:b763ff73a93a62c4ea128e32ed2cd0d6"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Assets/Scripts/SS3D/Permissions/SS3D.Permissions.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SS3D.Systems.Permissions
namespace SS3D.Permissions
{
public enum ServerRoleTypes
{
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/SS3D/Systems/Health/BodyParts/Bodypart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FishNet.Object;
using Coimbra;
using FishNet.Object;
using FishNet.Object.Synchronizing;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -9,7 +10,6 @@
using System.Linq;
using System.Collections.ObjectModel;
using FishNet;
using Coimbra;
using SS3D.Systems.Inventory.Containers;
using SS3D.Systems.Inventory.Items;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using SS3D.Core;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using UnityEngine;
using FishNet;
using SS3D.Data;
using SS3D.Data.Enums;
using FishNet.Object;
using SS3D.Systems.Inventory.Containers;
using FishNet.Connection;
using SS3D.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using FishNet.Connection;
using SS3D.Core;
using SS3D.Systems.Permissions;
using SS3D.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FishNet.Connection;
using SS3D.Systems.Permissions;
using SS3D.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Core;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using System;
using System.Collections;
using SS3D.Permissions;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using static UnityEngine.EventSystems.EventTrigger;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
using FishNet.Connection;
using FishNet;
using SS3D.Core;
using SS3D.Data.Enums;
using SS3D.Data;
using SS3D.Systems.Entities;
using SS3D.Permissions;
using SS3D.Systems.Inventory.Containers;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace SS3D.Systems.IngameConsoleSystem.Commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Linq;
using FishNet.Connection;
using SS3D.Systems.Permissions;
using SS3D.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Systems.Permissions;
using System.Collections;
using SS3D.Permissions;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Permissions;
using SS3D.Systems.Health;
using SS3D.Systems.Permissions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Core;
using SS3D.Permissions;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using SS3D.Systems.Inventory.Items;
using UnityEngine;
using SS3D.Systems.Permissions;
using FishNet.Object;
using FishNet.Connection;
using SS3D.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FishNet.Connection;
using SS3D.Permissions;
using SS3D.Systems.Inventory.Items;
using SS3D.Systems.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
namespace SS3D.Systems.IngameConsoleSystem.Commands.ItemCommands
{
/// <summary>
/// Command to describe an item held in the active hand of the player calling the command.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using FishNet.Connection;
using SS3D.Permissions;
using SS3D.Systems.Inventory.Items;
using SS3D.Systems.Permissions;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
using SS3D.Core;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using SS3D.Systems;
using FishNet.Connection;
using SS3D.Core;
using SS3D.Data;
using SS3D.Data.AssetDatabases;
using SS3D.Data.Enums;
using SS3D.Permissions;
using SS3D.Systems.Entities;
using SS3D.Systems.Inventory.Items;
using SS3D.Utils;
using SS3D.Core.Settings;
using UnityEngine;
using UnityEngine.UIElements;
using FishNet.Managing.Server;
using FishNet;
using FishNet.Connection;
using UnityEngine.InputSystem;

namespace SS3D.Systems.IngameConsoleSystem.Commands
namespace SS3D.Systems.IngameConsoleSystem.Commands.ItemCommands
{
public class SpawnItemCommand : Command
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Core;
using SS3D.Permissions;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using SS3D.Systems.Health;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Linq;
using FishNet.Connection;
using SS3D.Core;
using SS3D.Permissions;
using SS3D.Systems.Entities;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;

namespace SS3D.Systems.IngameConsoleSystem.Commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FishNet.Connection;
using SS3D.Systems.Permissions;
using SS3D.Permissions;
using UnityEngine;

namespace SS3D.Systems.IngameConsoleSystem.Commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using FishNet.Connection;
using FishNet.Object;
using SS3D.Core;
using SS3D.Permissions;
using SS3D.Systems.Entities;
using SS3D.Systems.Entities.Humanoid;
using SS3D.Systems.Permissions;
using SS3D.Systems.PlayerControl;
using System.Globalization;
using UnityEngine;

namespace SS3D.Systems.IngameConsoleSystem.Commands
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using FishNet.Connection;
using SS3D.Systems.Permissions;
using SS3D.Permissions;
using UnityEngine.Device;

namespace SS3D.Systems.IngameConsoleSystem.Commands
Expand Down
Loading
Loading