2007-11-06 09:26:10 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-11-06 09:26:10 +00:00
|
|
|
{
|
|
|
|
|
public class FindObjectsCommand : Command
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
Dictionary<UUID, Primitive> PrimsWaiting = new Dictionary<UUID, Primitive>();
|
2007-11-06 09:26:10 +00:00
|
|
|
AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
|
|
|
|
|
|
|
|
|
|
public FindObjectsCommand(TestClient testClient)
|
|
|
|
|
{
|
2009-10-26 06:03:26 +00:00
|
|
|
testClient.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
Name = "findobjects";
|
|
|
|
|
Description = "Finds all objects, which name contains search-string. " +
|
|
|
|
|
"Usage: findobjects [radius] <search-string>";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Objects;
|
2007-11-06 09:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2007-11-06 09:26:10 +00:00
|
|
|
{
|
|
|
|
|
// *** parse arguments ***
|
|
|
|
|
if ((args.Length < 1) || (args.Length > 2))
|
|
|
|
|
return "Usage: findobjects [radius] <search-string>";
|
|
|
|
|
float radius = float.Parse(args[0]);
|
2009-08-03 18:28:52 +00:00
|
|
|
string searchString = (args.Length > 1) ? args[1] : String.Empty;
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
// *** get current location ***
|
2008-07-25 05:15:05 +00:00
|
|
|
Vector3 location = Client.Self.SimPosition;
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
// *** find all objects in radius ***
|
2008-01-03 21:55:49 +00:00
|
|
|
List<Primitive> prims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(
|
2009-08-03 18:28:52 +00:00
|
|
|
delegate(Primitive prim)
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
Vector3 pos = prim.Position;
|
2008-08-01 20:22:22 +00:00
|
|
|
return ((prim.ParentID == 0) && (pos != Vector3.Zero) && (Vector3.Distance(pos, location) < radius));
|
2007-11-06 09:26:10 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// *** request properties of these objects ***
|
|
|
|
|
bool complete = RequestObjectProperties(prims, 250);
|
|
|
|
|
|
2009-08-03 18:28:52 +00:00
|
|
|
foreach (Primitive p in prims)
|
|
|
|
|
{
|
|
|
|
|
string name = p.Properties != null ? p.Properties.Name : null;
|
|
|
|
|
if (String.IsNullOrEmpty(searchString) || ((name != null) && (name.Contains(searchString))))
|
2019-06-08 17:58:54 -05:00
|
|
|
Console.WriteLine("Object '{0}': {1}", name, p.ID.ToString());
|
2007-11-06 09:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-08 17:58:54 -05:00
|
|
|
if (complete) return "Done searching";
|
|
|
|
|
Console.WriteLine("Warning: Unable to retrieve full properties for:");
|
|
|
|
|
foreach (UUID uuid in PrimsWaiting.Keys)
|
|
|
|
|
Console.WriteLine(uuid);
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
return "Done searching";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool RequestObjectProperties(List<Primitive> objects, int msPerRequest)
|
|
|
|
|
{
|
|
|
|
|
// Create an array of the local IDs of all the prims we are requesting properties for
|
|
|
|
|
uint[] localids = new uint[objects.Count];
|
|
|
|
|
|
2009-08-03 18:28:52 +00:00
|
|
|
lock (PrimsWaiting)
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
PrimsWaiting.Clear();
|
|
|
|
|
|
2009-08-03 18:28:52 +00:00
|
|
|
for (int i = 0; i < objects.Count; ++i)
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
localids[i] = objects[i].LocalID;
|
|
|
|
|
PrimsWaiting.Add(objects[i].ID, objects[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Client.Objects.SelectObjects(Client.Network.CurrentSim, localids);
|
|
|
|
|
|
|
|
|
|
return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-26 06:03:26 +00:00
|
|
|
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
2007-11-06 09:26:10 +00:00
|
|
|
{
|
2009-08-03 18:28:52 +00:00
|
|
|
lock (PrimsWaiting)
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
Primitive prim;
|
2009-10-26 06:03:26 +00:00
|
|
|
if (PrimsWaiting.TryGetValue(e.Properties.ObjectID, out prim))
|
2009-08-03 18:28:52 +00:00
|
|
|
{
|
2009-10-26 06:03:26 +00:00
|
|
|
prim.Properties = e.Properties;
|
2007-11-06 09:26:10 +00:00
|
|
|
}
|
2009-10-26 06:03:26 +00:00
|
|
|
PrimsWaiting.Remove(e.Properties.ObjectID);
|
2007-11-06 09:26:10 +00:00
|
|
|
|
|
|
|
|
if (PrimsWaiting.Count == 0)
|
|
|
|
|
AllPropertiesReceived.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|