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:
@@ -739,6 +739,9 @@
|
||||
<Content Include="$(MSBuildThisFileDirectory)Data\ContentPackages\Vanilla 0.7.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="$(MSBuildThisFileDirectory)Data\permissionpresets.xml">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="$(MSBuildThisFileDirectory)Icon.ico" />
|
||||
<Content Include="$(MSBuildThisFileDirectory)Mods\info.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
@@ -1479,6 +1482,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\BanList.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\ChatMessage.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\Client.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\ClientPermissions.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\EntitySpawner.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\FileTransfer\FileSender.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Source\Networking\GameServer.cs" />
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<PermissionPresets>
|
||||
<Preset
|
||||
name="None"
|
||||
description="No special privileges."
|
||||
permissions="None"/>
|
||||
|
||||
<Preset
|
||||
name="Moderator"
|
||||
description="Allowed to manage round settings and kick players."
|
||||
permissions="EndRound,Kick,SelectSub,SelectMode,ManageCampaign,ConsoleCommands">
|
||||
<Command name="clientlist"/>
|
||||
<Command name="autorestart"/>
|
||||
<Command name="autorestartinterval"/>
|
||||
<Command name="autorestarttimer"/>
|
||||
<Command name="kick"/>
|
||||
<Command name="kickid"/>
|
||||
<Command name="campaigninfo"/>
|
||||
<Command name="campaigndestination"/>
|
||||
</Preset>
|
||||
|
||||
<Preset
|
||||
name="Admin"
|
||||
description="Allowed to ban and kick players, manage round settings and use nearly all console commands."
|
||||
permissions="EndRound,Kick,Ban,SelectSub,SelectMode,ManageCampaign,ConsoleCommands">
|
||||
<Command name="clientlist"/>
|
||||
<Command name="autorestart"/>
|
||||
<Command name="autorestartinterval"/>
|
||||
<Command name="autorestarttimer"/>
|
||||
<Command name="kick"/>
|
||||
<Command name="kickid"/>
|
||||
<Command name="campaigninfo"/>
|
||||
<Command name="campaigndestination"/>
|
||||
<Command name="spawn"/>
|
||||
<Command name="spawnitem"/>
|
||||
<Command name="disablecrewai"/>
|
||||
<Command name="enablecrewai"/>
|
||||
<Command name="ban"/>
|
||||
<Command name="banid"/>
|
||||
<Command name="banip"/>
|
||||
<Command name="teleportcharacter"/>
|
||||
<Command name="godmode"/>
|
||||
<Command name="lockx"/>
|
||||
<Command name="locky"/>
|
||||
<Command name="heal"/>
|
||||
<Command name="revive"/>
|
||||
<Command name="freeze"/>
|
||||
<Command name="freecam"/>
|
||||
<Command name="explosion"/>
|
||||
<Command name="fixitems"/>
|
||||
<Command name="fixhulls"/>
|
||||
<Command name="power"/>
|
||||
<Command name="oxygen"/>
|
||||
<Command name="setclientcharacter"/>
|
||||
</Preset>
|
||||
</PermissionPresets>
|
||||
@@ -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