60 lines
2.2 KiB
C#
60 lines
2.2 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace OpenMetaverse.TestClient.Commands
|
|
{
|
|
class SearchClassifiedsCommand : Command
|
|
{
|
|
System.Threading.AutoResetEvent waitQuery = new System.Threading.AutoResetEvent(false);
|
|
|
|
public SearchClassifiedsCommand(TestClient testClient)
|
|
{
|
|
Name = "searchclassifieds";
|
|
Description = "Searches Classified Ads. Usage: searchclassifieds [search text]";
|
|
Category = CommandCategory.Search;
|
|
}
|
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
|
{
|
|
if (args.Length < 1)
|
|
return "Usage: searchclassifieds [search text]";
|
|
|
|
string searchText = args.Aggregate(string.Empty, (current, t) => current + (t + " "));
|
|
searchText = searchText.TrimEnd();
|
|
waitQuery.Reset();
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
EventHandler<DirClassifiedsReplyEventArgs> callback = delegate(object sender, DirClassifiedsReplyEventArgs e)
|
|
{
|
|
result.AppendFormat("Your search string '{0}' returned {1} classified ads" + System.Environment.NewLine,
|
|
searchText, e.Classifieds.Count);
|
|
foreach (DirectoryManager.Classified ad in e.Classifieds)
|
|
{
|
|
result.AppendLine(ad.ToString());
|
|
}
|
|
|
|
// classifieds are sent 16 ads at a time
|
|
if (e.Classifieds.Count < 16)
|
|
{
|
|
waitQuery.Set();
|
|
}
|
|
};
|
|
|
|
Client.Directory.DirClassifiedsReply += callback;
|
|
|
|
UUID searchID = Client.Directory.StartClassifiedSearch(searchText, DirectoryManager.ClassifiedCategories.Any, DirectoryManager.ClassifiedQueryFlags.Mature | DirectoryManager.ClassifiedQueryFlags.PG);
|
|
|
|
if (!waitQuery.WaitOne(20000, false) && Client.Network.Connected)
|
|
{
|
|
result.AppendLine("Timeout waiting for simulator to respond to query.");
|
|
}
|
|
|
|
Client.Directory.DirClassifiedsReply -= callback;
|
|
|
|
return result.ToString();
|
|
}
|
|
}
|
|
}
|