From a9f9a1c5166d6dd376606ba6ee62c31be89af033 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Mon, 27 Jul 2020 21:49:14 +0800 Subject: [PATCH 1/2] Added newVesselProtection and forcePublicSpaceObjects server settings --- Server/Permissions.cs | 34 ++++++++++++++++++++++++++++++++++ Server/Settings.cs | 4 ++++ 2 files changed, 38 insertions(+) diff --git a/Server/Permissions.cs b/Server/Permissions.cs index d57931ac..2b8eb524 100644 --- a/Server/Permissions.cs +++ b/Server/Permissions.cs @@ -226,6 +226,7 @@ public void SetVesselOwnerIfUnowned(Guid guid, string owner) if (!vesselPermissions.ContainsKey(guid)) { SetVesselOwner(guid, owner); + SetVesselProtection(guid, Settings.settingsStore.newVesselProtection); } } } @@ -267,11 +268,44 @@ public void SetVesselProtection(Guid guid, VesselProtectionType protection) { return; } + else if (Settings.settingsStore.forcePublicSpaceObjects && GetSavedValue(guid, "name") == "SpaceObject") + { + return; + } vesselPermissions[guid].protection = protection; SaveVesselPermissions(guid); } } + //I could not find any functions that allowed me to extract saved vessel data, so I have made one here. + public string GetSavedValue(Guid guid, string VesselValue) + { + string findvalue = VesselValue + " ="; + string FinalVesselValue = "nil"; + bool foundvar = false; + string VesselFile = Path.Combine(Server.universeDirectory, "Vessels", guid.ToString() + ".txt"); + + if (File.Exists(VesselFile)) + { + using (StreamReader sr = new StreamReader(VesselFile)) + { + string currentLine = sr.ReadLine(); + while (currentLine != null && !foundvar) + { + string trimmedLine = currentLine.Trim(); + if (trimmedLine.Trim().StartsWith(findvalue, StringComparison.Ordinal)) + { + FinalVesselValue = trimmedLine.Substring(trimmedLine.IndexOf("=", StringComparison.Ordinal) + 2); + foundvar = true; + } + currentLine = sr.ReadLine(); + } + } + } + + return FinalVesselValue; + } + public void DeleteVessel(Guid guid) { lock (vesselPermissions) diff --git a/Server/Settings.cs b/Server/Settings.cs index 4e60a8bb..04b1df5e 100644 --- a/Server/Settings.cs +++ b/Server/Settings.cs @@ -96,5 +96,9 @@ public class SettingsStore public double expireLogs = 0; [Description("Specify the minimum distance in which vessels can interact with eachother at the launch pad and runway")] public float safetyBubbleDistance = 100.0f; + [Description("Specify which protection mode to set new vessels to.")] + public VesselProtectionType newVesselProtection = VesselProtectionType.PUBLIC; + [Description("Specify whether to force Space Objects (asteroids and comets) to be public.")] + public bool forcePublicSpaceObjects = false; } } \ No newline at end of file From f2c7ba92202a219590448e1aefbb08103f040ba1 Mon Sep 17 00:00:00 2001 From: FrostBird347 <39435218+FrostBird347@users.noreply.github.com> Date: Mon, 27 Jul 2020 22:29:06 +0800 Subject: [PATCH 2/2] Fixed forcePublicSpaceObjects --- Server/Permissions.cs | 74 ++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/Server/Permissions.cs b/Server/Permissions.cs index 2b8eb524..362e92ce 100644 --- a/Server/Permissions.cs +++ b/Server/Permissions.cs @@ -136,7 +136,7 @@ private void Clean() { string vesselFileName = Path.GetFileName(file); string vesselFileNameWE = Path.GetFileNameWithoutExtension(file); - if (!File.Exists(Path.Combine(vesselProtoPath, vesselFileName))) + if (!File.Exists(Path.Combine(vesselProtoPath, vesselFileName))) { DarkLog.Debug("Deleting permissions for unknown vessel: " + vesselFileNameWE); File.Delete(file); @@ -268,44 +268,12 @@ public void SetVesselProtection(Guid guid, VesselProtectionType protection) { return; } - else if (Settings.settingsStore.forcePublicSpaceObjects && GetSavedValue(guid, "name") == "SpaceObject") - { - return; - } + vesselPermissions[guid].protection = protection; SaveVesselPermissions(guid); } } - //I could not find any functions that allowed me to extract saved vessel data, so I have made one here. - public string GetSavedValue(Guid guid, string VesselValue) - { - string findvalue = VesselValue + " ="; - string FinalVesselValue = "nil"; - bool foundvar = false; - string VesselFile = Path.Combine(Server.universeDirectory, "Vessels", guid.ToString() + ".txt"); - - if (File.Exists(VesselFile)) - { - using (StreamReader sr = new StreamReader(VesselFile)) - { - string currentLine = sr.ReadLine(); - while (currentLine != null && !foundvar) - { - string trimmedLine = currentLine.Trim(); - if (trimmedLine.Trim().StartsWith(findvalue, StringComparison.Ordinal)) - { - FinalVesselValue = trimmedLine.Substring(trimmedLine.IndexOf("=", StringComparison.Ordinal) + 2); - foundvar = true; - } - currentLine = sr.ReadLine(); - } - } - } - - return FinalVesselValue; - } - public void DeleteVessel(Guid guid) { lock (vesselPermissions) @@ -326,10 +294,16 @@ public bool PlayerIsVesselOwner(string playerName, Guid vesselID) } } - public bool PlayerHasVesselPermission(string playerName, Guid vesselID) + public bool PlayerHasVesselPermission(string playerName, Guid vesselID) { + lock (vesselPermissions) { + if (Settings.settingsStore.forcePublicSpaceObjects && vesselPermissions[vesselID].protection != VesselProtectionType.PUBLIC && GetSavedValue(vesselID, "type") == "SpaceObject") + { + SetVesselProtection(vesselID, VesselProtectionType.PUBLIC); + } + if (!vesselPermissions.ContainsKey(vesselID)) { return true; @@ -350,8 +324,36 @@ public bool PlayerHasVesselPermission(string playerName, Guid vesselID) return true; } } - } + } return false; } + + //I could not find any functions that allowed me to extract saved vessel data, so I have made one here. + public string GetSavedValue(Guid guid, string VesselValue) + { + string findvalue = VesselValue + " ="; + string FinalVesselValue = "nil"; + bool foundvar = false; + string VesselFile = Path.Combine(Server.universeDirectory, "Vessels", guid.ToString() + ".txt"); + + if (File.Exists(VesselFile)) + { + using (StreamReader sr = new StreamReader(VesselFile)) + { + string currentLine = sr.ReadLine(); + while (currentLine != null && !foundvar) + { + string trimmedLine = currentLine.Trim(); + if (trimmedLine.Trim().StartsWith(findvalue, StringComparison.Ordinal)) + { + FinalVesselValue = trimmedLine.Substring(trimmedLine.IndexOf("=", StringComparison.Ordinal) + 2); + foundvar = true; + } + currentLine = sr.ReadLine(); + } + } + } + return FinalVesselValue; + } } }