2009-10-07 20:13:33 +00:00
|
|
|
|
using System;
|
2021-07-25 11:10:52 -05:00
|
|
|
|
using System.Linq;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace OpenMetaverse.TestClient.Commands
|
|
|
|
|
|
{
|
|
|
|
|
|
class SearchClassifiedsCommand : Command
|
|
|
|
|
|
{
|
2009-10-16 02:53:53 +00:00
|
|
|
|
System.Threading.AutoResetEvent waitQuery = new System.Threading.AutoResetEvent(false);
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
public SearchClassifiedsCommand(TestClient testClient)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "searchclassifieds";
|
|
|
|
|
|
Description = "Searches Classified Ads. Usage: searchclassifieds [search text]";
|
2009-10-17 05:50:51 +00:00
|
|
|
|
Category = CommandCategory.Search;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
|
return "Usage: searchclassifieds [search text]";
|
|
|
|
|
|
|
2021-07-25 11:10:52 -05:00
|
|
|
|
string searchText = args.Aggregate(string.Empty, (current, t) => current + (t + " "));
|
2009-10-07 20:13:33 +00:00
|
|
|
|
searchText = searchText.TrimEnd();
|
|
|
|
|
|
waitQuery.Reset();
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder();
|
2009-10-10 06:38:07 +00:00
|
|
|
|
|
|
|
|
|
|
EventHandler<DirClassifiedsReplyEventArgs> callback = delegate(object sender, DirClassifiedsReplyEventArgs e)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
result.AppendFormat("Your search string '{0}' returned {1} classified ads" + System.Environment.NewLine,
|
2009-10-10 06:38:07 +00:00
|
|
|
|
searchText, e.Classifieds.Count);
|
|
|
|
|
|
foreach (DirectoryManager.Classified ad in e.Classifieds)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
result.AppendLine(ad.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// classifieds are sent 16 ads at a time
|
2009-10-10 06:38:07 +00:00
|
|
|
|
if (e.Classifieds.Count < 16)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
waitQuery.Set();
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2009-10-10 06:38:07 +00:00
|
|
|
|
Client.Directory.DirClassifiedsReply += callback;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
UUID searchID = Client.Directory.StartClassifiedSearch(searchText, DirectoryManager.ClassifiedCategories.Any, DirectoryManager.ClassifiedQueryFlags.Mature | DirectoryManager.ClassifiedQueryFlags.PG);
|
|
|
|
|
|
|
2025-01-13 07:44:05 -06:00
|
|
|
|
if (!waitQuery.WaitOne(TimeSpan.FromSeconds(20), false) && Client.Network.Connected)
|
2009-10-07 20:13:33 +00:00
|
|
|
|
{
|
|
|
|
|
|
result.AppendLine("Timeout waiting for simulator to respond to query.");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-10-10 06:38:07 +00:00
|
|
|
|
Client.Directory.DirClassifiedsReply -= callback;
|
2009-10-07 20:13:33 +00:00
|
|
|
|
|
|
|
|
|
|
return result.ToString();
|
2009-10-10 06:38:07 +00:00
|
|
|
|
}
|
2009-10-07 20:13:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|