Added permission presets (or ranks). Current presets are none (no special permissions), moderator (round management & kicking) and admin (almost everything permitted).
This commit is contained in:
@@ -1,31 +1,10 @@
|
||||
using Lidgren.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
[Flags]
|
||||
enum ClientPermissions
|
||||
{
|
||||
None = 0,
|
||||
[Description("End round")]
|
||||
EndRound = 1,
|
||||
[Description("Kick")]
|
||||
Kick = 2,
|
||||
[Description("Ban")]
|
||||
Ban = 4,
|
||||
[Description("Select submarine")]
|
||||
SelectSub = 8,
|
||||
[Description("Select game mode")]
|
||||
SelectMode = 16,
|
||||
[Description("Manage campaign")]
|
||||
ManageCampaign = 32,
|
||||
[Description("Console commands")]
|
||||
ConsoleCommands = 64
|
||||
}
|
||||
|
||||
class Client
|
||||
{
|
||||
public string Name;
|
||||
@@ -81,7 +60,11 @@ namespace Barotrauma.Networking
|
||||
public float DeleteDisconnectedTimer;
|
||||
|
||||
public ClientPermissions Permissions = ClientPermissions.None;
|
||||
public List<DebugConsole.Command> PermittedConsoleCommands = new List<DebugConsole.Command>();
|
||||
public List<DebugConsole.Command> PermittedConsoleCommands
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
|
||||
public bool SpectateOnly;
|
||||
|
||||
@@ -116,6 +99,7 @@ namespace Barotrauma.Networking
|
||||
this.Name = name;
|
||||
this.ID = ID;
|
||||
|
||||
PermittedConsoleCommands = new List<DebugConsole.Command>();
|
||||
kickVoters = new List<Client>();
|
||||
|
||||
votes = new object[Enum.GetNames(typeof(VoteType)).Length];
|
||||
@@ -160,7 +144,7 @@ namespace Barotrauma.Networking
|
||||
public void SetPermissions(ClientPermissions permissions, List<DebugConsole.Command> permittedConsoleCommands)
|
||||
{
|
||||
this.Permissions = permissions;
|
||||
this.PermittedConsoleCommands = permittedConsoleCommands;
|
||||
this.PermittedConsoleCommands = new List<DebugConsole.Command>(permittedConsoleCommands);
|
||||
}
|
||||
|
||||
public void GivePermission(ClientPermissions permission)
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma.Networking
|
||||
{
|
||||
[Flags]
|
||||
enum ClientPermissions
|
||||
{
|
||||
None = 0,
|
||||
[Description("End round")]
|
||||
EndRound = 1,
|
||||
[Description("Kick")]
|
||||
Kick = 2,
|
||||
[Description("Ban")]
|
||||
Ban = 4,
|
||||
[Description("Select submarine")]
|
||||
SelectSub = 8,
|
||||
[Description("Select game mode")]
|
||||
SelectMode = 16,
|
||||
[Description("Manage campaign")]
|
||||
ManageCampaign = 32,
|
||||
[Description("Console commands")]
|
||||
ConsoleCommands = 64
|
||||
}
|
||||
|
||||
class PermissionPreset
|
||||
{
|
||||
public static List<PermissionPreset> List = new List<PermissionPreset>();
|
||||
|
||||
public readonly string Name;
|
||||
public readonly string Description;
|
||||
public readonly ClientPermissions Permissions;
|
||||
public readonly List<DebugConsole.Command> PermittedCommands;
|
||||
|
||||
public PermissionPreset(XElement element)
|
||||
{
|
||||
Name = element.GetAttributeString("name", "");
|
||||
Description = element.GetAttributeString("description", "");
|
||||
|
||||
string permissionsStr = element.GetAttributeString("permissions", "");
|
||||
if (!Enum.TryParse(permissionsStr, out Permissions))
|
||||
{
|
||||
DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + permissionsStr + " is not a valid permission!");
|
||||
}
|
||||
|
||||
PermittedCommands = new List<DebugConsole.Command>();
|
||||
if (Permissions.HasFlag(ClientPermissions.ConsoleCommands))
|
||||
{
|
||||
foreach (XElement subElement in element.Elements())
|
||||
{
|
||||
if (subElement.Name.ToString().ToLowerInvariant() != "command") continue;
|
||||
string commandName = subElement.GetAttributeString("name", "");
|
||||
|
||||
DebugConsole.Command command = DebugConsole.FindCommand(commandName);
|
||||
if (command == null)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in permission preset \"" + Name + "\" - " + commandName + "\" is not a valid console command.");
|
||||
continue;
|
||||
}
|
||||
|
||||
PermittedCommands.Add(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void LoadAll(string file)
|
||||
{
|
||||
if (!File.Exists(file)) return;
|
||||
|
||||
XDocument doc = XMLExtensions.TryLoadXml(file);
|
||||
if (doc == null || doc.Root == null) return;
|
||||
|
||||
foreach (XElement element in doc.Root.Elements())
|
||||
{
|
||||
List.Add(new PermissionPreset(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -125,8 +125,9 @@ namespace Barotrauma.Networking
|
||||
banList = new BanList();
|
||||
|
||||
LoadSettings();
|
||||
PermissionPreset.LoadAll(PermissionPresetFile);
|
||||
LoadClientPermissions();
|
||||
|
||||
|
||||
CoroutineManager.StartCoroutine(StartServer(isPublic));
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace Barotrauma.Networking
|
||||
}
|
||||
|
||||
public const string SettingsFile = "serversettings.xml";
|
||||
public static readonly string PermissionPresetFile = "Data" + Path.DirectorySeparatorChar + "permissionpresets.xml";
|
||||
public static readonly string ClientPermissionsFile = "Data" + Path.DirectorySeparatorChar + "clientpermissions.xml";
|
||||
|
||||
public Dictionary<string, SerializableProperty> SerializableProperties
|
||||
|
||||
Reference in New Issue
Block a user