2008-01-05 23:30:50 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2008-01-05 23:30:50 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
public class JoinGroupCommand : Command
|
|
|
|
|
{
|
|
|
|
|
ManualResetEvent GetGroupsSearchEvent = new ManualResetEvent(false);
|
2008-07-25 05:15:05 +00:00
|
|
|
private UUID queryID = UUID.Zero;
|
|
|
|
|
private UUID resolvedGroupID;
|
2008-01-05 23:30:50 +00:00
|
|
|
private string groupName;
|
|
|
|
|
private string resolvedGroupName;
|
|
|
|
|
private bool joinedGroup;
|
|
|
|
|
|
|
|
|
|
public JoinGroupCommand(TestClient testClient)
|
|
|
|
|
{
|
|
|
|
|
Name = "joingroup";
|
|
|
|
|
Description = "join a group. Usage: joingroup GroupName | joingroup UUID GroupId";
|
2008-07-25 08:55:36 +00:00
|
|
|
Category = CommandCategory.Groups;
|
2008-01-05 23:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
public override string Execute(string[] args, UUID fromAgentID)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
if (args.Length < 1)
|
|
|
|
|
return Description;
|
|
|
|
|
|
|
|
|
|
groupName = String.Empty;
|
2008-07-25 05:15:05 +00:00
|
|
|
resolvedGroupID = UUID.Zero;
|
2008-01-05 23:30:50 +00:00
|
|
|
resolvedGroupName = String.Empty;
|
|
|
|
|
|
|
|
|
|
if (args[0].ToLower() == "uuid")
|
|
|
|
|
{
|
|
|
|
|
if (args.Length < 2)
|
|
|
|
|
return Description;
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
if (!UUID.TryParse((resolvedGroupName = groupName = args[1]), out resolvedGroupID))
|
2008-01-05 23:30:50 +00:00
|
|
|
return resolvedGroupName + " doesn't seem a valid UUID";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < args.Length; i++)
|
|
|
|
|
groupName += args[i] + " ";
|
|
|
|
|
groupName = groupName.Trim();
|
|
|
|
|
DirectoryManager.DirGroupsReplyCallback callback = new DirectoryManager.DirGroupsReplyCallback(Directory_OnDirGroupsReply);
|
|
|
|
|
Client.Directory.OnDirGroupsReply += callback;
|
|
|
|
|
queryID = Client.Directory.StartGroupSearch(DirectoryManager.DirFindFlags.Groups, groupName, 0);
|
|
|
|
|
|
|
|
|
|
GetGroupsSearchEvent.WaitOne(60000, false);
|
|
|
|
|
|
|
|
|
|
Client.Directory.OnDirGroupsReply -= callback;
|
|
|
|
|
GetGroupsSearchEvent.Reset();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
if (resolvedGroupID == UUID.Zero)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(resolvedGroupName))
|
|
|
|
|
return "Unable to obtain UUID for group " + groupName;
|
|
|
|
|
else
|
|
|
|
|
return resolvedGroupName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GroupManager.GroupJoinedCallback gcallback = new GroupManager.GroupJoinedCallback(Groups_OnGroupJoined);
|
|
|
|
|
Client.Groups.OnGroupJoined += gcallback;
|
|
|
|
|
Client.Groups.RequestJoinGroup(resolvedGroupID);
|
|
|
|
|
|
|
|
|
|
/* A.Biondi
|
|
|
|
|
* TODO: implement the pay to join procedure.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
GetGroupsSearchEvent.WaitOne(60000, false);
|
|
|
|
|
|
|
|
|
|
Client.Groups.OnGroupJoined -= gcallback;
|
|
|
|
|
GetGroupsSearchEvent.Reset();
|
2009-07-15 23:23:11 +00:00
|
|
|
Client.ReloadGroupsCache();
|
2008-01-05 23:30:50 +00:00
|
|
|
|
|
|
|
|
if (joinedGroup)
|
|
|
|
|
return "Joined the group " + resolvedGroupName;
|
|
|
|
|
return "Unable to join the group " + resolvedGroupName;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Groups_OnGroupJoined(UUID groupID, bool success)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
Console.WriteLine(Client.ToString() + (success ? " joined " : " failed to join ") + groupID.ToString());
|
|
|
|
|
|
|
|
|
|
/* A.Biondi
|
|
|
|
|
* This code is not necessary because it is yet present in the
|
|
|
|
|
* GroupCommand.cs as well. So the new group will be activated by
|
|
|
|
|
* the mentioned command. If the GroupCommand.cs would change,
|
|
|
|
|
* just uncomment the following two lines.
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(Client.ToString() + " setting " + groupID.ToString() + " as the active group");
|
|
|
|
|
Client.Groups.ActivateGroup(groupID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
joinedGroup = success;
|
|
|
|
|
GetGroupsSearchEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-25 05:15:05 +00:00
|
|
|
void Directory_OnDirGroupsReply(UUID queryid, List<DirectoryManager.GroupSearchData> matchedGroups)
|
2008-01-05 23:30:50 +00:00
|
|
|
{
|
|
|
|
|
if (queryID == queryid)
|
|
|
|
|
{
|
2008-07-25 05:15:05 +00:00
|
|
|
queryID = UUID.Zero;
|
2008-01-05 23:30:50 +00:00
|
|
|
if (matchedGroups.Count < 1)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("ERROR: Got an empty reply");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (matchedGroups.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
/* A.Biondi
|
|
|
|
|
* The Group search doesn't work as someone could expect...
|
|
|
|
|
* It'll give back to you a long list of groups even if the
|
|
|
|
|
* searchText (groupName) matches esactly one of the groups
|
|
|
|
|
* names present on the server, so we need to check each result.
|
|
|
|
|
* UUIDs of the matching groups are written on the console.
|
|
|
|
|
*/
|
|
|
|
|
Console.WriteLine("Matching groups are:\n");
|
|
|
|
|
foreach (DirectoryManager.GroupSearchData groupRetrieved in matchedGroups)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(groupRetrieved.GroupName + "\t\t\t(" +
|
|
|
|
|
Name + " UUID " + groupRetrieved.GroupID.ToString() + ")");
|
|
|
|
|
|
|
|
|
|
if (groupRetrieved.GroupName.ToLower() == groupName.ToLower())
|
|
|
|
|
{
|
|
|
|
|
resolvedGroupID = groupRetrieved.GroupID;
|
|
|
|
|
resolvedGroupName = groupRetrieved.GroupName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(resolvedGroupName))
|
|
|
|
|
resolvedGroupName = "Ambiguous name. Found " + matchedGroups.Count.ToString() + " groups (UUIDs on console)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
GetGroupsSearchEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|