Allow use of regular expressions in "show object name", "show part name" and "delete object name" console commands if --regex switch is used.
Deleteing objects by name, creator uuid or owner uuid now requires confirmation to avoid accidental deletion.0.7.3-extended
parent
afb0600621
commit
66c204b983
|
@ -29,8 +29,10 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using log4net;
|
using log4net;
|
||||||
using Mono.Addins;
|
using Mono.Addins;
|
||||||
|
using NDesk.Options;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
using OpenMetaverse;
|
using OpenMetaverse;
|
||||||
using OpenSim.Framework;
|
using OpenSim.Framework;
|
||||||
|
@ -78,25 +80,31 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
m_console = MainConsole.Instance;
|
m_console = MainConsole.Instance;
|
||||||
|
|
||||||
m_console.Commands.AddCommand("Objects", false, "delete object owner",
|
m_console.Commands.AddCommand(
|
||||||
"delete object owner <UUID>",
|
"Objects", false, "delete object owner",
|
||||||
"Delete a scene object by owner", HandleDeleteObject);
|
"delete object owner <UUID>",
|
||||||
|
"Delete a scene object by owner", HandleDeleteObject);
|
||||||
|
|
||||||
m_console.Commands.AddCommand("Objects", false, "delete object creator",
|
m_console.Commands.AddCommand(
|
||||||
"delete object creator <UUID>",
|
"Objects", false, "delete object creator",
|
||||||
"Delete a scene object by creator", HandleDeleteObject);
|
"delete object creator <UUID>",
|
||||||
|
"Delete a scene object by creator", HandleDeleteObject);
|
||||||
|
|
||||||
m_console.Commands.AddCommand("Objects", false, "delete object uuid",
|
m_console.Commands.AddCommand(
|
||||||
"delete object uuid <UUID>",
|
"Objects", false, "delete object uuid",
|
||||||
"Delete a scene object by uuid", HandleDeleteObject);
|
"delete object uuid <UUID>",
|
||||||
|
"Delete a scene object by uuid", HandleDeleteObject);
|
||||||
|
|
||||||
m_console.Commands.AddCommand("Objects", false, "delete object name",
|
m_console.Commands.AddCommand(
|
||||||
"delete object name <name>",
|
"Objects", false, "delete object name",
|
||||||
"Delete a scene object by name", HandleDeleteObject);
|
"delete object name [--regex] <name>",
|
||||||
|
"Delete a scene object by name.\nIf --regex is specified then the name is treatead as a regular expression",
|
||||||
|
HandleDeleteObject);
|
||||||
|
|
||||||
m_console.Commands.AddCommand("Objects", false, "delete object outside",
|
m_console.Commands.AddCommand(
|
||||||
"delete object outside",
|
"Objects", false, "delete object outside",
|
||||||
"Delete all scene objects outside region boundaries", HandleDeleteObject);
|
"delete object outside",
|
||||||
|
"Delete all scene objects outside region boundaries", HandleDeleteObject);
|
||||||
|
|
||||||
m_console.Commands.AddCommand(
|
m_console.Commands.AddCommand(
|
||||||
"Objects",
|
"Objects",
|
||||||
|
@ -109,8 +117,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
"Objects",
|
"Objects",
|
||||||
false,
|
false,
|
||||||
"show object name",
|
"show object name",
|
||||||
"show object name <name>",
|
"show object name [--regex] <name>",
|
||||||
"Show details of scene objects with the given name", HandleShowObjectByName);
|
"Show details of scene objects with the given name.\nIf --regex is specified then the name is treatead as a regular expression",
|
||||||
|
HandleShowObjectByName);
|
||||||
|
|
||||||
m_console.Commands.AddCommand(
|
m_console.Commands.AddCommand(
|
||||||
"Objects",
|
"Objects",
|
||||||
|
@ -123,8 +132,9 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
"Objects",
|
"Objects",
|
||||||
false,
|
false,
|
||||||
"show part name",
|
"show part name",
|
||||||
"show part name <name>",
|
"show part name [--regex] <name>",
|
||||||
"Show details of scene object parts with the given name", HandleShowPartByName);
|
"Show details of scene object parts with the given name.\nIf --regex is specified then the name is treatead as a regular expression",
|
||||||
|
HandleShowPartByName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveRegion(Scene scene)
|
public void RemoveRegion(Scene scene)
|
||||||
|
@ -169,22 +179,38 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
m_console.OutputFormat(sb.ToString());
|
m_console.OutputFormat(sb.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleShowObjectByName(string module, string[] cmd)
|
private void HandleShowObjectByName(string module, string[] cmdparams)
|
||||||
{
|
{
|
||||||
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmd.Length < 4)
|
bool useRegex = false;
|
||||||
|
OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
|
||||||
|
|
||||||
|
List<string> mainParams = options.Parse(cmdparams);
|
||||||
|
|
||||||
|
if (mainParams.Count < 4)
|
||||||
{
|
{
|
||||||
m_console.OutputFormat("Usage: show object name <name>");
|
m_console.OutputFormat("Usage: show object name [--regex] <name>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = cmd[3];
|
string name = mainParams[3];
|
||||||
|
|
||||||
List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
|
List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
|
||||||
|
Action<SceneObjectGroup> searchAction;
|
||||||
|
|
||||||
m_scene.ForEachSOG(so => { if (so.Name == name) { sceneObjects.Add(so); }});
|
if (useRegex)
|
||||||
|
{
|
||||||
|
Regex nameRegex = new Regex(name);
|
||||||
|
searchAction = so => { if (nameRegex.IsMatch(so.Name)) { sceneObjects.Add(so); }};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchAction = so => { if (so.Name == name) { sceneObjects.Add(so); }};
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(searchAction);
|
||||||
|
|
||||||
if (sceneObjects.Count == 0)
|
if (sceneObjects.Count == 0)
|
||||||
{
|
{
|
||||||
|
@ -235,22 +261,39 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
m_console.OutputFormat(sb.ToString());
|
m_console.OutputFormat(sb.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleShowPartByName(string module, string[] cmd)
|
private void HandleShowPartByName(string module, string[] cmdparams)
|
||||||
{
|
{
|
||||||
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (cmd.Length < 4)
|
bool useRegex = false;
|
||||||
|
OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
|
||||||
|
|
||||||
|
List<string> mainParams = options.Parse(cmdparams);
|
||||||
|
|
||||||
|
if (mainParams.Count < 4)
|
||||||
{
|
{
|
||||||
m_console.OutputFormat("Usage: show part name <name>");
|
m_console.OutputFormat("Usage: show part name [--regex] <name>");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
string name = cmd[3];
|
string name = mainParams[3];
|
||||||
|
|
||||||
List<SceneObjectPart> parts = new List<SceneObjectPart>();
|
List<SceneObjectPart> parts = new List<SceneObjectPart>();
|
||||||
|
|
||||||
m_scene.ForEachSOG(so => so.ForEachPart(sop => { if (sop.Name == name) { parts.Add(sop); } }));
|
Action<SceneObjectGroup> searchAction;
|
||||||
|
|
||||||
|
if (useRegex)
|
||||||
|
{
|
||||||
|
Regex nameRegex = new Regex(name);
|
||||||
|
searchAction = so => so.ForEachPart(sop => { if (nameRegex.IsMatch(sop.Name)) { parts.Add(sop); } });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchAction = so => so.ForEachPart(sop => { if (sop.Name == name) { parts.Add(sop); } });
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(searchAction);
|
||||||
|
|
||||||
if (parts.Count == 0)
|
if (parts.Count == 0)
|
||||||
{
|
{
|
||||||
|
@ -312,96 +355,121 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
o = cmd[3];
|
o = cmd[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SceneObjectGroup> deletes = new List<SceneObjectGroup>();
|
List<SceneObjectGroup> deletes = null;
|
||||||
|
|
||||||
UUID match;
|
UUID match;
|
||||||
|
bool requireConfirmation = true;
|
||||||
|
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case "owner":
|
case "owner":
|
||||||
if (!UUID.TryParse(o, out match))
|
if (!UUID.TryParse(o, out match))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
deletes = new List<SceneObjectGroup>();
|
||||||
{
|
|
||||||
if (g.OwnerID == match && !g.IsAttachment)
|
|
||||||
deletes.Add(g);
|
|
||||||
});
|
|
||||||
|
|
||||||
// if (deletes.Count == 0)
|
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
||||||
// m_console.OutputFormat("No objects were found with owner {0}", match);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "creator":
|
|
||||||
if (!UUID.TryParse(o, out match))
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
|
||||||
{
|
|
||||||
if (g.RootPart.CreatorID == match && !g.IsAttachment)
|
|
||||||
deletes.Add(g);
|
|
||||||
});
|
|
||||||
|
|
||||||
// if (deletes.Count == 0)
|
|
||||||
// m_console.OutputFormat("No objects were found with creator {0}", match);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "uuid":
|
|
||||||
if (!UUID.TryParse(o, out match))
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
|
||||||
{
|
|
||||||
if (g.UUID == match && !g.IsAttachment)
|
|
||||||
deletes.Add(g);
|
|
||||||
});
|
|
||||||
|
|
||||||
// if (deletes.Count == 0)
|
|
||||||
// m_console.OutputFormat("No objects were found with uuid {0}", match);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "name":
|
|
||||||
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
|
||||||
{
|
|
||||||
if (g.RootPart.Name == o && !g.IsAttachment)
|
|
||||||
deletes.Add(g);
|
|
||||||
});
|
|
||||||
|
|
||||||
// if (deletes.Count == 0)
|
|
||||||
// m_console.OutputFormat("No objects were found with name {0}", o);
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "outside":
|
|
||||||
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
|
||||||
{
|
|
||||||
SceneObjectPart rootPart = g.RootPart;
|
|
||||||
bool delete = false;
|
|
||||||
|
|
||||||
if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0)
|
|
||||||
{
|
{
|
||||||
delete = true;
|
if (g.OwnerID == match && !g.IsAttachment)
|
||||||
}
|
deletes.Add(g);
|
||||||
else
|
});
|
||||||
{
|
|
||||||
ILandObject parcel
|
// if (deletes.Count == 0)
|
||||||
= m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
|
// m_console.OutputFormat("No objects were found with owner {0}", match);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "creator":
|
||||||
|
if (!UUID.TryParse(o, out match))
|
||||||
|
return;
|
||||||
|
|
||||||
if (parcel == null || parcel.LandData.Name == "NO LAND")
|
deletes = new List<SceneObjectGroup>();
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
||||||
|
{
|
||||||
|
if (g.RootPart.CreatorID == match && !g.IsAttachment)
|
||||||
|
deletes.Add(g);
|
||||||
|
});
|
||||||
|
|
||||||
|
// if (deletes.Count == 0)
|
||||||
|
// m_console.OutputFormat("No objects were found with creator {0}", match);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "uuid":
|
||||||
|
if (!UUID.TryParse(o, out match))
|
||||||
|
return;
|
||||||
|
|
||||||
|
requireConfirmation = false;
|
||||||
|
deletes = new List<SceneObjectGroup>();
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
||||||
|
{
|
||||||
|
if (g.UUID == match && !g.IsAttachment)
|
||||||
|
deletes.Add(g);
|
||||||
|
});
|
||||||
|
|
||||||
|
// if (deletes.Count == 0)
|
||||||
|
// m_console.OutputFormat("No objects were found with uuid {0}", match);
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "name":
|
||||||
|
deletes = GetDeleteCandidatesByName(module, cmd);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "outside":
|
||||||
|
deletes = new List<SceneObjectGroup>();
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(delegate (SceneObjectGroup g)
|
||||||
|
{
|
||||||
|
SceneObjectPart rootPart = g.RootPart;
|
||||||
|
bool delete = false;
|
||||||
|
|
||||||
|
if (rootPart.GroupPosition.Z < 0.0 || rootPart.GroupPosition.Z > 10000.0)
|
||||||
|
{
|
||||||
delete = true;
|
delete = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ILandObject parcel
|
||||||
|
= m_scene.LandChannel.GetLandObject(rootPart.GroupPosition.X, rootPart.GroupPosition.Y);
|
||||||
|
|
||||||
|
if (parcel == null || parcel.LandData.Name == "NO LAND")
|
||||||
|
delete = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delete && !g.IsAttachment && !deletes.Contains(g))
|
||||||
|
deletes.Add(g);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (deletes.Count == 0)
|
||||||
|
m_console.OutputFormat("No objects were found outside region bounds");
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
if (delete && !g.IsAttachment && !deletes.Contains(g))
|
default:
|
||||||
deletes.Add(g);
|
m_console.OutputFormat("Unrecognized mode {0}", mode);
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (deletes.Count == 0)
|
if (deletes == null || deletes.Count <= 0)
|
||||||
// m_console.OutputFormat("No objects were found outside region bounds");
|
return;
|
||||||
|
|
||||||
break;
|
if (requireConfirmation)
|
||||||
|
{
|
||||||
|
string response = MainConsole.Instance.CmdPrompt(
|
||||||
|
string.Format(
|
||||||
|
"Are you sure that you want to delete {0} objects from {1}",
|
||||||
|
deletes.Count, m_scene.RegionInfo.RegionName),
|
||||||
|
"n");
|
||||||
|
|
||||||
|
if (response.ToLower() != "y")
|
||||||
|
{
|
||||||
|
MainConsole.Instance.OutputFormat(
|
||||||
|
"Aborting delete of {0} objects from {1}", deletes.Count, m_scene.RegionInfo.RegionName);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName);
|
m_console.OutputFormat("Deleting {0} objects in {1}", deletes.Count, m_scene.RegionInfo.RegionName);
|
||||||
|
@ -412,5 +480,44 @@ namespace OpenSim.Region.CoreModules.World.Objects.Commands
|
||||||
m_scene.DeleteSceneObject(g, false);
|
m_scene.DeleteSceneObject(g, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<SceneObjectGroup> GetDeleteCandidatesByName(string module, string[] cmdparams)
|
||||||
|
{
|
||||||
|
if (!(m_console.ConsoleScene == null || m_console.ConsoleScene == m_scene))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
bool useRegex = false;
|
||||||
|
OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null );
|
||||||
|
|
||||||
|
List<string> mainParams = options.Parse(cmdparams);
|
||||||
|
|
||||||
|
if (mainParams.Count < 4)
|
||||||
|
{
|
||||||
|
m_console.OutputFormat("Usage: delete object name [--regex] <name>");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
string name = mainParams[3];
|
||||||
|
|
||||||
|
List<SceneObjectGroup> sceneObjects = new List<SceneObjectGroup>();
|
||||||
|
Action<SceneObjectGroup> searchAction;
|
||||||
|
|
||||||
|
if (useRegex)
|
||||||
|
{
|
||||||
|
Regex nameRegex = new Regex(name);
|
||||||
|
searchAction = so => { if (nameRegex.IsMatch(so.Name)) { sceneObjects.Add(so); }};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
searchAction = so => { if (so.Name == name) { sceneObjects.Add(so); }};
|
||||||
|
}
|
||||||
|
|
||||||
|
m_scene.ForEachSOG(searchAction);
|
||||||
|
|
||||||
|
if (sceneObjects.Count == 0)
|
||||||
|
m_console.OutputFormat("No objects with name {0} found in {1}", name, m_scene.RegionInfo.RegionName);
|
||||||
|
|
||||||
|
return sceneObjects;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue