Skip to content

Commit

Permalink
Add bool to toggle set owner permission on server host
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoburatto committed Sep 30, 2023
1 parent fbd13b6 commit 92645ed
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Assets/Scripts/SS3D/Permissions/PermissionSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Coimbra;
using UnityEngine;

namespace SS3D.Permissions
{
[ProjectSettings("SS3D/Server")]
public class PermissionSettings : ScriptableSettings
{
[SerializeField]
private bool _addServerOwnerPermissionToServerHost;

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.

22 changes: 18 additions & 4 deletions Assets/Scripts/SS3D/Permissions/PermissionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,25 @@ public bool TryGetUserRole(string ckey, out ServerRoleTypes userPermission)
[Server]
public void ChangeUserPermission(string ckey, ServerRoleTypes role)
{
ServerRoleTypes previousRole = _userPermissions.TryGetValue(ckey, out ServerRoleTypes permission) ? permission : ServerRoleTypes.None;

throw new NotImplementedException();
// TODO: This
// Add new user permission to list
// Add new user permission to text file
Punpun.Information(this, $"Updating user {ckey} role from {previousRole} to {role}");

_userPermissions[ckey] = role;

SaveUserPermissions();
}

public void SaveUserPermissions()
{
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
5 changes: 4 additions & 1 deletion Assets/Scripts/SS3D/Systems/PlayerControl/PlayerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Coimbra;
using System.Collections.Generic;
using System.Linq;
using FishNet.Connection;
Expand Down Expand Up @@ -176,8 +177,10 @@ private void ProcessAuthorizePlayer(NetworkConnection conn, UserAuthorizationMes

player.SetCkey(ckey);

if (player.NetworkObject.Owner.IsHost)
if (conn.IsHost && PermissionSettings.AddServerOwnerPermissionToServerHost)
{
Punpun.Information(this, $"Adding ServerOwner permission to server owner: {ckey}", Logs.ServerOnly, ckey);

Subsystems.Get<PermissionSystem>().ChangeUserPermission(ckey, ServerRoleTypes.ServerOwner);
}

Expand Down
17 changes: 17 additions & 0 deletions Assets/Settings/ServerRoleSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f321f4b30171436abd45f5ecf17afa03, type: 3}
m_Name: ServerRoleSettings
m_EditorClassIdentifier:
_preload: 1
_type: 2
_addServerOwnerPermissionToServerHost: 1
8 changes: 8 additions & 0 deletions Assets/Settings/ServerRoleSettings.asset.meta

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

1 change: 1 addition & 0 deletions ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ PlayerSettings:
- {fileID: 11400000, guid: 3c59f55e6898e694083e7a1ede49fe18, type: 2}
- {fileID: 11400000, guid: 2024dd0c65f45424f98ac0c8a6979181, type: 2}
- {fileID: 11400000, guid: 97967903e9bd51b499aaa39639cc9bb2, type: 2}
- {fileID: 11400000, guid: c15209f668bbfab479eb5184981c2bf7, type: 2}
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
Expand Down

0 comments on commit 92645ed

Please sign in to comment.