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

Commit

Permalink
Fix protection, enable faction selector, merge dev branch into master.
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxar-tc committed Aug 18, 2016
1 parent 6fc715f commit 268fb6f
Show file tree
Hide file tree
Showing 24 changed files with 425 additions and 180 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//196
//237
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("1.13.7.196")]
[assembly: AssemblyVersion("1.13.7.196")]
[assembly: AssemblyFileVersion("1.13.7.237")]
[assembly: AssemblyVersion("1.13.7.237")]
18 changes: 13 additions & 5 deletions EssentialsPlugin/Editors/GridPicker.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace EssentialsPlugin.Editors
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Sandbox.Game.Entities;
Expand All @@ -9,7 +10,6 @@
public partial class GridPicker : Form
{
public long SelectedEntity;
private MyEntity[] _grids;
public GridPicker()
{
InitializeComponent();
Expand All @@ -18,14 +18,22 @@ public GridPicker()
private void GridPicker_Load(object sender, EventArgs e)
{
LST_Entities.DoubleClick += LST_Entities_DoubleClick;
_grids = MyEntities.GetEntities().Where( x => x is MyCubeGrid ).ToArray();
foreach ( var grid in _grids )
LST_Entities.Items.Add( $"{grid.DisplayName??""}:{grid.EntityId}" );
List<GridListItem> grids = new List<GridListItem>();
foreach (var entity in MyEntities.GetEntities( ))
{
if(entity is MyCubeGrid && !entity.Closed && entity.Physics!=null)
grids.Add( new GridListItem( (MyCubeGrid)entity ) );
}

grids.Sort( (a,b) => string.Compare( a.ToString( ), b.ToString( ), StringComparison.Ordinal ) );

foreach ( var grid in grids )
LST_Entities.Items.Add( grid );
}

private void BTN_Ok_Click(object sender, EventArgs e)
{
SelectedEntity = _grids[LST_Entities.SelectedIndex].EntityId;
SelectedEntity = ((GridListItem)LST_Entities.SelectedItem).Grid.EntityId;
this.DialogResult = DialogResult.OK;
this.Close();
}
Expand Down
45 changes: 45 additions & 0 deletions EssentialsPlugin/Editors/ListItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EssentialsPlugin.Editors
{
using Sandbox.Game.Entities;
using Sandbox.Game.World;
using VRage.Game.Entity;

public class GridListItem
{
public GridListItem( MyCubeGrid grid )
{
Grid = grid;
}

public MyCubeGrid Grid;
/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString( )
{
return $"{Grid.DisplayName ?? ""}: {Grid.EntityId}";
}
}

public class FactionListItem
{
public FactionListItem(MyFaction faction)
{
Faction = faction;
}

public MyFaction Faction;

/// <summary>Returns a string that represents the current object.</summary>
/// <returns>A string that represents the current object.</returns>
public override string ToString( )
{
return $"{Faction.Tag??"ERROR"}: {Faction.Name??Faction.FactionId.ToString( )}";
}
}
}
1 change: 1 addition & 0 deletions EssentialsPlugin/Editors/ProtectionEditor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 60 additions & 9 deletions EssentialsPlugin/Editors/ProtectionEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace EssentialsPlugin.Editors
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
Expand All @@ -13,12 +15,12 @@ public ProtectionEditor()
{
InitializeComponent();
}

private readonly string[] _modeDesc = {
"These players are allowed to add blocks to this grid.",
"These players are allowed to remove blocks from this grid.",
"These players are allowed to paint blocks on this grid.",
"These players are allowed to change ownership of blocks on this grid.",
"These players are allowed to change ownership of blocks.",
"These players are allowed to rename blocks on this grid.",
"These players are allowed to rename this grid.",
"These players are allowed to convert this grid to a station.",
Expand All @@ -44,13 +46,28 @@ private void ProtectionEditor_Load(object sender, EventArgs e)
"Grid Delete"
} );
//CMB_Mode.Items.AddRange( Enum.GetNames( typeof(ProtectedItem.ProtectionModeEnum) ) );
List<FactionListItem> factions = new List<FactionListItem>();
foreach ( var faction in MySession.Static.Factions )
{
LST_Factions.Items.Add( $"{faction.Value.Tag}: {faction.Value.Name}" );
if (faction.Value == null)
continue;
factions.Add( new FactionListItem( faction.Value ) );
}

LST_Entries.SelectedIndex = 0;
CMB_Mode.SelectedIndex = 0;
factions.Sort( (a,b)=>string.Compare( a.ToString( ), b.ToString( ), StringComparison.Ordinal ) );

foreach (var fac in factions)
{
LST_Factions.Items.Add( fac );
}

if ( LST_Entries.Items.Count > 0 )
{
LST_Entries.SelectedIndex = 0;
CMB_Mode.SelectedIndex = 0;
}
else
splitContainer1.Panel2.Enabled = false;
}

