From 5dfd504cd4bcdb1bd03d15c59b6ab665e6469f5d Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Wed, 27 Dec 2006 21:55:35 +0000 Subject: [PATCH] * Fixed a bug in SetAvatarInformation() where the AboutText wasn't being set * Added FindSimCommand to TestClient that searches for a simulator name and returns the region handle and X/Y coords * Added CloneProfileCommand to TestClient that demos the avatar profile commands in libsl git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@766 52acb1d6-8a22-11de-b505-999d5b087335 --- libsecondlife-cs/MainAvatar.cs | 1 + .../TestClient/Commands/BalanceCommand.cs | 1 - .../Commands/CloneProfileCommand.cs | 88 +++++++++++++++++++ .../TestClient/Commands/FindSimCommand.cs | 59 +++++++++++++ .../examples/TestClient/TestClient.cs | 10 +-- .../examples/TestClient/TestClient.csproj | 2 + 6 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 libsecondlife-cs/examples/TestClient/Commands/CloneProfileCommand.cs create mode 100644 libsecondlife-cs/examples/TestClient/Commands/FindSimCommand.cs diff --git a/libsecondlife-cs/MainAvatar.cs b/libsecondlife-cs/MainAvatar.cs index 42d1c738..209bebce 100644 --- a/libsecondlife-cs/MainAvatar.cs +++ b/libsecondlife-cs/MainAvatar.cs @@ -384,6 +384,7 @@ namespace libsecondlife apup.AgentData.SessionID = Client.Network.SessionID; apup.PropertiesData = new AvatarPropertiesUpdatePacket.PropertiesDataBlock(); + apup.PropertiesData.AboutText = Helpers.StringToField(this.ProfileProperties.AboutText); apup.PropertiesData.AllowPublish = this.ProfileProperties.AllowPublish; apup.PropertiesData.FLAboutText = Helpers.StringToField(this.ProfileProperties.FirstLifeText); apup.PropertiesData.FLImageID = this.ProfileProperties.FirstLifeImage; diff --git a/libsecondlife-cs/examples/TestClient/Commands/BalanceCommand.cs b/libsecondlife-cs/examples/TestClient/Commands/BalanceCommand.cs index 77622a07..bc50c940 100644 --- a/libsecondlife-cs/examples/TestClient/Commands/BalanceCommand.cs +++ b/libsecondlife-cs/examples/TestClient/Commands/BalanceCommand.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text; using libsecondlife; using libsecondlife.Packets; diff --git a/libsecondlife-cs/examples/TestClient/Commands/CloneProfileCommand.cs b/libsecondlife-cs/examples/TestClient/Commands/CloneProfileCommand.cs new file mode 100644 index 00000000..9b3631d4 --- /dev/null +++ b/libsecondlife-cs/examples/TestClient/Commands/CloneProfileCommand.cs @@ -0,0 +1,88 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using libsecondlife; +using libsecondlife.Packets; + +namespace libsecondlife.TestClient +{ + public class CloneProfileCommand : Command + { + SecondLife Client; + Avatar.Properties Properties; + Avatar.Interests Interests; + bool ReceivedProperties = false; + bool ReceivedInterests = false; + ManualResetEvent ReceivedProfileEvent = new ManualResetEvent(false); + + public CloneProfileCommand(TestClient testClient) + { + TestClient = testClient; + Client = (SecondLife)TestClient; + + Client.Avatars.OnAvatarInterests += new AvatarManager.AvatarInterestsCallback(Avatars_OnAvatarInterests); + Client.Avatars.OnAvatarProperties += new AvatarManager.AvatarPropertiesCallback(Avatars_OnAvatarProperties); + + Name = "cloneprofile"; + Description = "Clones another avatars profile as closely as possible. WARNING: This command will " + + "destroy your existing profile! Usage: cloneprofile [targetuuid]"; + } + + public override string Execute(string[] args, LLUUID fromAgentID) + { + if (args.Length != 1) + return Description; + + LLUUID targetID; + ReceivedProperties = false; + ReceivedInterests = false; + + try + { + targetID = new LLUUID(args[0]); + } + catch (Exception) + { + return Description; + } + + Client.Avatars.RequestAvatarProperties(targetID); + + ReceivedProfileEvent.Reset(); + ReceivedProfileEvent.WaitOne(5000, false); + + if (!ReceivedInterests || !ReceivedProperties) + return "Failed to retrieve a complete profile for that UUID"; + + Client.Self.ProfileInterests = Interests; + Client.Self.ProfileProperties = Properties; + Client.Self.SetAvatarInformation(); + + return "Synchronized our profile to the profile of " + targetID.ToStringHyphenated(); + } + + void Avatars_OnAvatarProperties(LLUUID avatarID, Avatar.Properties properties) + { + lock (ReceivedProfileEvent) + { + Properties = properties; + ReceivedProperties = true; + + if (ReceivedInterests && ReceivedProperties) + ReceivedProfileEvent.Set(); + } + } + + void Avatars_OnAvatarInterests(LLUUID avatarID, Avatar.Interests interests) + { + lock (ReceivedProfileEvent) + { + Interests = interests; + ReceivedInterests = true; + + if (ReceivedInterests && ReceivedProperties) + ReceivedProfileEvent.Set(); + } + } + } +} diff --git a/libsecondlife-cs/examples/TestClient/Commands/FindSimCommand.cs b/libsecondlife-cs/examples/TestClient/Commands/FindSimCommand.cs new file mode 100644 index 00000000..dfffe27e --- /dev/null +++ b/libsecondlife-cs/examples/TestClient/Commands/FindSimCommand.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using libsecondlife.Packets; + +namespace libsecondlife.TestClient +{ + public class FindSimCommand : Command + { + SecondLife Client; + Dictionary GridDataCached = new Dictionary(); + + public FindSimCommand(TestClient testClient) + { + TestClient = testClient; + Client = (SecondLife)TestClient; + + Name = "findsim"; + Description = "Searches for a simulator and returns information about it. Usage: findsim [Simulator Name]"; + } + + public override string Execute(string[] args, LLUUID fromAgentID) + { + if (args.Length < 1) + return "Usage: findsim [Simulator Name]"; + + string simName = string.Empty; + for (int i = 0; i < args.Length; i++) + simName += args[i] + " "; + simName = simName.TrimEnd().ToLower(); + + if (!GridDataCached.ContainsKey(Client)) + { + GridDataCached[Client] = false; + } + + if (!GridDataCached[Client]) + { + Client.Grid.AddAllSims(); + System.Threading.Thread.Sleep(5000); + GridDataCached[Client] = true; + } + + int attempts = 0; + GridRegion region = null; + while (region == null && attempts++ < 5) + { + region = Client.Grid.GetGridRegion(simName); + } + + if (region != null) + return "Found " + region.Name + ": handle=" + region.RegionHandle + + "(" + region.X + "," + region.Y + ")"; + else + return "Lookup of " + simName + " failed"; + } + } +} diff --git a/libsecondlife-cs/examples/TestClient/TestClient.cs b/libsecondlife-cs/examples/TestClient/TestClient.cs index 11ce5c0b..f38b8707 100644 --- a/libsecondlife-cs/examples/TestClient/TestClient.cs +++ b/libsecondlife-cs/examples/TestClient/TestClient.cs @@ -10,6 +10,10 @@ namespace libsecondlife.TestClient { public class TestClient : SecondLife { + public delegate void PrimCreatedCallback(Simulator simulator, PrimObject prim); + + public event PrimCreatedCallback OnPrimCreated; + public Dictionary> SimPrims; public LLUUID GroupID = LLUUID.Zero; public Dictionary GroupMembers; @@ -18,12 +22,9 @@ namespace libsecondlife.TestClient public Dictionary Commands = new Dictionary(); public Dictionary SharedValues = new Dictionary(); public bool Running = true; - public string Master = ""; + public string Master = String.Empty; public ClientManager ClientManager; - public delegate void PrimCreatedCallback(Simulator simulator, PrimObject prim); - public event PrimCreatedCallback OnPrimCreated; - private LLQuaternion bodyRotation = LLQuaternion.Identity; private LLVector3 forward = new LLVector3(0, 0.9999f, 0); private LLVector3 left = new LLVector3(0.9999f, 0, 0); @@ -31,7 +32,6 @@ namespace libsecondlife.TestClient private int DrawDistance = 64; private System.Timers.Timer updateTimer; - /// /// /// diff --git a/libsecondlife-cs/examples/TestClient/TestClient.csproj b/libsecondlife-cs/examples/TestClient/TestClient.csproj index e9a84393..ded9a07d 100644 --- a/libsecondlife-cs/examples/TestClient/TestClient.csproj +++ b/libsecondlife-cs/examples/TestClient/TestClient.csproj @@ -37,8 +37,10 @@ + + Code