From c40b17ac30fa6d0b618c1962db407cd0350c607d Mon Sep 17 00:00:00 2001 From: John Gross Date: Fri, 2 Jun 2017 19:40:52 -0700 Subject: [PATCH] Fix NetworkManager, add more entity management, default command permission level to "Admin" --- Torch.Client/Properties/AssemblyInfo.cs | 4 +- Torch.Server/Properties/AssemblyInfo.cs | 4 +- Torch.Server/Torch.Server.csproj | 33 +++++++--- .../{ => Entities}/Blocks/BlockViewModel.cs | 18 ++++- .../Blocks/BlockViewModelGenerator.cs | 0 .../Blocks/PropertyViewModel.cs | 0 .../ViewModels/Entities/CharacterViewModel.cs | 2 +- .../ViewModels/Entities/EntityViewModel.cs | 3 +- .../{ => Entities}/FloatingObjectViewModel.cs | 2 +- .../ViewModels/Entities/GridViewModel.cs | 13 ++-- .../ViewModels/Entities/VoxelMapViewModel.cs | 38 ++++++++++- .../ViewModels/EntityTreeViewModel.cs | 13 ++-- Torch.Server/Views/ConfigControl.xaml | 62 +++++++++--------- .../Converters/StringBuilderConverter.cs | 22 +++++++ .../Views/Converters/StringIdConverter.cs | 22 +++++++ .../Views/Converters/Vector3DConverter.cs | 29 +++++++++ .../{ => Entities}/Blocks/BlockView.xaml | 9 ++- .../{ => Entities}/Blocks/BlockView.xaml.cs | 0 .../{ => Entities}/Blocks/PropertyView.xaml | 3 +- .../Blocks/PropertyView.xaml.cs | 36 +--------- Torch.Server/Views/Entities/GridView.xaml | 22 +++++++ Torch.Server/Views/Entities/GridView.xaml.cs | 28 ++++++++ Torch.Server/Views/Entities/VoxelMapView.xaml | 22 +++++++ .../Views/Entities/VoxelMapView.xaml.cs | 35 ++++++++++ Torch.Server/Views/EntitiesControl.xaml | 10 +-- Torch.Server/Views/EntitiesControl.xaml.cs | 10 ++- Torch.Server/Views/TorchUI.xaml | 2 +- Torch.Server/Views/TorchUI.xaml.cs | 12 ++++ Torch/Collections/MTObservableCollection.cs | 17 +++++ Torch/Commands/CategoryAttribute.cs | 14 ++-- Torch/Commands/Command.cs | 2 +- Torch/Commands/CommandAttribute.cs | 14 ++++ Torch/Managers/MultiplayerManager.cs | 2 +- .../Managers/NetworkManager/NetworkManager.cs | 27 ++++++-- Torch/Persistent.cs | 65 +++++++++++++++++++ Torch/Torch.csproj | 5 ++ Torch/TorchConfig.cs | 3 + 37 files changed, 489 insertions(+), 114 deletions(-) rename Torch.Server/ViewModels/{ => Entities}/Blocks/BlockViewModel.cs (74%) rename Torch.Server/ViewModels/{ => Entities}/Blocks/BlockViewModelGenerator.cs (100%) rename Torch.Server/ViewModels/{ => Entities}/Blocks/PropertyViewModel.cs (100%) rename Torch.Server/ViewModels/{ => Entities}/FloatingObjectViewModel.cs (87%) create mode 100644 Torch.Server/Views/Converters/StringBuilderConverter.cs create mode 100644 Torch.Server/Views/Converters/StringIdConverter.cs create mode 100644 Torch.Server/Views/Converters/Vector3DConverter.cs rename Torch.Server/Views/{ => Entities}/Blocks/BlockView.xaml (79%) rename Torch.Server/Views/{ => Entities}/Blocks/BlockView.xaml.cs (100%) rename Torch.Server/Views/{ => Entities}/Blocks/PropertyView.xaml (87%) rename Torch.Server/Views/{ => Entities}/Blocks/PropertyView.xaml.cs (69%) create mode 100644 Torch.Server/Views/Entities/GridView.xaml create mode 100644 Torch.Server/Views/Entities/GridView.xaml.cs create mode 100644 Torch.Server/Views/Entities/VoxelMapView.xaml create mode 100644 Torch.Server/Views/Entities/VoxelMapView.xaml.cs create mode 100644 Torch/Persistent.cs diff --git a/Torch.Client/Properties/AssemblyInfo.cs b/Torch.Client/Properties/AssemblyInfo.cs index 464f2bf..adadb02 100644 --- a/Torch.Client/Properties/AssemblyInfo.cs +++ b/Torch.Client/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("1.0.135.374")] -[assembly: AssemblyFileVersion("1.0.135.374")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.153.575")] +[assembly: AssemblyFileVersion("1.0.153.575")] \ No newline at end of file diff --git a/Torch.Server/Properties/AssemblyInfo.cs b/Torch.Server/Properties/AssemblyInfo.cs index 464f2bf..adadb02 100644 --- a/Torch.Server/Properties/AssemblyInfo.cs +++ b/Torch.Server/Properties/AssemblyInfo.cs @@ -1,4 +1,4 @@ using System.Reflection; -[assembly: AssemblyVersion("1.0.135.374")] -[assembly: AssemblyFileVersion("1.0.135.374")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.153.575")] +[assembly: AssemblyFileVersion("1.0.153.575")] \ No newline at end of file diff --git a/Torch.Server/Torch.Server.csproj b/Torch.Server/Torch.Server.csproj index cc464a9..8b870f9 100644 --- a/Torch.Server/Torch.Server.csproj +++ b/Torch.Server/Torch.Server.csproj @@ -175,14 +175,14 @@ Component - - - + + + - + @@ -191,10 +191,11 @@ AddWorkshopItemsDialog.xaml - + + BlockView.xaml - + PropertyView.xaml @@ -206,6 +207,14 @@ EntitiesControl.xaml + + + + GridView.xaml + + + VoxelMapView.xaml + ModsControl.xaml @@ -260,11 +269,11 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile - + Designer MSBuild:Compile @@ -280,6 +289,14 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/Torch.Server/ViewModels/Blocks/BlockViewModel.cs b/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs similarity index 74% rename from Torch.Server/ViewModels/Blocks/BlockViewModel.cs rename to Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs index e26860b..57f2cad 100644 --- a/Torch.Server/ViewModels/Blocks/BlockViewModel.cs +++ b/Torch.Server/ViewModels/Entities/Blocks/BlockViewModel.cs @@ -1,8 +1,11 @@ using System; using System.Collections.Generic; +using System.Drawing.Text; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; +using Sandbox.Game.Entities.Cube; using Sandbox.ModAPI; using Sandbox.ModAPI.Interfaces; using Torch.Server.ViewModels.Entities; @@ -26,9 +29,22 @@ namespace Torch.Server.ViewModels.Blocks } } + /// + public override string Position { get => base.Position; set { } } + + public long BuiltBy + { + get => ((MySlimBlock)Block.SlimBlock).BuiltBy; + set + { + TorchBase.Instance.InvokeBlocking(() => ((MySlimBlock)Block.SlimBlock).TransferAuthorship(value)); + OnPropertyChanged(); + } + } + public override bool CanStop => false; - public BlockViewModel(IMyTerminalBlock block) : base(block) + public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree) { Block = block; var propList = new List(); diff --git a/Torch.Server/ViewModels/Blocks/BlockViewModelGenerator.cs b/Torch.Server/ViewModels/Entities/Blocks/BlockViewModelGenerator.cs similarity index 100% rename from Torch.Server/ViewModels/Blocks/BlockViewModelGenerator.cs rename to Torch.Server/ViewModels/Entities/Blocks/BlockViewModelGenerator.cs diff --git a/Torch.Server/ViewModels/Blocks/PropertyViewModel.cs b/Torch.Server/ViewModels/Entities/Blocks/PropertyViewModel.cs similarity index 100% rename from Torch.Server/ViewModels/Blocks/PropertyViewModel.cs rename to Torch.Server/ViewModels/Entities/Blocks/PropertyViewModel.cs diff --git a/Torch.Server/ViewModels/Entities/CharacterViewModel.cs b/Torch.Server/ViewModels/Entities/CharacterViewModel.cs index 6b82e17..d54b005 100644 --- a/Torch.Server/ViewModels/Entities/CharacterViewModel.cs +++ b/Torch.Server/ViewModels/Entities/CharacterViewModel.cs @@ -4,7 +4,7 @@ namespace Torch.Server.ViewModels.Entities { public class CharacterViewModel : EntityViewModel { - public CharacterViewModel(MyCharacter character) : base(character) + public CharacterViewModel(MyCharacter character, EntityTreeViewModel tree) : base(character, tree) { } diff --git a/Torch.Server/ViewModels/Entities/EntityViewModel.cs b/Torch.Server/ViewModels/Entities/EntityViewModel.cs index 03e4285..54e724b 100644 --- a/Torch.Server/ViewModels/Entities/EntityViewModel.cs +++ b/Torch.Server/ViewModels/Entities/EntityViewModel.cs @@ -6,6 +6,7 @@ namespace Torch.Server.ViewModels.Entities { public class EntityViewModel : ViewModel { + protected EntityTreeViewModel Tree { get; } public IMyEntity Entity { get; } public long Id => Entity.EntityId; @@ -36,7 +37,7 @@ namespace Torch.Server.ViewModels.Entities public virtual bool CanDelete => !(Entity is IMyCharacter); - public EntityViewModel(IMyEntity entity) + public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree) { Entity = entity; } diff --git a/Torch.Server/ViewModels/FloatingObjectViewModel.cs b/Torch.Server/ViewModels/Entities/FloatingObjectViewModel.cs similarity index 87% rename from Torch.Server/ViewModels/FloatingObjectViewModel.cs rename to Torch.Server/ViewModels/Entities/FloatingObjectViewModel.cs index bbb8ffc..faf0984 100644 --- a/Torch.Server/ViewModels/FloatingObjectViewModel.cs +++ b/Torch.Server/ViewModels/Entities/FloatingObjectViewModel.cs @@ -9,6 +9,6 @@ namespace Torch.Server.ViewModels public override string Name => $"{base.Name} ({Floating.Amount})"; - public FloatingObjectViewModel(MyFloatingObject floating) : base(floating) { } + public FloatingObjectViewModel(MyFloatingObject floating, EntityTreeViewModel tree) : base(floating, tree) { } } } diff --git a/Torch.Server/ViewModels/Entities/GridViewModel.cs b/Torch.Server/ViewModels/Entities/GridViewModel.cs index 3dab4a0..1ed0e62 100644 --- a/Torch.Server/ViewModels/Entities/GridViewModel.cs +++ b/Torch.Server/ViewModels/Entities/GridViewModel.cs @@ -11,15 +11,17 @@ namespace Torch.Server.ViewModels.Entities public MTObservableCollection Blocks { get; } = new MTObservableCollection(); /// - public override string Name => $"{base.Name} ({Grid.BlocksCount} blocks)"; + public string DescriptiveName => $"{Name} ({Grid.BlocksCount} blocks)"; - public GridViewModel(MyCubeGrid grid) : base(grid) + public GridViewModel() { } + + public GridViewModel(MyCubeGrid grid, EntityTreeViewModel tree) : base(grid, tree) { TorchBase.Instance.InvokeBlocking(() => { foreach (var block in grid.GetFatBlocks().Where(b => b is IMyTerminalBlock)) { - Blocks.Add(new BlockViewModel((IMyTerminalBlock)block)); + Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, tree)); } }); Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName); @@ -39,8 +41,9 @@ namespace Torch.Server.ViewModels.Entities private void Grid_OnBlockAdded(Sandbox.Game.Entities.Cube.MySlimBlock obj) { - if (obj.FatBlock != null) - Blocks.Add(new BlockViewModel((IMyTerminalBlock)obj.FatBlock)); + var block = obj.FatBlock as IMyTerminalBlock; + if (block != null) + Blocks.Add(new BlockViewModel(block, Tree)); Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName); OnPropertyChanged(nameof(Name)); diff --git a/Torch.Server/ViewModels/Entities/VoxelMapViewModel.cs b/Torch.Server/ViewModels/Entities/VoxelMapViewModel.cs index de27cfb..9809214 100644 --- a/Torch.Server/ViewModels/Entities/VoxelMapViewModel.cs +++ b/Torch.Server/ViewModels/Entities/VoxelMapViewModel.cs @@ -1,4 +1,9 @@ -using Sandbox.Game.Entities; +using System.Collections.Generic; +using System.Linq; +using Sandbox.Game.Entities; +using VRage.Game.Entity; +using VRage.Game.ModAPI; +using VRage.Library.Collections; namespace Torch.Server.ViewModels.Entities { @@ -10,6 +15,35 @@ namespace Torch.Server.ViewModels.Entities public override bool CanStop => false; - public VoxelMapViewModel(MyVoxelBase e) : base(e) { } + public MTObservableCollection AttachedGrids { get; } = new MTObservableCollection(); + + public void UpdateAttachedGrids() + { + AttachedGrids.Clear(); + var box = Entity.WorldAABB; + var entities = new List(); + MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, entities, MyEntityQueryType.Static); + foreach (var entity in entities.Where(e => e is IMyCubeGrid)) + { + var gridModel = Tree.Grids.FirstOrDefault(g => g.Entity.EntityId == entity.EntityId); + if (gridModel == null) + { + gridModel = new GridViewModel((MyCubeGrid)entity, Tree); + Tree.Grids.Add(gridModel); + } + + AttachedGrids.Add(gridModel); + } + } + + public VoxelMapViewModel(MyVoxelBase e, EntityTreeViewModel tree) : base(e, tree) + { + + } + + public VoxelMapViewModel() + { + + } } } diff --git a/Torch.Server/ViewModels/EntityTreeViewModel.cs b/Torch.Server/ViewModels/EntityTreeViewModel.cs index 640c5a4..37412e1 100644 --- a/Torch.Server/ViewModels/EntityTreeViewModel.cs +++ b/Torch.Server/ViewModels/EntityTreeViewModel.cs @@ -53,20 +53,23 @@ namespace Torch.Server.ViewModels private void MyEntities_OnEntityAdd(VRage.Game.Entity.MyEntity obj) { - //TODO: make view models switch (obj) { case MyCubeGrid grid: - Grids.Add(new GridViewModel(grid)); + if (Grids.All(g => g.Entity.EntityId != obj.EntityId)) + Grids.Add(new GridViewModel(grid, this)); break; case MyCharacter character: - Characters.Add(new CharacterViewModel(character)); + if (Characters.All(g => g.Entity.EntityId != obj.EntityId)) + Characters.Add(new CharacterViewModel(character, this)); break; case MyFloatingObject floating: - FloatingObjects.Add(new FloatingObjectViewModel(floating)); + if (FloatingObjects.All(g => g.Entity.EntityId != obj.EntityId)) + FloatingObjects.Add(new FloatingObjectViewModel(floating, this)); break; case MyVoxelBase voxel: - VoxelMaps.Add(new VoxelMapViewModel(voxel)); + if (VoxelMaps.All(g => g.Entity.EntityId != obj.EntityId)) + VoxelMaps.Add(new VoxelMapViewModel(voxel, this)); break; } } diff --git a/Torch.Server/Views/ConfigControl.xaml b/Torch.Server/Views/ConfigControl.xaml index 319622f..2e43456 100644 --- a/Torch.Server/Views/ConfigControl.xaml +++ b/Torch.Server/Views/ConfigControl.xaml @@ -16,39 +16,39 @@ - - - - - - + +