private void UpdateListbox()
Expand Down Expand Up @@ -94,6 +111,7 @@ private void LST_Entries_SelectedIndexChanged(object sender, EventArgs e)

private void BTN_AddItem_Click(object sender, EventArgs e)
{
splitContainer1.Panel2.Enabled = true;
PluginSettings.Instance.ProtectedItems.Add( new ProtectedItem() );
UpdateListbox();
LST_Entries.SelectedIndex = PluginSettings.Instance.ProtectedItems.Count - 1;
Expand All @@ -102,9 +120,17 @@ private void BTN_AddItem_Click(object sender, EventArgs e)
private void BTN_RemoveItem_Click(object sender, EventArgs e)
{
PluginSettings.Instance.ProtectedItems.RemoveAt( LST_Entries.SelectedIndex );
if ( LST_Entries.SelectedIndex >= PluginSettings.Instance.ProtectedItems.Count )
if ( PluginSettings.Instance.ProtectedItems.Count == 0 )
{
LST_Entries.ClearSelected( );
LST_Entries.Items.Clear( );
splitContainer1.Panel2.Enabled = false;
}
else if ( LST_Entries.SelectedIndex >= PluginSettings.Instance.ProtectedItems.Count )
{
LST_Entries.SelectedIndex--;
UpdateListbox();
UpdateListbox( );
}
}

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

private void LoadCurrentSettings()
{
CHK_Enabled.Checked = !_currentSettings.Enabled;
CHK_Enabled.Checked = _currentItem.Enabled;
CHK_Damage.Checked = _currentItem.ProtectDamage;
CHK_LogOnly.Checked = _currentItem.LogOnly;
CHK_Anyone.Checked = _currentSettings.AllExempt;
CHK_BigOwner.Checked = _currentSettings.BigOwnerExempt;
CHK_SmallOwner.Checked = _currentSettings.SmallOwnerExempt;
CHK_Admin.Checked = _currentSettings.AdminExempt;
Expand All @@ -152,6 +181,20 @@ private void LoadCurrentSettings()
}
TXT_SpeedVal.Text = _currentSettings.SpeedLimit.ToString();
TXT_SpeedTime.Text = _currentSettings.SpeedTime.ToString();
LST_Factions.SelectedIndexChanged -= LST_Factions_SelectedIndexChanged;
LST_Factions.SelectedItems.Clear( );
if (_currentSettings.Factions != null)
{
var itemsCopy = new object[LST_Factions.Items.Count];
LST_Factions.Items.CopyTo( itemsCopy, 0 );
foreach (var facItem in itemsCopy)
{
if (_currentSettings.Factions.Contains( ( (FactionListItem)facItem ).Faction.FactionId ))
//LST_Factions.SelectedItems.Add( facItem );
LST_Factions.SetSelected( LST_Factions.Items.IndexOf( facItem ), true );
}
}
LST_Factions.SelectedIndexChanged += LST_Factions_SelectedIndexChanged;
}

private void TXT_EntityId_TextChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -189,7 +232,7 @@ private void CHK_LogOnly_CheckedChanged(object sender, EventArgs e)

private void CHK_Anyone_CheckedChanged(object sender, EventArgs e)
{
_currentSettings.Enabled = !CHK_Enabled.Checked;
_currentSettings.AllExempt = CHK_Anyone.Checked;
}

private void CHK_BigOwner_CheckedChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -282,5 +325,13 @@ private void TXT_SpeedTime_TextChanged(object sender, EventArgs e)
{
_currentSettings.SpeedTime = double.Parse( TXT_SpeedTime.Text );
}

private void LST_Factions_SelectedIndexChanged(object sender, EventArgs e)
{
List<long> facIds = new List<long>();
foreach(var faction in LST_Factions.SelectedItems)
facIds.Add( ((FactionListItem)faction).Faction.FactionId );
_currentSettings.Factions = facIds.ToArray( );
}
}
}
3 changes: 3 additions & 0 deletions EssentialsPlugin/EntityManagers/EntityManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
using VRage.Game;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using IMyBeacon = Sandbox.ModAPI.IMyBeacon;
using IMyMedicalRoom = SpaceEngineers.Game.ModAPI.IMyMedicalRoom;
using IMyProductionBlock = Sandbox.ModAPI.IMyProductionBlock;
using IMyRadioAntenna = Sandbox.ModAPI.IMyRadioAntenna;

