Moving examples, mapgenerator, and VisualParamGenerator to Programs folder (SVN is seriously ruined still, don't check out yet)

git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@1961 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
John Hurliman
2008-07-22 23:21:49 +00:00
parent ef71c02528
commit f2dde3daae
153 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
/// <summary>
/// Changes Avatars currently active group
/// </summary>
public class ActivateGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
Dictionary<LLUUID, Group> groups = new Dictionary<LLUUID, Group>();
string activeGroup;
public ActivateGroupCommand(TestClient testClient)
{
Name = "activategroup";
Description = "Set a group as active. Usage: activategroup GroupName";
}
public override string Execute(string[] args, LLUUID fromAgentID)
{
if (args.Length < 1)
return Description;
groups.Clear();
activeGroup = string.Empty;
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
GroupManager.CurrentGroupsCallback callback = new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Client.Groups.OnCurrentGroups += callback;
Client.Groups.RequestCurrentGroups();
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnCurrentGroups -= callback;
GroupsEvent.Reset();
if (groups.Count > 0)
{
foreach (Group currentGroup in groups.Values)
if (currentGroup.Name.ToLower() == groupName.ToLower())
{
NetworkManager.PacketCallback pcallback = new NetworkManager.PacketCallback(AgentDataUpdateHandler);
Client.Network.RegisterCallback(PacketType.AgentDataUpdate, pcallback);
Console.WriteLine("setting " + currentGroup.Name + " as active group");
Client.Groups.ActivateGroup(currentGroup.ID);
GroupsEvent.WaitOne(30000, false);
Client.Network.UnregisterCallback(PacketType.AgentDataUpdate, pcallback);
GroupsEvent.Reset();
/* A.Biondi
* TODO: Handle titles choosing.
*/
if (String.IsNullOrEmpty(activeGroup))
return Client.ToString() + " failed to activate the group " + groupName;
return "Active group is now " + activeGroup;
}
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
}
return Client.ToString() + " doesn't seem member of any group";
}
void Groups_OnCurrentGroups(Dictionary<LLUUID, Group> cGroups)
{
groups = cGroups;
GroupsEvent.Set();
}
private void AgentDataUpdateHandler(Packet packet, Simulator sim)
{
AgentDataUpdatePacket p = (AgentDataUpdatePacket)packet;
if (p.AgentData.AgentID == Client.Self.AgentID)
{
activeGroup = Helpers.FieldToUTF8String(p.AgentData.GroupName) + " ( " + Helpers.FieldToUTF8String(p.AgentData.GroupTitle) + " )";
GroupsEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
public class GroupsCommand : Command
{
ManualResetEvent GetCurrentGroupsEvent = new ManualResetEvent(false);
Dictionary<LLUUID, Group> groups = new Dictionary<LLUUID, Group>();
public GroupsCommand(TestClient testClient)
{
testClient.Groups.OnCurrentGroups += new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Name = "groups";
Description = "List avatar groups. Usage: groups";
}
public override string Execute(string[] args, LLUUID fromAgentID)
{
if (groups.Count == 0)
{
Client.Groups.RequestCurrentGroups();
GetCurrentGroupsEvent.WaitOne(10000, false);
}
if (groups.Count > 0)
{
return getGroupsString();
}
else
{
return "No groups";
}
}
void Groups_OnCurrentGroups(Dictionary<LLUUID, Group> pGroups)
{
groups = pGroups;
GetCurrentGroupsEvent.Set();
}
string getGroupsString()
{
StringBuilder sb = new StringBuilder();
foreach (Group group in groups.Values)
{
sb.AppendLine(group.Name + " " + group.ID);
}
return sb.ToString();
}
}
}

View File

@@ -0,0 +1,147 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
public class JoinGroupCommand : Command
{
ManualResetEvent GetGroupsSearchEvent = new ManualResetEvent(false);
private LLUUID queryID = LLUUID.Zero;
private LLUUID resolvedGroupID;
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";
}
public override string Execute(string[] args, LLUUID fromAgentID)
{
if (args.Length < 1)
return Description;
groupName = String.Empty;
resolvedGroupID = LLUUID.Zero;
resolvedGroupName = String.Empty;
if (args[0].ToLower() == "uuid")
{
if (args.Length < 2)
return Description;
if (!LLUUID.TryParse((resolvedGroupName = groupName = args[1]), out resolvedGroupID))
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();
}
if (resolvedGroupID == LLUUID.Zero)
{
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();
if (joinedGroup)
return "Joined the group " + resolvedGroupName;
return "Unable to join the group " + resolvedGroupName;
}
void Groups_OnGroupJoined(LLUUID groupID, bool success)
{
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();
}
void Directory_OnDirGroupsReply(LLUUID queryid, List<DirectoryManager.GroupSearchData> matchedGroups)
{
if (queryID == queryid)
{
queryID = LLUUID.Zero;
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();
}
}
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Packets;
using System.Text;
namespace OpenMetaverse.TestClient
{
public class LeaveGroupCommand : Command
{
ManualResetEvent GroupsEvent = new ManualResetEvent(false);
Dictionary<LLUUID, Group> groups = new Dictionary<LLUUID, Group>();
private bool leftGroup;
public LeaveGroupCommand(TestClient testClient)
{
Name = "leavegroup";
Description = "Leave a group. Usage: leavegroup GroupName";
}
public override string Execute(string[] args, LLUUID fromAgentID)
{
if (args.Length < 1)
return Description;
groups.Clear();
string groupName = String.Empty;
for (int i = 0; i < args.Length; i++)
groupName += args[i] + " ";
groupName = groupName.Trim();
GroupManager.CurrentGroupsCallback callback = new GroupManager.CurrentGroupsCallback(Groups_OnCurrentGroups);
Client.Groups.OnCurrentGroups += callback;
Client.Groups.RequestCurrentGroups();
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnCurrentGroups -= callback;
GroupsEvent.Reset();
if (groups.Count > 0)
{
foreach (Group currentGroup in groups.Values)
if (currentGroup.Name.ToLower() == groupName.ToLower())
{
GroupManager.GroupLeftCallback lcallback = new GroupManager.GroupLeftCallback(Groups_OnGroupLeft);
Client.Groups.OnGroupLeft += lcallback;
Client.Groups.LeaveGroup(currentGroup.ID);
/* A.Biondi
* TODO: modify GroupsCommand.cs
* GroupsCommand.cs doesn't refresh the groups list until a new
* CurrentGroupsCallback occurs, so if you'd issue the command
* 'Groups' right after have left a group, it'll display still yet
* the group you just left (unless you have 0 groups, because it
* would force the refresh with Client.Groups.RequestCurrentGroups).
*/
GroupsEvent.WaitOne(30000, false);
Client.Groups.OnGroupLeft -= lcallback;
GroupsEvent.Reset();
if (leftGroup)
return Client.ToString() + " has left the group " + groupName;
return "failed to left the group " + groupName;
}
return Client.ToString() + " doesn't seem to be member of the group " + groupName;
}
return Client.ToString() + " doesn't seem member of any group";
}
void Groups_OnCurrentGroups(Dictionary<LLUUID, Group> cGroups)
{
groups = cGroups;
GroupsEvent.Set();
}
void Groups_OnGroupLeft(LLUUID groupID, bool success)
{
Console.WriteLine(Client.ToString() + (success ? " has left group " : " failed to left group ") + groupID.ToString());
leftGroup = success;
GroupsEvent.Set();
}
}
}