LIBOMV-686 Implements new event patterns based on the Microsoft Framework Design Guidelines in AvatarManager

* BREAKING CHANGE * this is a major shift in the way events are internally handled.
* TODO: need to complete the EventArgs class documentation
* Adds new TestClient commands "play" to play animations, and bots to detect other bots.

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3163 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Jim Radford
2009-10-22 04:29:25 +00:00
parent b0cb77e1e5
commit 0f8677cee9
12 changed files with 1187 additions and 462 deletions

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace OpenMetaverse.TestClient
{
public class BotsCommand : Command
{
private Dictionary<UUID, bool> m_AgentList = new Dictionary<UUID, bool>();
public BotsCommand(TestClient testClient)
{
Name = "bots";
Description = "detects avatars that appear to be bots.";
Category = CommandCategory.Other;
testClient.Avatars.ViewerEffect += new EventHandler<ViewerEffectEventArgs>(Avatars_ViewerEffect);
testClient.Avatars.ViewerEffectLookAt += new EventHandler<ViewerEffectLookAtEventArgs>(Avatars_ViewerEffectLookAt);
testClient.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
}
void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
}
}
void Avatars_ViewerEffectLookAt(object sender, ViewerEffectLookAtEventArgs e)
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
}
}
void Avatars_ViewerEffect(object sender, ViewerEffectEventArgs e)
{
lock (m_AgentList)
{
if (m_AgentList.ContainsKey(e.SourceID))
m_AgentList[e.SourceID] = true;
else
m_AgentList.Add(e.SourceID, true);
}
}
public override string Execute(string[] args, UUID fromAgentID)
{
StringBuilder result = new StringBuilder();
lock (Client.Network.Simulators)
{
for (int i = 0; i < Client.Network.Simulators.Count; i++)
{
Client.Network.Simulators[i].ObjectsAvatars.ForEach(
delegate(Avatar av)
{
lock (m_AgentList)
{
if (!m_AgentList.ContainsKey(av.ID))
{
result.AppendLine();
result.AppendFormat("{0} (Group: {1}, Location: {2}, UUID: {3} LocalID: {4}) Is Probably a bot",
av.Name, av.GroupName, av.Position, av.ID, av.LocalID);
}
}
}
);
}
}
return result.ToString();
}
}
}

View File

