This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
/admin identity cleanup and /admin faction cleanup; cargo ship spawn …
…logic
- Loading branch information
Showing
16 changed files
with
524 additions
and
148 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
//306 | ||
//327 | ||
// | ||
// 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.5.306")] | ||
[assembly: AssemblyVersion("1.13.5.306")] | ||
[assembly: AssemblyFileVersion("1.13.5.327")] | ||
[assembly: AssemblyVersion("1.13.5.327")] |
106 changes: 106 additions & 0 deletions
106
EssentialsPlugin/ChatHandlers/Admin/HandleAdminAsteroidCleanup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
namespace EssentialsPlugin.ChatHandlers.Admin | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Sandbox.Engine.Multiplayer; | ||
using Sandbox.Game.Entities.Character; | ||
using Sandbox.ModAPI; | ||
using Utility; | ||
using VRage.Game.ModAPI; | ||
using VRage.ModAPI; | ||
using VRage.Network; | ||
using VRageMath; | ||
|
||
public class HandleAdminAsteroidCleanup : ChatHandlerBase | ||
{ | ||
public override string GetHelp( ) | ||
{ | ||
return "Removes asteroids without a player or ship within 1km. Usage: /admin asteroid cleanup"; | ||
} | ||
|
||
public override string GetCommandText( ) | ||
{ | ||
return "/admin asteroid cleanup"; | ||
} | ||
|
||
public override Communication.ServerDialogItem GetHelpDialog( ) | ||
{ | ||
Communication.ServerDialogItem dialogItem = new Communication.ServerDialogItem | ||
{ | ||
title = "Help", | ||
header = "", | ||
content = GetHelp( ), | ||
buttonText = "close" | ||
}; | ||
return dialogItem; | ||
} | ||
|
||
public override bool IsAdminCommand( ) | ||
{ | ||
return true; | ||
} | ||
|
||
public override bool AllowedInConsole( ) | ||
{ | ||
return true; | ||
} | ||
|
||
private static HashSet<Vector3D> entityPositions = new HashSet<Vector3D>( ); | ||
private static Dictionary<Vector3D, IMyVoxelMap> asteroidPositions = new Dictionary<Vector3D, IMyVoxelMap>( ); | ||
private static HashSet<IMyVoxelMap> toRemove = new HashSet<IMyVoxelMap>( ); | ||
|
||
public override bool HandleCommand( ulong userId, string[] words ) | ||
{ | ||
Essentials.Log.Info( "Asteroid cleanup" ); | ||
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( ); | ||
Wrapper.GameAction( ( ) => | ||
{ | ||
MyAPIGateway.Entities.GetEntities( entities ); | ||
foreach ( IMyEntity entity in entities ) | ||
{ | ||
if ( entity == null ) | ||
continue; | ||
if ( entity is IMyVoxelMap ) | ||
asteroidPositions.Add( entity.PositionComp.GetPosition( ), (IMyVoxelMap)entity ); | ||
else | ||
entityPositions.Add( entity.PositionComp.GetPosition( ) ); | ||
} | ||
} ); | ||
//TODO: Use a thread pool to speed this up? | ||
DateTime profile = DateTime.Now; | ||
Communication.SendPrivateInformation( userId, $"Found {asteroidPositions.Count} asteroids." ); | ||
foreach ( var asteroid in asteroidPositions ) | ||
{ | ||
bool found = false; | ||
BoundingSphereD bound = new BoundingSphereD( asteroid.Key, 1000 ); | ||
foreach ( Vector3D checkPosition in entityPositions ) | ||
{ | ||
if ( bound.Contains( checkPosition ) == ContainmentType.Contains ) | ||
{ | ||
found = true; | ||
break; | ||
} | ||
} | ||
|
||
if ( !found ) | ||
toRemove.Add( asteroid.Value ); | ||
} | ||
Communication.SendPrivateInformation( userId, $"Found {toRemove.Count} asteroids to remove." ); | ||
int count = 0; | ||
foreach ( IMyVoxelMap asteroid in toRemove ) | ||
{ | ||
if ( asteroid == null || asteroid.Closed ) | ||
continue; | ||
|
||
count++; | ||
|
||
Wrapper.GameAction( ( ) => asteroid.Close( ) ); | ||
} | ||
Communication.SendPrivateInformation( userId, $"Removed {count} asteroids." ); | ||
Essentials.Log.Info( "Asteroid cleanup elapsed time: " + (DateTime.Now - profile) ); | ||
return true; | ||
} | ||
} | ||
} | ||
|
118 changes: 118 additions & 0 deletions
118
EssentialsPlugin/ChatHandlers/Admin/HandleAdminFactionCleanup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
namespace EssentialsPlugin.ChatHandlers.Admin | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Sandbox.Game.Multiplayer; | ||
using Sandbox.Game.World; | ||
using Sandbox.ModAPI; | ||
using Utility; | ||
|
||
public class HandleAdminFactionCleanup : ChatHandlerBase | ||
{ | ||
public override string GetHelp( ) | ||
{ | ||
return "Cleans up factions with 1 or fewer members. Usage: /admin faction cleanup (verbose)"; | ||
} | ||
|
||
public override string GetCommandText( ) | ||
{ | ||
return "/admin faction cleanup"; | ||
} | ||
|
||
public override Communication.ServerDialogItem GetHelpDialog( ) | ||
{ | ||
Communication.ServerDialogItem dialogItem = new Communication.ServerDialogItem | ||
{ | ||
title = "Help", | ||
header = "", | ||
content = GetHelp( ), | ||
buttonText = "close" | ||
}; | ||
return dialogItem; | ||
} | ||
|
||
public override bool IsAdminCommand( ) | ||
{ | ||
return true; | ||
} | ||
|
||
public override bool AllowedInConsole( ) | ||
{ | ||
return true; | ||
} | ||
|
||
public override bool HandleCommand( ulong userId, string[] words ) | ||
{ | ||
Essentials.Log.Info( "Faction cleanup" ); | ||
MyFactionCollection factionCollection = MySession.Static.Factions; | ||
if ( factionCollection == null ) | ||
{ | ||
Essentials.Log.Info( "Fail" ); | ||
return true; | ||
} | ||
HashSet<MyFaction> toDelete = new HashSet<MyFaction>( ); | ||
bool verbose = words.Any( ) && words[0].ToLower( ) == "verbose"; | ||
|
||
foreach ( KeyValuePair<long, MyFaction> item in factionCollection ) | ||
{ | ||
MyFaction faction = item.Value; | ||
if ( faction == null ) | ||
continue; | ||
|
||
//get factions with one or fewer members | ||
if ( faction.Members.Count( ) <= 1 ) | ||
{ | ||
MyPlayer.PlayerId playerId; | ||
|
||
//check if the member is a valid player | ||
MyPlayer member; | ||
if ( !MySession.Static.Players.TryGetPlayerId( faction.Members.First( ).Value.PlayerId, out playerId ) ) | ||
{ | ||
toDelete.Add( faction ); | ||
continue; | ||
} | ||
//check if the player is online | ||
//I'm not sure what happens if we delete a faction with a member logged in | ||
//probably nothing, but maybe Clang | ||
member = MySession.Static.Players.GetPlayerById( playerId ); | ||
if ( member==null || member.Identity.IsDead ) | ||
toDelete.Add( faction ); | ||
} | ||
} | ||
|
||
Essentials.Log.Info( $"Found {toDelete.Count} factions to delete." ); | ||
if(verbose) | ||
Communication.SendPrivateInformation( userId, $"Found {toDelete.Count} factions to delete." ); | ||
int count = 0; | ||
foreach ( MyFaction faction in toDelete ) | ||
{ | ||
if ( faction == null ) | ||
continue; | ||
|
||
//make sure the faction still exists | ||
if ( !factionCollection.Contains( faction.FactionId ) ) | ||
continue; | ||
|
||
//NPC factions | ||
if ( faction.IsEveryoneNpc( ) ) | ||
continue; | ||
|
||
count++; | ||
if ( verbose ) | ||
Communication.SendPrivateInformation( userId, $"Removing faction {faction.Tag}: {faction.Name}" ); | ||
|
||
if(DateTime.Now.Millisecond<10) | ||
Communication.SendPrivateInformation( userId, $"Removed {count} of {toDelete.Count} factions." ); | ||
|
||
//delete the faction | ||
Wrapper.GameAction( ( ) => MyFactionCollection.RemoveFaction( faction.FactionId ) ); | ||
} | ||
|
||
Communication.SendPrivateInformation( userId, $"Removed {count} factions with one or fewer members." ); | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
119 changes: 79 additions & 40 deletions
119
EssentialsPlugin/ChatHandlers/Admin/HandleAdminIdentityCleanup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,114 @@ | ||
namespace EssentialsPlugin.ChatHandlers.Admin | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Sandbox.Game.Multiplayer; | ||
using Sandbox.Game.World; | ||
using Sandbox.ModAPI; | ||
using Utility; | ||
public class HandleAdminIdentityCleanup : ChatHandlerBase | ||
{ | ||
using VRage.Game.ModAPI; | ||
using VRage.ModAPI; | ||
|
||
public override string GetHelp() | ||
{ | ||
return "For testing."; | ||
} | ||
public class HandleAdminIdentityCleanup : ChatHandlerBase | ||
{ | ||
public override string GetHelp( ) | ||
{ | ||
return "Cleans up trash identities. Usage: /admin identity cleanup (verbose)"; | ||
} | ||
|
||
public override string GetCommandText() | ||
{ | ||
return "/admin identity cleanup"; | ||
} | ||
public override string GetCommandText( ) | ||
{ | ||
return "/admin identity cleanup"; | ||
} | ||
|
||
public override Communication.ServerDialogItem GetHelpDialog( ) | ||
{ | ||
Communication.ServerDialogItem DialogItem = new Communication.ServerDialogItem( ); | ||
DialogItem.title = "Help"; | ||
DialogItem.header = ""; | ||
DialogItem.content = GetHelp( ); | ||
DialogItem.buttonText = "close"; | ||
return DialogItem; | ||
Communication.ServerDialogItem dialogItem = new Communication.ServerDialogItem | ||
{ | ||
title = "Help", | ||
header = "", | ||
content = GetHelp( ), | ||
buttonText = "close" | ||
}; | ||
return dialogItem; | ||
} | ||
|
||
public override bool IsAdminCommand() | ||
{ | ||
return true; | ||
} | ||
public override bool IsAdminCommand( ) | ||
{ | ||
return true; | ||
} | ||
|
||
public override bool AllowedInConsole() | ||
{ | ||
return true; | ||
} | ||
public override bool AllowedInConsole( ) | ||
{ | ||
return true; | ||
} | ||
|
||
public override bool HandleCommand( ulong userId, string[ ] words ) | ||
{/* | ||
public override bool HandleCommand( ulong userId, string[] words ) | ||
{ | ||
MyPlayerCollection playerCollection = MyAPIGateway.Players as MyPlayerCollection; | ||
bool verbose = words.Any( ) && words[0].ToLower( ) == "verbose"; | ||
|
||
if ( playerCollection == null ) | ||
return true; | ||
|
||
var identities = playerCollection.GetAllIdentities( ).GroupBy( x => x.DisplayName ).Where( y => y.Count( ) > 1 ).ToList( ); | ||
HashSet<long> owners = new HashSet<long>( ); | ||
HashSet<MyIdentity> toRemove = new HashSet<MyIdentity>( ); | ||
|
||
HashSet<IMyEntity> entities = new HashSet<IMyEntity>( ); | ||
|
||
while ( identities.Count > 0 ) | ||
Wrapper.GameAction( ( ) => MyAPIGateway.Entities.GetEntities( entities ) ); | ||
|
||
foreach ( IMyEntity entity in entities ) | ||
{ | ||
string compareName = identities[0].Key; | ||
var toDelete = identities.Where(x => x. ) | ||
IMyCubeGrid grid = entity as IMyCubeGrid; | ||
if ( grid == null ) | ||
continue; | ||
|
||
foreach ( long owner in grid.SmallOwners ) | ||
owners.Add( owner ); | ||
} | ||
|
||
int count = identitiesToDelete.Count; | ||
foreach(MyIdentity toDelete in identitiesToDelete) | ||
Dictionary<long, MyIdentity>.ValueCollection myIdentities = playerCollection.GetAllIdentities( ); | ||
|
||
foreach ( MyIdentity identity in myIdentities ) | ||
{ | ||
Essentials.Log.Info( $"Deleted dead identity {toDelete.DisplayName}" ); | ||
playerCollection.RemoveIdentity( toDelete.IdentityId ); | ||
if ( !identity.IsDead ) | ||
continue; | ||
|
||
if ( !owners.Contains( identity.IdentityId ) ) | ||
toRemove.Add( identity ); | ||
} | ||
|
||
if ( count != 0 ) | ||
int count = toRemove.Count; | ||
int removedCount = 0; | ||
Essentials.Log.Info( count ); | ||
|
||
foreach ( MyIdentity identity in toRemove ) | ||
{ | ||
Essentials.Log.Info( $"Deleted {count} dead identities." ); | ||
//make extra sure the player isn't online | ||
if ( !identity.IsDead ) | ||
continue; | ||
|
||
//make sure the identity still exists | ||
if ( !playerCollection.HasIdentity( identity.IdentityId ) ) | ||
continue; | ||
|
||
removedCount++; | ||
if ( verbose ) | ||
Communication.SendPrivateInformation( userId, $"Removed identity {identity.DisplayName}: {identity.IdentityId}" ); | ||
|
||
if ( DateTime.Now.Millisecond <10 ) | ||
Communication.SendPrivateInformation( userId, $"Removed {removedCount} of {count} identities." ); | ||
|
||
|
||
Wrapper.GameAction( ( ) => playerCollection.RemoveIdentity( identity.IdentityId ) ); | ||
} | ||
*/ | ||
return true; | ||
} | ||
|
||
} | ||
Communication.SendPrivateInformation( userId, $"Removed {count} identities." ); | ||
|
||
return true; | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.