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

Commit 5cc6bad

Browse files
committed
Made logging in conceal a lot more useful.
1 parent 54821bf commit 5cc6bad

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

EssentialsPlugin/EntityManagers/EntityManagement.cs

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using EssentialsPlugin.ProcessHandlers;
88
using EssentialsPlugin.Utility;
9+
using NLog;
910
using Sandbox.Common;
1011
using Sandbox.Common.ObjectBuilders;
1112
using Sandbox.ModAPI;
@@ -377,30 +378,30 @@ private static void ConcealEntities(HashSet<IMyEntity> entitesToConceal)
377378
Essentials.Log.Info(string.Format("Concealed {0} entities.", entitesToConceal.Count));
378379
}
379380

380-
private static void ConcealEntity(IMyEntity entity)
381+
private static void ConcealEntity( IMyEntity entity )
381382
{
382383
int pos = 0;
383384
try
384385
{
385-
if (!entity.InScene)
386+
if ( !entity.InScene )
386387
return;
387388

388-
MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder((IMyCubeGrid)entity);
389-
if (builder == null)
389+
MyObjectBuilder_CubeGrid builder = CubeGrids.SafeGetObjectBuilder( (IMyCubeGrid) entity );
390+
if ( builder == null )
390391
return;
391392

392393
pos = 1;
393-
IMyCubeGrid grid = (IMyCubeGrid)entity;
394+
IMyCubeGrid grid = (IMyCubeGrid) entity;
394395
long ownerId = 0;
395396
string ownerName = "";
396-
if (CubeGrids.GetOwner(builder, out ownerId))
397+
if ( CubeGrids.GetOwner( builder, out ownerId ) )
397398
{
398399
//ownerId = grid.BigOwners.First();
399-
ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId(ownerId).Name;
400+
ownerName = PlayerMap.Instance.GetPlayerItemFromPlayerId( ownerId ).Name;
400401
}
401402

402403
pos = 2;
403-
if (entity.Physics != null)
404+
if ( entity.Physics != null )
404405
{
405406
entity.Physics.LinearVelocity = Vector3.Zero;
406407
entity.Physics.AngularVelocity = Vector3.Zero;
@@ -413,17 +414,17 @@ private static void ConcealEntity(IMyEntity entity)
413414
*/
414415

415416
builder.PersistentFlags = MyPersistentEntityFlags2.None;
416-
MyAPIGateway.Entities.RemapObjectBuilder(builder);
417+
MyAPIGateway.Entities.RemapObjectBuilder( builder );
417418

418419
pos = 3;
419-
if (RemovedGrids.Contains(entity.EntityId))
420+
if ( RemovedGrids.Contains( entity.EntityId ) )
420421
{
421-
Essentials.Log.Info("Conceal", string.Format("Concealing - Id: {0} DUPE FOUND - Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
422-
BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
422+
Essentials.Log.Info( "Concealing - Id: {0} DUPE FOUND - Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId );
423+
BaseEntityNetworkManager.BroadcastRemoveEntity( entity, false );
423424
}
424425
else
425426
{
426-
if (!PluginSettings.Instance.DynamicConcealServerOnly)
427+
if ( !PluginSettings.Instance.DynamicConcealServerOnly )
427428
{
428429
/*
429430
if (PluginSettings.Instance.DynamicBlockManagementEnabled)
@@ -439,30 +440,30 @@ private static void ConcealEntity(IMyEntity entity)
439440
BlockManagement.Instance.EnableGrid((IMyCubeGrid)entity);
440441
}
441442
*/
442-
IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
443-
Essentials.Log.Info("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
444-
if (newEntity == null)
445-
{
446-
Essentials.Log.Info("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
447-
return;
448-
}
443+
IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder( builder );
444+
Essentials.Log.Debug( "Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId );
445+
if ( newEntity == null )
446+
{
447+
Essentials.Log.Error( string.Format( "Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId ) );
448+
return;
449+
}
449450

450-
RemovedGrids.Add(entity.EntityId);
451-
BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
452-
MyAPIGateway.Entities.AddEntity(newEntity, false);
453-
Essentials.Log.Info("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId));
454-
}
451+
RemovedGrids.Add( entity.EntityId );
452+
BaseEntityNetworkManager.BroadcastRemoveEntity( entity, false );
453+
MyAPIGateway.Entities.AddEntity( newEntity, false );
454+
Essentials.Log.Debug( "End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, newEntity.EntityId );
455+
}
455456
else
456-
{
457-
Essentials.Log.Info("Conceal", string.Format("Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
457+
{
458+
Essentials.Log.Debug( "Start Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId );
458459
entity.InScene = false;
459-
Essentials.Log.Info("Conceal", string.Format("End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId));
460-
}
461-
}
460+
Essentials.Log.Debug( "End Concealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3}", entity.EntityId, entity.DisplayName, ownerId, ownerName, builder.EntityId );
461+
}
462+
}
462463
}
463-
catch (Exception ex)
464+
catch ( Exception ex )
464465
{
465-
Essentials.Log.Info(string.Format("ConcealEntity({1}): {0}", ex.ToString(), pos));
466+
Essentials.Log.Error( "Failure while concealing entity {0}.", pos, ex );
466467
}
467468
}
468469

@@ -538,11 +539,11 @@ public static void CheckAndRevealEntities()
538539
re += (DateTime.Now - reStart).TotalMilliseconds;
539540

540541
if ((DateTime.Now - start).TotalMilliseconds > 2000)
541-
Essentials.Log.Info(string.Format("Completed Reveal Check: {0}ms (br: {1}ms, re: {2}ms)", (DateTime.Now - start).TotalMilliseconds, br, re));
542+
Essentials.Log.Info( "Completed Reveal Check: {0}ms (br: {1}ms, re: {2}ms)", (DateTime.Now - start).TotalMilliseconds, br, re );
542543
}
543544
catch (Exception ex)
544545
{
545-
Essentials.Log.Info(string.Format("CheckAndReveal(): {0}", ex.ToString()));
546+
Essentials.Log.Error( ex );
546547
}
547548
finally
548549
{
@@ -770,15 +771,15 @@ private static void RevealEntity(KeyValuePair<IMyEntity, string> item)
770771

771772
if(RemovedGrids.Contains(entity.EntityId))
772773
{
773-
Essentials.Log.Info("Conceal", string.Format("Revealing - Id: {0} DUPE FOUND Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
774+
Essentials.Log.Info( "Revealing - Id: {0} DUPE FOUND Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason );
774775
BaseEntityNetworkManager.BroadcastRemoveEntity(entity, false);
775776
}
776777
else
777778
{
778779
if (!PluginSettings.Instance.DynamicConcealServerOnly)
779780
{
780781
IMyEntity newEntity = MyAPIGateway.Entities.CreateFromObjectBuilder(builder);
781-
Essentials.Log.Info("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason));
782+
Essentials.Log.Info( "Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason );
782783
if (newEntity == null)
783784
{
784785
Essentials.Log.Info("Conceal", string.Format("Issue - CreateFromObjectBuilder failed: {0}", newEntity.EntityId));
@@ -800,11 +801,11 @@ private static void RevealEntity(KeyValuePair<IMyEntity, string> item)
800801
List<MyObjectBuilder_EntityBase> addList = new List<MyObjectBuilder_EntityBase>();
801802
addList.Add(newEntity.GetObjectBuilder());
802803
MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
803-
Essentials.Log.Info("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason));
804+
Essentials.Log.Info( "End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {5}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, newEntity.EntityId, reason );
804805
}
805806
else
806807
{
807-
Essentials.Log.Info("Conceal", string.Format("Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
808+
Essentials.Log.Info( "Start Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason );
808809
entity.InScene = true;
809810
// Send to users, client will remove if doesn't need - this solves login problem
810811
/*CC
@@ -816,7 +817,7 @@ private static void RevealEntity(KeyValuePair<IMyEntity, string> item)
816817
MyAPIGateway.Multiplayer.SendEntitiesCreated(addList);
817818
}
818819
*/
819-
Essentials.Log.Info("Conceal", string.Format("End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason));
820+
Essentials.Log.Info( "End Revealing - Id: {0} -> {4} Display: {1} OwnerId: {2} OwnerName: {3} Reason: {4}", entity.EntityId, entity.DisplayName.Replace("\r", "").Replace("\n", ""), ownerId, ownerName, reason );
820821
}
821822
}
822823
//});

0 commit comments

Comments
 (0)