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)
|
|
|
|
|
{
|
|
|
|
|
testClient.Objects.OnObjectProperties += new ObjectManager.ObjectPropertiesCallback(Objects_OnObjectProperties);
|
|
|
|
|
|
|
|
|
|
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))))
|
2007-11-30 13:15:31 +00:00
|
|
|
Console.WriteLine(String.Format("Object '{0}': {1}", name, p.ID.ToString()));
|
2007-11-06 09:26:10 +00:00
|
|
|
}
|
|
|
|
|
|
2009-08-03 18:28:52 +00:00
|
|
|
if (!complete)
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
Console.WriteLine("Warning: Unable to retrieve full properties for:");
|
2008-07-25 05:15:05 +00:00
|
|
|
foreach (UUID uuid in PrimsWaiting.Keys)
|
2007-11-06 09:26:10 +00:00
|
|
|
Console.WriteLine(uuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-24 05:06:51 +00:00
|
|
|
void Objects_OnObjectProperties(Simulator simulator, Primitive.ObjectProperties properties)
|
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-08-03 18:28:52 +00:00
|
|
|
if (PrimsWaiting.TryGetValue(properties.ObjectID, out prim))
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
prim.Properties = properties;
|
|
|
|
|
}
|
|
|
|
|
PrimsWaiting.Remove(properties.ObjectID);
|
|
|
|
|
|
|
|
|
|
if (PrimsWaiting.Count == 0)
|
|
|
|
|
AllPropertiesReceived.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|