public class EntityManagement
{
Expand Down
7 changes: 3 additions & 4 deletions EssentialsPlugin/Essentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class Essentials : IPlugin, IChatEventHandler, IPlayerEventHandler, ICube

#region Properties

public static bool StableBuild = true;
public static bool StableBuild = false;

public static string PluginPath
{
Expand Down Expand Up @@ -1087,7 +1087,6 @@ public float AtmosphericCargoShipSpawnTime {
}
}

/*
[Category("Programmable Block Blacklist")]
[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!!")]
[Browsable(true)]
Expand All @@ -1103,7 +1102,7 @@ public MTObservableCollection<BlacklistItem> BlacklistItems
PluginSettings.Instance.BlacklistItems = value;
}
}
*/

/*
[Category("Game Modes")]
[Description("Conquest Game Mode - This mode tracks asteroid owners by counting owned blocks near an asteroid to determine the owner. Includes a leaderboard")]
Expand Down Expand Up @@ -1290,7 +1289,7 @@ private void DoInit( string path )

MyAPIGateway.Multiplayer.RegisterMessageHandler(9005, Communication.ReceiveMessageParts);
MyAPIGateway.Multiplayer.RegisterMessageHandler( 9007, Communication.HandleAddConcealExempt );
//BlacklistManager.Instance.UpdateBlacklist();
BlacklistManager.Instance.UpdateBlacklist();
Log.Info( "Plugin '{0}' initialized. (Version: {1} ID: {2})", Name, Version, Id );
}

Expand Down
3 changes: 2 additions & 1 deletion EssentialsPlugin/EssentialsPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<Compile Include="ChatHandlers\HandleInfo.cs" />
<Compile Include="ChatHandlers\Utility\HandleUtilityGridsList.cs" />
<Compile Include="ChatHandlers\Utility\HandleUtilityExportServer.cs" />
<Compile Include="Editors\ListItems.cs" />
<Compile Include="Essentials.cs" />
<Compile Include="EntityManagers\BlockManagement.cs" />
<Compile Include="EntityManagers\TurretManagement.cs" />
Expand Down Expand Up @@ -264,7 +265,7 @@
</ItemGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.3.7\lib\net45\NLog.dll</HintPath>
<HintPath>..\packages\NLog.4.1.2\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
Expand Down
47 changes: 31 additions & 16 deletions EssentialsPlugin/NetworkHandlers/BlockNameHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace EssentialsPlugin.NetworkHandlers
{
using System.Reflection;
using System.Timers;
using ProcessHandlers;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Entities;
using Sandbox.Game.World;
Expand Down Expand Up @@ -102,23 +103,37 @@ public override bool Handle( ulong remoteUserId, CallSite site, BitStream stream

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

if (settings.PunishmentType == ProtectedItem.PunishmentEnum.Kick)
switch ( settings.PunishmentType )
{
_kickTimer.Elapsed += (sender, e) =>
{
Essentials.Log.Info($"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
MyMultiplayer.Static.KickClient(remoteUserId);
};
_kickTimer.Start();
}
else if (settings.PunishmentType == ProtectedItem.PunishmentEnum.Ban)
{
_kickTimer.Elapsed += (sender, e) =>
{
Essentials.Log.Info($"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
MyMultiplayer.Static.BanClient(remoteUserId, true);
};
_kickTimer.Start();
case ProtectedItem.PunishmentEnum.Kick:
_kickTimer.Elapsed += (sender, e) =>
{
Essentials.Log.Info($"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
MyMultiplayer.Static.KickClient(remoteUserId);
};
_kickTimer.AutoReset = false;
_kickTimer.Start();
break;
case ProtectedItem.PunishmentEnum.Ban:
_kickTimer.Elapsed += (sender, e) =>
{
Essentials.Log.Info($"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)}:{remoteUserId} for renaming blocks on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
MyMultiplayer.Static.BanClient(remoteUserId, true);
};
_kickTimer.AutoReset = false;
_kickTimer.Start();
break;
case ProtectedItem.PunishmentEnum.Speed:
Task.Run( ( ) =>
{
lock ( ProcessSpeed.SpeedPlayers )
{
long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId( remoteUserId );
ProcessSpeed.SpeedPlayers[playerId] = new Tuple<float, DateTime>( (float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes( settings.SpeedTime ) );
}
} );
Essentials.Log.Info( $"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes" );
break;
}

found = true;
Expand Down
Loading

0 comments on commit 268fb6f

Please sign in to comment.