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

Added newVesselProtection and forcePublicSpaceObjects server settings #477

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
42 changes: 39 additions & 3 deletions Server/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -226,6 +226,7 @@ public void SetVesselOwnerIfUnowned(Guid guid, string owner)
if (!vesselPermissions.ContainsKey(guid))
{
SetVesselOwner(guid, owner);
SetVesselProtection(guid, Settings.settingsStore.newVesselProtection);
}
}
}
Expand Down Expand Up @@ -267,6 +268,7 @@ public void SetVesselProtection(Guid guid, VesselProtectionType protection)
{
return;
}

vesselPermissions[guid].protection = protection;
SaveVesselPermissions(guid);
}
Expand All @@ -292,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;
Expand All @@ -316,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;
}
}
}
4 changes: 4 additions & 0 deletions Server/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}