@@ -18,20 +18,19 @@ namespace OpenMetaverse.TestClient
public CloneProfileCommand(TestClient testClient)
{
testClient.Avatars.OnAvatarInterests += new AvatarManager.AvatarInterestsCallback(Avatars_OnAvatarInterests);
testClient.Avatars.OnAvatarProperties += new AvatarManager.AvatarPropertiesCallback(Avatars_OnAvatarProperties);
testClient.Avatars.OnAvatarGroups += new AvatarManager.AvatarGroupsCallback(Avatars_OnAvatarGroups);
testClient.Avatars.AvatarInterestsReply += new EventHandler<AvatarInterestsReplyEventArgs>(Avatars_AvatarInterestsReply);
testClient.Avatars.AvatarPropertiesReply += new EventHandler<AvatarPropertiesReplyEventArgs>(Avatars_AvatarPropertiesReply);
testClient.Avatars.AvatarGroupsReply += new EventHandler<AvatarGroupsReplyEventArgs>(Avatars_AvatarGroupsReply);
testClient.Groups.GroupJoinedReply += new EventHandler<GroupOperationEventArgs>(Groups_OnGroupJoined);
testClient.Avatars.OnAvatarPicks += new AvatarManager.AvatarPicksCallback(Avatars_OnAvatarPicks);
testClient.Avatars.OnPickInfo += new AvatarManager.PickInfoCallback(Avatars_OnPickInfo);
testClient.Avatars.AvatarPicksReply += new EventHandler<AvatarPicksReplyEventArgs>(Avatars_AvatarPicksReply);
testClient.Avatars.PickInfoReply += new EventHandler<PickInfoReplyEventArgs>(Avatars_PickInfoReply);
Name = "cloneprofile";
Description = "Clones another avatars profile as closely as possible. WARNING: This command will " +
"destroy your existing profile! Usage: cloneprofile [targetuuid]";
Category = CommandCategory.Other;
}
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length != 1)
@@ -80,67 +79,7 @@ namespace OpenMetaverse.TestClient
}
return "Synchronized our profile to the profile of " + targetID.ToString();
}
void Avatars_OnAvatarPicks(UUID avatarid, Dictionary<UUID, string> picks)
{
foreach (KeyValuePair<UUID, string> kvp in picks)
{
if (avatarid == Client.Self.AgentID)
{
Client.Self.PickDelete(kvp.Key);
}
else
{
Client.Avatars.RequestPickInfo(avatarid, kvp.Key);
}
}
}
void Avatars_OnPickInfo(UUID pickid, ProfilePick pick)
{
Client.Self.PickInfoUpdate(pickid, pick.TopPick, pick.ParcelID, pick.Name, pick.PosGlobal, pick.SnapshotID, pick.Desc);
}
void Avatars_OnAvatarProperties(UUID avatarID, Avatar.AvatarProperties properties)
{
lock (ReceivedProfileEvent)
{
Properties = properties;
ReceivedProperties = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
void Avatars_OnAvatarInterests(UUID avatarID, Avatar.Interests interests)
{
lock (ReceivedProfileEvent)
{
Interests = interests;
ReceivedInterests = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
void Avatars_OnAvatarGroups(UUID avatarID, List<AvatarGroup> groups)
{
lock (ReceivedProfileEvent)
{
foreach (AvatarGroup group in groups)
{
Groups.Add(group.GroupID);
}
ReceivedGroups = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
}
void Groups_OnGroupJoined(object sender, GroupOperationEventArgs e)
{
@@ -154,5 +93,67 @@ namespace OpenMetaverse.TestClient
Client.Groups.ActivateGroup(e.GroupID);
}
}
void Avatars_PickInfoReply(object sender, PickInfoReplyEventArgs e)
{
Client.Self.PickInfoUpdate(e.PickID, e.Pick.TopPick, e.Pick.ParcelID, e.Pick.Name, e.Pick.PosGlobal, e.Pick.SnapshotID, e.Pick.Desc);
}
void Avatars_AvatarPicksReply(object sender, AvatarPicksReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> kvp in e.Picks)
{
if (e.AvatarID == Client.Self.AgentID)
{
Client.Self.PickDelete(kvp.Key);
}
else
{
Client.Avatars.RequestPickInfo(e.AvatarID, kvp.Key);
}
}
}
void Avatars_AvatarGroupsReply(object sender, AvatarGroupsReplyEventArgs e)
{
lock (ReceivedProfileEvent)
{
foreach (AvatarGroup group in e.Groups)
{
Groups.Add(group.GroupID);
}
ReceivedGroups = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
void Avatars_AvatarPropertiesReply(object sender, AvatarPropertiesReplyEventArgs e)
{
lock (ReceivedProfileEvent)
{
Properties = e.Properties;
ReceivedProperties = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
void Avatars_AvatarInterestsReply(object sender, AvatarInterestsReplyEventArgs e)
{
lock (ReceivedProfileEvent)
{
Interests = e.Interests;
ReceivedInterests = true;
if (ReceivedInterests && ReceivedProperties && ReceivedGroups)
ReceivedProfileEvent.Set();
}
}
}
}

View File

@@ -0,0 +1,90 @@
using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
using OpenMetaverse;
using OpenMetaverse.Packets;
namespace OpenMetaverse.TestClient
{
public class PlayAnimationCommand : Command
{
private Dictionary<UUID, string> m_BuiltInAnimations = new Dictionary<UUID, string>();
public PlayAnimationCommand(TestClient testClient)
{
Name = "play";
Description = "Attempts to play an animation";
Category = CommandCategory.Appearance;
Type t = typeof(Animations);
FieldInfo[] f = t.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (FieldInfo field in f)
{
m_BuiltInAnimations.Add((UUID)field.GetValue(t), field.Name);
}
Console.WriteLine(f);
}
private string Usage()
{
String usage = "Usage:\n" +
"\tplay list - list the built in animations\n" +
"\tplay show - show any currently playing animations\n" +
"\tplay UUID - play an animation asset\n" +
"\tplay ANIMATION - where ANIMATION is one of the values returned from \"play list\"\n";
return usage;
}
public override string Execute(string[] args, UUID fromAgentID)
{
StringBuilder result = new StringBuilder();
if (args.Length != 1)
return Usage();
UUID animationID;
string arg = args[0].Trim();
if (UUID.TryParse(args[0], out animationID))
{
Client.Self.AnimationStart(animationID, true);
}
else if (arg.ToLower().Equals("list"))
{
foreach (string key in m_BuiltInAnimations.Values)
{
result.AppendLine(key);
}
}
else if (arg.ToLower().Equals("show"))
{
Client.Self.SignaledAnimations.ForEach(delegate(KeyValuePair<UUID, int> kvp) {
if (m_BuiltInAnimations.ContainsKey(kvp.Key))
{
result.AppendFormat("The {0} System Animation is being played, sequence is {1}", m_BuiltInAnimations[kvp.Key], kvp.Value);
}
else
{
result.AppendFormat("The {0} Asset Animation is being played, sequence is {0}", kvp.Key, kvp.Value);
}
});
}
else if (m_BuiltInAnimations.ContainsValue(args[0].Trim().ToUpper()))
{
foreach (var kvp in m_BuiltInAnimations)
{
if (kvp.Value.Equals(arg.ToUpper()))
{
Client.Self.AnimationStart(kvp.Key, true);
break;
}
}
}
else
{
return Usage();
}
return result.ToString();
}
}
}

View File

@@ -14,13 +14,13 @@ namespace OpenMetaverse.TestClient
public ImCommand(TestClient testClient)
{
testClient.Avatars.OnAvatarNameSearch += new AvatarManager.AvatarNameSearchCallback(Avatars_OnAvatarNameSearch);
testClient.Avatars.AvatarPickerReply += Avatars_AvatarPickerReply;
Name = "im";
Description = "Instant message someone. Usage: im [firstname] [lastname] [message]";
Category = CommandCategory.Communication;
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 3)
@@ -56,9 +56,9 @@ namespace OpenMetaverse.TestClient
}
}
void Avatars_OnAvatarNameSearch(UUID queryID, Dictionary<UUID, string> avatars)
void Avatars_AvatarPickerReply(object sender, AvatarPickerReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> kvp in avatars)
foreach (KeyValuePair<UUID, string> kvp in e.Avatars)
{
if (kvp.Value.ToLower() == ToAvatarName.ToLower())
{

View File

@@ -28,7 +28,7 @@ namespace OpenMetaverse.TestClient.Commands
result.Remove(0, result.Length);
waitQuery.Reset();
Client.Avatars.OnAvatarNames += Avatars_OnAvatarNames;
Client.Avatars.UUIDNameReply += Avatars_OnAvatarNames;
Client.Groups.GroupProfile += Groups_OnGroupProfile;
Client.Avatars.RequestAvatarName(key);
@@ -38,7 +38,7 @@ namespace OpenMetaverse.TestClient.Commands
result.AppendLine("Timeout waiting for reply, this could mean the Key is not an avatar or a group");
}
Client.Avatars.OnAvatarNames -= Avatars_OnAvatarNames;
Client.Avatars.UUIDNameReply -= Avatars_OnAvatarNames;
Client.Groups.GroupProfile -= Groups_OnGroupProfile;
return result.ToString();
}
@@ -49,9 +49,9 @@ namespace OpenMetaverse.TestClient.Commands
waitQuery.Set();
}
void Avatars_OnAvatarNames(Dictionary<UUID, string> names)
void Avatars_OnAvatarNames(object sender, UUIDNameReplyEventArgs e)
{
foreach (KeyValuePair<UUID, string> kvp in names)
foreach (KeyValuePair<UUID, string> kvp in e.Names)
result.AppendLine("Avatar: " + kvp.Value + " " + kvp.Key);
waitQuery.Set();
}

View File

@@ -23,13 +23,22 @@ namespace OpenMetaverse.TestClient
{
testClient.Objects.OnObjectPropertiesFamily += new ObjectManager.ObjectPropertiesFamilyCallback(Objects_OnObjectPropertiesFamily);
testClient.Objects.OnObjectProperties += new ObjectManager.ObjectPropertiesCallback(Objects_OnObjectProperties);
testClient.Avatars.OnPointAt += new AvatarManager.PointAtCallback(Avatars_OnPointAt);
testClient.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
Name = "export";
Description = "Exports an object to an xml file. Usage: export uuid outputfile.xml";
Category = CommandCategory.Objects;
}
void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
{
if (e.SourceID == Client.MasterKey)
{
//Client.DebugLog("Master is now selecting " + targetID.ToString());
SelectedObject = e.TargetID;
}
}
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length != 2 && !(args.Length == 1 && SelectedObject != UUID.Zero))
@@ -211,16 +220,6 @@ namespace OpenMetaverse.TestClient
}
}
void Avatars_OnPointAt(UUID sourceID, UUID targetID, Vector3d targetPos,
PointAtType pointType, float duration, UUID id)
{
if (sourceID == Client.MasterKey)
{
//Client.DebugLog("Master is now selecting " + targetID.ToString());
SelectedObject = targetID;
}
}
void Objects_OnObjectPropertiesFamily(Simulator simulator, Primitive.ObjectProperties properties,
ReportType type)
{

View File

@@ -13,9 +13,36 @@ namespace OpenMetaverse.TestClient
Description = "Prints out information for every viewer effect that is received. Usage: showeffects [on/off]";
Category = CommandCategory.Other;
testClient.Avatars.OnEffect += new AvatarManager.EffectCallback(Avatars_OnEffect);
testClient.Avatars.OnLookAt += new AvatarManager.LookAtCallback(Avatars_OnLookAt);
testClient.Avatars.OnPointAt += new AvatarManager.PointAtCallback(Avatars_OnPointAt);
testClient.Avatars.ViewerEffect += new EventHandler<ViewerEffectEventArgs>(Avatars_ViewerEffect);
testClient.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
testClient.Avatars.ViewerEffectLookAt += new EventHandler<ViewerEffectLookAtEventArgs>(Avatars_ViewerEffectLookAt);
}
void Avatars_ViewerEffectLookAt(object sender, ViewerEffectLookAtEventArgs e)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [LookAt]: SourceID: {0} TargetID: {1} TargetPos: {2} Type: {3} Duration: {4} ID: {5}",
e.SourceID.ToString(), e.TargetID.ToString(), e.TargetPosition, e.LookType, e.Duration,
e.EffectID.ToString());
}
void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [PointAt]: SourceID: {0} TargetID: {1} TargetPos: {2} Type: {3} Duration: {4} ID: {5}",
e.SourceID.ToString(), e.TargetID.ToString(), e.TargetPosition, e.PointType, e.Duration,
e.EffectID.ToString());
}
void Avatars_ViewerEffect(object sender, ViewerEffectEventArgs e)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [{0}]: SourceID: {1} TargetID: {2} TargetPos: {3} Duration: {4} ID: {5}",
e.Type, e.SourceID.ToString(), e.TargetID.ToString(), e.TargetPosition, e.Duration,
e.EffectID.ToString());
}
public override string Execute(string[] args, UUID fromAgentID)
@@ -42,36 +69,7 @@ namespace OpenMetaverse.TestClient
{
return "Usage: showeffects [on/off]";
}
}
}
private void Avatars_OnPointAt(UUID sourceID, UUID targetID, Vector3d targetPos,
PointAtType pointType, float duration, UUID id)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [PointAt]: SourceID: {0} TargetID: {1} TargetPos: {2} Type: {3} Duration: {4} ID: {5}",
sourceID.ToString(), targetID.ToString(), targetPos, pointType, duration,
id.ToString());
}
private void Avatars_OnLookAt(UUID sourceID, UUID targetID, Vector3d targetPos,
LookAtType lookType, float duration, UUID id)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [LookAt]: SourceID: {0} TargetID: {1} TargetPos: {2} Type: {3} Duration: {4} ID: {5}",
sourceID.ToString(), targetID.ToString(), targetPos, lookType, duration,
id.ToString());
}
private void Avatars_OnEffect(EffectType type, UUID sourceID, UUID targetID,
Vector3d targetPos, float duration, UUID id)
{
if (ShowEffects)
Console.WriteLine(
"ViewerEffect [{0}]: SourceID: {1} TargetID: {2} TargetPos: {3} Duration: {4} ID: {5}",
type, sourceID.ToString(), targetID.ToString(), targetPos, duration,
id.ToString());
}
}
}