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

Commit 268fb6f

Browse files
committed
Fix protection, enable faction selector, merge dev branch into master.
1 parent 6fc715f commit 268fb6f

24 files changed

+425
-180
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//196
1+
//237
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.7.196")]
10-
[assembly: AssemblyVersion("1.13.7.196")]
9+
[assembly: AssemblyFileVersion("1.13.7.237")]
10+
[assembly: AssemblyVersion("1.13.7.237")]

EssentialsPlugin/Editors/GridPicker.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace EssentialsPlugin.Editors
22
{
33
using System;
4+
using System.Collections.Generic;
45
using System.Linq;
56
using System.Windows.Forms;
67
using Sandbox.Game.Entities;
@@ -9,7 +10,6 @@
910
public partial class GridPicker : Form
1011
{
1112
public long SelectedEntity;
12-
private MyEntity[] _grids;
1313
public GridPicker()
1414
{
1515
InitializeComponent();
@@ -18,14 +18,22 @@ public GridPicker()
1818
private void GridPicker_Load(object sender, EventArgs e)
1919
{
2020
LST_Entities.DoubleClick += LST_Entities_DoubleClick;
21-
_grids = MyEntities.GetEntities().Where( x => x is MyCubeGrid ).ToArray();
22-
foreach ( var grid in _grids )
23-
LST_Entities.Items.Add( $"{grid.DisplayName??""}:{grid.EntityId}" );
21+
List<GridListItem> grids = new List<GridListItem>();
22+
foreach (var entity in MyEntities.GetEntities( ))
23+
{
24+
if(entity is MyCubeGrid && !entity.Closed && entity.Physics!=null)
25+
grids.Add( new GridListItem( (MyCubeGrid)entity ) );
26+
}
27+
28+
grids.Sort( (a,b) => string.Compare( a.ToString( ), b.ToString( ), StringComparison.Ordinal ) );
29+
30+
foreach ( var grid in grids )
31+
LST_Entities.Items.Add( grid );
2432
}
2533

2634
private void BTN_Ok_Click(object sender, EventArgs e)
2735
{
28-
SelectedEntity = _grids[LST_Entities.SelectedIndex].EntityId;
36+
SelectedEntity = ((GridListItem)LST_Entities.SelectedItem).Grid.EntityId;
2937
this.DialogResult = DialogResult.OK;
3038
this.Close();
3139
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace EssentialsPlugin.Editors
8+
{
9+
using Sandbox.Game.Entities;
10+
using Sandbox.Game.World;
11+
using VRage.Game.Entity;
12+
13+
public class GridListItem
14+
{
15+
public GridListItem( MyCubeGrid grid )
16+
{
17+
Grid = grid;
18+
}
19+
20+
public MyCubeGrid Grid;
21+
/// <summary>Returns a string that represents the current object.</summary>
22+
/// <returns>A string that represents the current object.</returns>
23+
public override string ToString( )
24+
{
25+
return $"{Grid.DisplayName ?? ""}: {Grid.EntityId}";
26+
}
27+
}
28+
29+
public class FactionListItem
30+
{
31+
public FactionListItem(MyFaction faction)
32+
{
33+
Faction = faction;
34+
}
35+
36+
public MyFaction Faction;
37+
38+
/// <summary>Returns a string that represents the current object.</summary>
39+
/// <returns>A string that represents the current object.</returns>
40+
public override string ToString( )
41+
{
42+
return $"{Faction.Tag??"ERROR"}: {Faction.Name??Faction.FactionId.ToString( )}";
43+
}
44+
}
45+
}

EssentialsPlugin/Editors/ProtectionEditor.Designer.cs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

EssentialsPlugin/Editors/ProtectionEditor.cs

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
namespace EssentialsPlugin.Editors
22
{
33
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
46
using System.Windows.Forms;
57
using Sandbox.Game.Entities;
68
using Sandbox.Game.World;
@@ -13,12 +15,12 @@ public ProtectionEditor()
1315
{
1416
InitializeComponent();
1517
}
16-
18+
1719
private readonly string[] _modeDesc = {
1820
"These players are allowed to add blocks to this grid.",
1921
"These players are allowed to remove blocks from this grid.",
2022
"These players are allowed to paint blocks on this grid.",
21-
"These players are allowed to change ownership of blocks on this grid.",
23+
"These players are allowed to change ownership of blocks.",
2224
"These players are allowed to rename blocks on this grid.",
2325
"These players are allowed to rename this grid.",
2426
"These players are allowed to convert this grid to a station.",
@@ -44,13 +46,28 @@ private void ProtectionEditor_Load(object sender, EventArgs e)
4446
"Grid Delete"
4547
} );
4648
//CMB_Mode.Items.AddRange( Enum.GetNames( typeof(ProtectedItem.ProtectionModeEnum) ) );
49+
List<FactionListItem> factions = new List<FactionListItem>();
4750
foreach ( var faction in MySession.Static.Factions )
4851
{
49-
LST_Factions.Items.Add( $"{faction.Value.Tag}: {faction.Value.Name}" );
52+
if (faction.Value == null)
53+
continue;
54+
factions.Add( new FactionListItem( faction.Value ) );
5055
}
5156

52-
LST_Entries.SelectedIndex = 0;
53-
CMB_Mode.SelectedIndex = 0;
57+
factions.Sort( (a,b)=>string.Compare( a.ToString( ), b.ToString( ), StringComparison.Ordinal ) );
58+
59+
foreach (var fac in factions)
60+
{
61+
LST_Factions.Items.Add( fac );
62+
}
63+
64+
if ( LST_Entries.Items.Count > 0 )
65+
{
66+
LST_Entries.SelectedIndex = 0;
67+
CMB_Mode.SelectedIndex = 0;
68+
}
69+
else
70+
splitContainer1.Panel2.Enabled = false;
5471
}
5572

5673
private void UpdateListbox()
@@ -94,6 +111,7 @@ private void LST_Entries_SelectedIndexChanged(object sender, EventArgs e)
94111

95112
private void BTN_AddItem_Click(object sender, EventArgs e)
96113
{
114+
splitContainer1.Panel2.Enabled = true;
97115
PluginSettings.Instance.ProtectedItems.Add( new ProtectedItem() );
98116
UpdateListbox();
99117
LST_Entries.SelectedIndex = PluginSettings.Instance.ProtectedItems.Count - 1;
@@ -102,9 +120,17 @@ private void BTN_AddItem_Click(object sender, EventArgs e)
102120
private void BTN_RemoveItem_Click(object sender, EventArgs e)
103121
{
104122
PluginSettings.Instance.ProtectedItems.RemoveAt( LST_Entries.SelectedIndex );
105-
if ( LST_Entries.SelectedIndex >= PluginSettings.Instance.ProtectedItems.Count )
123+
if ( PluginSettings.Instance.ProtectedItems.Count == 0 )
124+
{
125+
LST_Entries.ClearSelected( );
126+
LST_Entries.Items.Clear( );
127+
splitContainer1.Panel2.Enabled = false;
128+
}
129+
else if ( LST_Entries.SelectedIndex >= PluginSettings.Instance.ProtectedItems.Count )
130+
{
106131
LST_Entries.SelectedIndex--;
107-
UpdateListbox();
132+
UpdateListbox( );
133+
}
108134
}
109135

110136
private void BTN_SaveItem_Click(object sender, EventArgs e)
@@ -125,7 +151,10 @@ private void CMB_Mode_SelectedIndexChanged(object sender, EventArgs e)
125151

126152
private void LoadCurrentSettings()
127153
{
128-
CHK_Enabled.Checked = !_currentSettings.Enabled;
154+
CHK_Enabled.Checked = _currentItem.Enabled;
155+
CHK_Damage.Checked = _currentItem.ProtectDamage;
156+
CHK_LogOnly.Checked = _currentItem.LogOnly;
157+
CHK_Anyone.Checked = _currentSettings.AllExempt;
129158
CHK_BigOwner.Checked = _currentSettings.BigOwnerExempt;
130159
CHK_SmallOwner.Checked = _currentSettings.SmallOwnerExempt;
131160
CHK_Admin.Checked = _currentSettings.AdminExempt;
@@ -152,6 +181,20 @@ private void LoadCurrentSettings()
152181
}
153182
TXT_SpeedVal.Text = _currentSettings.SpeedLimit.ToString();
154183
TXT_SpeedTime.Text = _currentSettings.SpeedTime.ToString();
184+
LST_Factions.SelectedIndexChanged -= LST_Factions_SelectedIndexChanged;
185+
LST_Factions.SelectedItems.Clear( );
186+
if (_currentSettings.Factions != null)
187+
{
188+
var itemsCopy = new object[LST_Factions.Items.Count];
189+
LST_Factions.Items.CopyTo( itemsCopy, 0 );
190+
foreach (var facItem in itemsCopy)
191+
{
192+
if (_currentSettings.Factions.Contains( ( (FactionListItem)facItem ).Faction.FactionId ))
193+
//LST_Factions.SelectedItems.Add( facItem );
194+
LST_Factions.SetSelected( LST_Factions.Items.IndexOf( facItem ), true );
195+
}
196+
}
197+
LST_Factions.SelectedIndexChanged += LST_Factions_SelectedIndexChanged;
155198
}
156199

157200
private void TXT_EntityId_TextChanged(object sender, EventArgs e)
@@ -189,7 +232,7 @@ private void CHK_LogOnly_CheckedChanged(object sender, EventArgs e)
189232

190233
private void CHK_Anyone_CheckedChanged(object sender, EventArgs e)
191234
{
192-
_currentSettings.Enabled = !CHK_Enabled.Checked;
235+
_currentSettings.AllExempt = CHK_Anyone.Checked;
193236
}
194237

195238
private void CHK_BigOwner_CheckedChanged(object sender, EventArgs e)
@@ -282,5 +325,13 @@ private void TXT_SpeedTime_TextChanged(object sender, EventArgs e)
282325
{
283326
_currentSettings.SpeedTime = double.Parse( TXT_SpeedTime.Text );
284327
}
328+
329+
private void LST_Factions_SelectedIndexChanged(object sender, EventArgs e)
330+
{
331+
List<long> facIds = new List<long>();
332+
foreach(var faction in LST_Factions.SelectedItems)
333+
facIds.Add( ((FactionListItem)faction).Faction.FactionId );
334+
_currentSettings.Factions = facIds.ToArray( );
335+
}
285336
}
286337
}

EssentialsPlugin/EntityManagers/EntityManagement.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
using VRage.Game;
2323
using VRage.Game.Entity;
2424
using VRage.Game.ModAPI;
25+
using IMyBeacon = Sandbox.ModAPI.IMyBeacon;
26+
using IMyMedicalRoom = SpaceEngineers.Game.ModAPI.IMyMedicalRoom;
2527
using IMyProductionBlock = Sandbox.ModAPI.IMyProductionBlock;
28+
using IMyRadioAntenna = Sandbox.ModAPI.IMyRadioAntenna;
2629

2730
public class EntityManagement
2831
{

EssentialsPlugin/Essentials.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public class Essentials : IPlugin, IChatEventHandler, IPlayerEventHandler, ICube
6767

6868
#region Properties
6969

70-
public static bool StableBuild = true;
70+
public static bool StableBuild = false;
7171

7272
public static string PluginPath
7373
{
@@ -1087,7 +1087,6 @@ public float AtmosphericCargoShipSpawnTime {
10871087
}
10881088
}
10891089

1090-
/*
10911090
[Category("Programmable Block Blacklist")]
10921091
[Description("Types and members in this list will be unavailable to all programmable blocks. Ask on the KSH forum if you're unsure how to use this!!")]
10931092
[Browsable(true)]
@@ -1103,7 +1102,7 @@ public MTObservableCollection<BlacklistItem> BlacklistItems
11031102
PluginSettings.Instance.BlacklistItems = value;
11041103
}
11051104
}
1106-
*/
1105+
11071106
/*
11081107
[Category("Game Modes")]
11091108
[Description("Conquest Game Mode - This mode tracks asteroid owners by counting owned blocks near an asteroid to determine the owner. Includes a leaderboard")]
@@ -1290,7 +1289,7 @@ private void DoInit( string path )
12901289

12911290
MyAPIGateway.Multiplayer.RegisterMessageHandler(9005, Communication.ReceiveMessageParts);
12921291
MyAPIGateway.Multiplayer.RegisterMessageHandler( 9007, Communication.HandleAddConcealExempt );
1293-
//BlacklistManager.Instance.UpdateBlacklist();
1292+
BlacklistManager.Instance.UpdateBlacklist();
12941293
Log.Info( "Plugin '{0}' initialized. (Version: {1} ID: {2})", Name, Version, Id );
12951294
}
12961295

EssentialsPlugin/EssentialsPlugin.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<Compile Include="ChatHandlers\HandleInfo.cs" />
141141
<Compile Include="ChatHandlers\Utility\HandleUtilityGridsList.cs" />
142142
<Compile Include="ChatHandlers\Utility\HandleUtilityExportServer.cs" />
143+
<Compile Include="Editors\ListItems.cs" />
143144
<Compile Include="Essentials.cs" />
144145
<Compile Include="EntityManagers\BlockManagement.cs" />
145146
<Compile Include="EntityManagers\TurretManagement.cs" />
@@ -264,7 +265,7 @@
264265
</ItemGroup>
265266
<ItemGroup>
266267
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
267-
<HintPath>..\packages\NLog.4.3.7\lib\net45\NLog.dll</HintPath>
268+
<HintPath>..\packages\NLog.4.1.2\lib\net45\NLog.dll</HintPath>
268269
<Private>True</Private>
269270
</Reference>
270271
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">

EssentialsPlugin/NetworkHandlers/BlockNameHandler.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace EssentialsPlugin.NetworkHandlers
88
{
99
using System.Reflection;
1010
using System.Timers;
11+
using ProcessHandlers;
1112
using Sandbox.Engine.Multiplayer;
1213
using Sandbox.Game.Entities;
1314
using Sandbox.Game.World;
@@ -102,23 +103,37 @@ public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream
102103

103104
Essentials.Log.Info($"Intercepted block rename request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
104105

105-
if (settings.PunishmentType == ProtectedItem.PunishmentEnum.Kick)
106+
switch ( settings.PunishmentType )
106107
{
107-
_kickTimer.Elapsed += (sender, e) =>
108-
{
109-
Essentials.Log.Info($"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
110-
MyMultiplayer.Static.KickClient(remoteUserId);
111-
};
112-
_kickTimer.Start();
113-
}
114-
else if (settings.PunishmentType == ProtectedItem.PunishmentEnum.Ban)
115-
{
116-
_kickTimer.Elapsed += (sender, e) =>
117-
{
118-
Essentials.Log.Info($"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
119-
MyMultiplayer.Static.BanClient(remoteUserId, true);
120-
};
121-
_kickTimer.Start();
108+
case ProtectedItem.PunishmentEnum.Kick:
109+
_kickTimer.Elapsed += (sender, e) =>
110+
{
111+
Essentials.Log.Info($"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
112+
MyMultiplayer.Static.KickClient(remoteUserId);
113+
};
114+
_kickTimer.AutoReset = false;
115+
_kickTimer.Start();
116+
break;
117+
case ProtectedItem.PunishmentEnum.Ban:
118+
_kickTimer.Elapsed += (sender, e) =>
119+
{
120+
Essentials.Log.Info($"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
121+
MyMultiplayer.Static.BanClient(remoteUserId, true);
122+
};
123+
_kickTimer.AutoReset = false;
124+
_kickTimer.Start();
125+
break;
126+
case ProtectedItem.PunishmentEnum.Speed:
127+
Task.Run( ( ) =>
128+
{
129+
lock ( ProcessSpeed.SpeedPlayers )
130+
{
131+
long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( remoteUserId );
132+
ProcessSpeed.SpeedPlayers[playerId] = new Tuple<float, DateTime>( (float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes( settings.SpeedTime ) );
133+
}
134+
} );
135+
Essentials.Log.Info( $"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes" );
136+
break;
122137
}
123138

124139
found = true;

0 commit comments

Comments
 (0)