Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit 2dc710d

Browse files
committed
Initial commit.
1 parent 4740a69 commit 2dc710d

File tree

9 files changed

+527
-0
lines changed

9 files changed

+527
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//40
2+
//
3+
// This code was generated by a tool. Any changes made manually will be lost
4+
// the next time this code is regenerated.
5+
//
6+
7+
using System.Reflection;
8+
9+
[assembly: AssemblyFileVersion("1.0.0.40")]
10+
[assembly: AssemblyVersion("1.0.0.40")]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<#@ template language="C#" hostSpecific="True"#>
2+
<#@ output extension="cs" #>
3+
<#@ import namespace="System.IO" #>
4+
<#
5+
int revisionNumber;
6+
try
7+
{
8+
//If we cannot find the file, the revision number is set to zero,
9+
//so even if the file doesn't exists the generation will run anyway.
10+
//NOTE: we suppose we're not messing with the generated file
11+
using(var f = File.OpenText(Host.ResolvePath("AssemblyFileVersion.cs")))
12+
{
13+
//We're reading the previous revision number; in order to make the
14+
//code as simple as we can, we're just going to rewrite it on the first row, commented.
15+
//This is not elegant, but it's simple enough and quite effective.
16+
string s = f.ReadLine().Replace("//","");
17+
revisionNumber = int.Parse(s) + 1;
18+
}
19+
}catch
20+
{
21+
revisionNumber = 0;
22+
}
23+
#>
24+
//<#=revisionNumber#>
25+
//
26+
// This code was generated by a tool. Any changes made manually will be lost
27+
// the next time this code is regenerated.
28+
//
29+
30+
using System.Reflection;
31+
32+
[assembly: AssemblyFileVersion("1.0.0.<#= revisionNumber #>")]
33+
[assembly: AssemblyVersion("1.0.0.<#= revisionNumber #>")]
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
namespace GetOutOfMySandbox
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Runtime.InteropServices;
10+
using System.Threading;
11+
using System.Xml.Linq;
12+
using System.Xml.XPath;
13+
using NLog;
14+
using SEModAPIExtensions.API;
15+
using SEModAPIExtensions.API.Plugin;
16+
using SEModAPIInternal.API.Common;
17+
18+
public class GetOutOfMySandbox : IPlugin
19+
{
20+
public static Logger Log;
21+
private static GetOutOfMySandbox _instance;
22+
private Thread _pluginThread;
23+
private bool _running;
24+
private static readonly object Locker = new object( );
25+
26+
public void Init( )
27+
{
28+
string directoryName = Path.GetDirectoryName( Assembly.GetExecutingAssembly( ).Location );
29+
Log.Info( "Initializing GetOutOfMySandbox plugin at path {0}", directoryName );
30+
DoInit( directoryName );
31+
}
32+
33+
public void InitWithPath( String modPath )
34+
{
35+
string directoryName = Path.GetDirectoryName( modPath ) + "\\";
36+
Log.Info( "Initializing GetOutOfMySandbox plugin at path {0}", directoryName );
37+
DoInit( directoryName );
38+
}
39+
40+
private void DoInit( string path )
41+
{
42+
_instance = new GetOutOfMySandbox( );
43+
PluginPath = path;
44+
PluginSettings.Instance.Load( );
45+
_running = true;
46+
_pluginThread = new Thread( WaitLoop );
47+
_pluginThread.Start( );
48+
}
49+
50+
private void WaitLoop( )
51+
{
52+
WorldManager.Instance.WorldSaved += Instance_WorldSaved;
53+
lock ( Locker )
54+
{
55+
while ( _running )
56+
{
57+
Monitor.Wait( Locker );
58+
}
59+
}
60+
WorldManager.Instance.WorldSaved -= Instance_WorldSaved;
61+
PluginSettings.Instance.Save( );
62+
Log.Info( "GetOutOfMySandbox {0} has shut down.", Version );
63+
}
64+
65+
void Instance_WorldSaved( )
66+
{
67+
Log.Info( "Processing post-save cleanup events." );
68+
69+
try
70+
{
71+
string sandboxPath = Path.Combine( Server.Instance.Config.LoadWorld, "Sandbox.sbc" );
72+
XDocument sandboxSbc = XDocument.Load( sandboxPath );
73+
XDocument sectorFile = XDocument.Load( Path.Combine( Server.Instance.Config.LoadWorld, "SANDBOX_0_0_0_.sbs" ) );
74+
IEnumerable<XElement> allIdentities = sandboxSbc.XPathSelectElements( "/MyObjectBuilder_Checkpoint/Identities/MyObjectBuilder_Identity/IdentityId" );
75+
IEnumerable<XElement> cubeBlockOwners = sectorFile.XPathSelectElements( "/MyObjectBuilder_Sector/SectorObjects/MyObjectBuilder_EntityBase/CubeBlocks/MyObjectBuilder_CubeBlock/Owner" );
76+
IEnumerable<XElement> factionMembers = sandboxSbc.XPathSelectElements( "/MyObjectBuilder_Checkpoint/Factions/Factions/MyObjectBuilder_Faction/Members/MyObjectBuilder_FactionMember/PlayerId" );
77+
78+
List<string> idsToRemove = new List<string>( allIdentities.Select( o => o.Value ).Distinct( ).ToArray( ) );
79+
80+
string[ ] cubeBlockOwnerIds = cubeBlockOwners.Select( o => o.Value ).Distinct( ).ToArray( );
81+
idsToRemove.RemoveAll( o => cubeBlockOwnerIds.Contains( o ) );
82+
83+
if ( !PluginSettings.Instance.IgnoreFactionMembership )
84+
{
85+
string[ ] factionMemberIds = factionMembers.Select( f => f.Value ).Distinct( ).ToArray( );
86+
idsToRemove.RemoveAll( o => factionMemberIds.Contains( o ) );
87+
}
88+
89+
foreach ( string i in idsToRemove )
90+
{
91+
Log.Info( "Removing identity {0}", i );
92+
//Remove toolbar settings, etc
93+
XElement settingsElement = sandboxSbc.XPathSelectElement( string.Format( "/MyObjectBuilder_Checkpoint/AllPlayersData/dictionary/item[Value/IdentityId='{0}']", i ) );
94+
if ( settingsElement != null )
95+
{
96+
settingsElement.Remove( );
97+
}
98+
99+
//Remove from factions
100+
sandboxSbc.XPathSelectElements( string.Format( "/MyObjectBuilder_Checkpoint/Factions/Factions/MyObjectBuilder_Faction/Members/MyObjectBuilder_FactionMember[PlayerId='{0}']", i ) ).Remove( );
101+
//Remove chat history
102+
//XElement chatHistoryElement = sandboxSbc.XPathSelectElement( string.Format( "/MyObjectBuilder_Checkpoint/ChatHistory/MyObjectBuilder_ChatHistory/PlayerChatHistory/MyObjectBuilder_PlayerChatHistory[ID='{0}']", i ) );
103+
//chatHistoryElement.Remove( );
104+
//sandboxSbc.XPathSelectElement( string.Format( "/MyObjectBuilder_Checkpoint/ChatHistory/MyObjectBuilder_ChatHistory/[IdentityId='{0}']", i ) ).Remove( );
105+
//Remove GPS entries
106+
sandboxSbc.XPathSelectElements( string.Format( "/MyObjectBuilder_Checkpoint/Gps/dictionary/item[Key='{0}']", i ) ).Remove( );
107+
//Remove the identity
108+
sandboxSbc.XPathSelectElement( string.Format( "/MyObjectBuilder_Checkpoint/Identities/MyObjectBuilder_Identity[IdentityId='{0}']", i ) ).Remove( );
109+
}
110+
111+
sandboxSbc.Save( sandboxPath );
112+
}
113+
catch ( FileNotFoundException ex )
114+
{
115+
Log.Error( ex );
116+
}
117+
catch ( Exception ex )
118+
{
119+
Log.Error( ex );
120+
}
121+
122+
Log.Info( "Finished processing post-save cleanup events." );
123+
}
124+
125+
public void Update( )
126+
{
127+
128+
}
129+
130+
public void Shutdown( )
131+
{
132+
Log.Info( "Shutting down GetOutOfMySandbox - {0}", Version );
133+
lock ( Locker )
134+
{
135+
_running = false;
136+
Monitor.Pulse( Locker );
137+
}
138+
}
139+
140+
/// <summary>Singleton instance of the core <see cref="GetOutOfMySandbox"/> plugin class.</summary>
141+
internal static GetOutOfMySandbox Instance
142+
{
143+
get { return _instance ?? ( _instance = new GetOutOfMySandbox( ) ); }
144+
}
145+
146+
public Guid Id
147+
{
148+
get
149+
{
150+
GuidAttribute guidAttr = (GuidAttribute)typeof( GetOutOfMySandbox ).Assembly.GetCustomAttributes( typeof( GuidAttribute ), true )[ 0 ];
151+
return new Guid( guidAttr.Value );
152+
}
153+
}
154+
155+
public string Name { get { return "Get Out Of My Sandbox!"; } }
156+
157+
public Version Version { get { return typeof( GetOutOfMySandbox ).Assembly.GetName( ).Version; } }
158+
159+
public static string PluginPath { get; set; }
160+
161+
[Category( "Behavior" )]
162+
[Description( "Delete identities even if they belong to a faction." )]
163+
[Browsable( true )]
164+
[ReadOnly( false )]
165+
[DisplayName( "Ignore Faction Membership" )]
166+
public bool IgnoreFactionMembership
167+
{
168+
get
169+
{
170+
return PluginSettings.Instance.IgnoreFactionMembership;
171+
}
172+
173+
set
174+
{
175+
PluginSettings.Instance.IgnoreFactionMembership = value;
176+
}
177+
}
178+
179+
}
180+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{1797A95B-A8C1-4CD2-9E7A-0B579493A872}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>GetOutOfMySandbox</RootNamespace>
11+
<AssemblyName>GetOutOfMySandbox</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
<PlatformTarget>x64</PlatformTarget>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
<PlatformTarget>x64</PlatformTarget>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="NLog">
36+
<HintPath>packages\NLog.3.2.0.0\lib\net40\NLog.dll</HintPath>
37+
</Reference>
38+
<Reference Include="Sandbox.Common">
39+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\Sandbox.Common.dll</HintPath>
40+
</Reference>
41+
<Reference Include="Sandbox.Common.XmlSerializers">
42+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\Sandbox.Common.XmlSerializers.dll</HintPath>
43+
</Reference>
44+
<Reference Include="Sandbox.Game">
45+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\Sandbox.Game.dll</HintPath>
46+
</Reference>
47+
<Reference Include="SEModAPI">
48+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\SEModAPI.dll</HintPath>
49+
</Reference>
50+
<Reference Include="SEModAPIExtensions">
51+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\SEModAPIExtensions.dll</HintPath>
52+
</Reference>
53+
<Reference Include="SEModAPIInternal">
54+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\SEModAPIInternal.dll</HintPath>
55+
</Reference>
56+
<Reference Include="System" />
57+
<Reference Include="System.Core" />
58+
<Reference Include="System.Drawing" />
59+
<Reference Include="System.Runtime.Serialization" />
60+
<Reference Include="System.Windows.Forms" />
61+
<Reference Include="System.Xml.Linq" />
62+
<Reference Include="System.Data.DataSetExtensions" />
63+
<Reference Include="Microsoft.CSharp" />
64+
<Reference Include="System.Data" />
65+
<Reference Include="System.Xml" />
66+
<Reference Include="VRage">
67+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.dll</HintPath>
68+
</Reference>
69+
<Reference Include="VRage.Data">
70+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.Data.dll</HintPath>
71+
</Reference>
72+
<Reference Include="VRage.Input">
73+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.Input.dll</HintPath>
74+
</Reference>
75+
<Reference Include="VRage.Library">
76+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.Library.dll</HintPath>
77+
</Reference>
78+
<Reference Include="VRage.Math">
79+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.Math.dll</HintPath>
80+
</Reference>
81+
<Reference Include="VRage.Native">
82+
<HintPath>..\..\SEServerExtender\SEServerExtender\bin\x64\Release\VRage.Native.dll</HintPath>
83+
</Reference>
84+
</ItemGroup>
85+
<ItemGroup>
86+
<Compile Include="AssemblyFileVersion.cs">
87+
<AutoGen>True</AutoGen>
88+
<DesignTime>True</DesignTime>
89+
<DependentUpon>AssemblyFileVersion.tt</DependentUpon>
90+
</Compile>
91+
<Compile Include="GetOutOfMySandbox.cs" />
92+
<Compile Include="PluginSettings.cs" />
93+
<Compile Include="Properties\AssemblyInfo.cs" />
94+
</ItemGroup>
95+
<ItemGroup>
96+
<None Include="AssemblyFileVersion.tt">
97+
<Generator>TextTemplatingFileGenerator</Generator>
98+
<LastGenOutput>AssemblyFileVersion.cs</LastGenOutput>
99+
</None>
100+
<None Include="packages.config" />
101+
<None Include="README.md" />
102+
</ItemGroup>
103+
<ItemGroup>
104+
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
105+
</ItemGroup>
106+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
107+
<PropertyGroup>
108+
<PreBuildEvent>copy "$(TargetPath)" "C:\ProgramData\SpaceEngineersDedicated\survival test\Mods\Essentials\"
109+
set textTemplatingPath="%25CommonProgramFiles(x86)%25\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
110+
if %25textTemplatingPath%25=="\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe" set textTemplatingPath="%25CommonProgramFiles%25\Microsoft Shared\TextTemplating\$(VisualStudioVersion)\texttransform.exe"
111+
%25textTemplatingPath%25 "$(ProjectDir)AssemblyFileVersion.tt"</PreBuildEvent>
112+
</PropertyGroup>
113+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
114+
Other similar extension points exist, see Microsoft.Common.targets.
115+
<Target Name="BeforeBuild">
116+
</Target>
117+
<Target Name="AfterBuild">
118+
</Target>
119+
-->
120+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetOutOfMySandbox", "GetOutOfMySandbox.csproj", "{1797A95B-A8C1-4CD2-9E7A-0B579493A872}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1797A95B-A8C1-4CD2-9E7A-0B579493A872}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{1797A95B-A8C1-4CD2-9E7A-0B579493A872}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{1797A95B-A8C1-4CD2-9E7A-0B579493A872}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{1797A95B-A8C1-4CD2-9E7A-0B579493A872}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

0 commit comments

Comments
 (0)