This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| fuss:libopenmetaverse [2015/01/05 23:46] – [Extract Full Avatar Name] office | fuss:libopenmetaverse [2025/10/21 23:26] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ======== Role UUID to Name ======== | + | ====== Extract Full Avatar Name ====== | 
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Resolves a role name to a role UUID. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool RoleUUIDToName(UUID RoleUUID, UUID GroupUUID, int millisecondsTimeout, | + | |
| - | { | + | |
| - | string localRoleName = roleName; | + | |
| - |     var GroupRoleDataEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - | { | + | |
| - |         foreach (var kvp in s.Roles.Where(kvp => kvp.Key.Equals(RoleUUID))) { localRoleName = kvp.Value.Name; | + | |
| - |         GroupRoleDataEvent.Set(); | + | |
| - | }; | + | |
| - |     Client.Groups.GroupRoleDataReply += GroupRoleDataReplyDelegate; | + | |
| - |     Client.Groups.RequestGroupRoles(GroupUUID); | + | |
| - |     if (GroupRoleDataEvent.WaitOne(millisecondsTimeout, | + | |
| - | { | + | |
| - |         Client.Groups.GroupRoleDataReply -= GroupRoleDataReplyDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Groups.GroupRoleDataReply -= GroupRoleDataReplyDelegate; | + | |
| - |     roleName = localRoleName; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Role Name to Role UUID ======== | + | |
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Resolves a role name to a role UUID. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool RoleNameToRoleUUID(string roleName, UUID groupUUID, int millisecondsTimeout, | + | |
| - | var localRoleUUID = roleUUID; | + | |
| - |     var GroupRoleDataEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - | foreach(var kvp in s.Roles.Where(kvp => kvp.Value.Name.Equals(roleName))) { | + | |
| - | localRoleUUID = kvp.Key; | + | |
| - | } | + | |
| - |         GroupRoleDataEvent.Set(); | + | |
| - | }; | + | |
| - |     roleUUID = localRoleUUID; | + | |
| - |     Client.Groups.GroupRoleDataReply += GroupRoleDataReplyDelegate; | + | |
| - |     Client.Groups.RequestGroupRoles(groupUUID); | + | |
| - |     if(!GroupRoleDataEvent.WaitOne(millisecondsTimeout, | + | |
| - |         Client.Groups.GroupRoleDataReply -= GroupRoleDataReplyDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Groups.GroupRoleDataReply -= GroupRoleDataReplyDelegate; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Determine if an Agent is in a Group ======== | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Determines whether an agent referenced by an UUID is in a group | + | |
| - | /// referenced by an UUID. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool AgentInGroup(UUID AgentUUID, UUID GroupUUID, int millisecondsTimeout) { | + | |
| - | var agentInGroup = false; | + | |
| - |     var GroupsEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - | if (s.Members.Any(kvp => kvp.Key.Equals(AgentUUID))) { agentInGroup = true; } | + | |
| - |         GroupsEvent.Set(); | + | |
| - | }; | + | |
| - |     Client.Groups.GroupMembersReply += HandleGroupMembersReplyDelegate; | + | |
| - |     Client.Groups.RequestGroupMembers(GroupUUID); | + | |
| - |     GroupsEvent.WaitOne(millisecondsTimeout, | + | |
| - |     Client.Groups.GroupMembersReply -= HandleGroupMembersReplyDelegate; | + | |
| - |     return agentInGroup; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Agent UUID to Name ======== | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Resolves an agent UUID to an agent name. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool AgentUUIDToName(UUID agentUUID, int millisecondsTimeout, | + | |
| - |     var localAgentName = agentName; | + | |
| - |     var agentNameEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - | foreach(var agent in s.Names.Where(kvp => !kvp.Value.Equals(string.Empty))) { | + | |
| - |             localAgentName = agent.Value; | + | |
| - | } | + | |
| - |         agentNameEvent.Set(); | + | |
| - | }; | + | |
| - |     Client.Avatars.UUIDNameReply += UUIDNameReplyDelegate; | + | |
| - |     Client.Avatars.RequestAvatarName(agentUUID); | + | |
| - |     if(!agentNameEvent.WaitOne(millisecondsTimeout, | + | |
| - |         Client.Avatars.UUIDNameReply -= UUIDNameReplyDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Avatars.UUIDNameReply -= UUIDNameReplyDelegate; | + | |
| - |     agentName = localAgentName; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Agent Name to UUID ======== | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Resolves an agent name to an agent UUID by searching the directory | + | |
| - | /// services. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool AgentNameToUUID(string agentFirstName, | + | |
| - |     var localAgentUUID = agentUUID; | + | |
| - |     var agentUUIDEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - |         Parallel.ForEach(s.MatchedPeople.Where(match => match.FirstName.Equals(agentFirstName) && match.LastName.Equals(agentLastName)), | + | |
| - |         agentUUIDEvent.Set(); | + | |
| - | }; | + | |
| - |     Client.Directory.DirPeopleReply += DirPeopleReplyDelegate; | + | |
| - |     Client.Directory.StartPeopleSearch(String.Format(CultureInfo.InvariantCulture, | + | |
| - |     if(!agentUUIDEvent.WaitOne(millisecondsTimeout, | + | |
| - |         Client.Directory.DirPeopleReply -= DirPeopleReplyDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Directory.DirPeopleReply -= DirPeopleReplyDelegate; | + | |
| - |     agentUUID = localAgentUUID; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | + | ||
| - | ======== Group UUID to Name ======== | + | |
| - | + | ||
| - | Performed by concurrently searching current groups and the directory and accepting whichever answer comes first. | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Resolves a group UUID. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool GroupUUIDToName(UUID groupUUID, int millisecondsTimeout, | + | |
| - |     var localGroupName = groupName; | + | |
| - |     var GroupNameEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - |         localGroupName = s.Group.Name; | + | |
| - |         GroupNameEvent.Set(); | + | |
| - | }; | + | |
| - |     Client.Groups.GroupProfile += GroupProfileDelegate; | + | |
| - |     Client.Groups.RequestGroupProfile(groupUUID); | + | |
| - |     if(!GroupNameEvent.WaitOne(millisecondsTimeout, | + | |
| - |         Client.Groups.GroupProfile -= GroupProfileDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Groups.GroupProfile -= GroupProfileDelegate; | + | |
| - |     groupName = localGroupName; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Find UUID of Inventory Item ======== | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// /// | + | |
| - | /// < | + | |
| - | /// Finds an inventory item starting from a given root folder and | + | |
| - | ///      | + | |
| - | /// as setting itemUUID to the UUID of the found item. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | static bool SearchInventoryItem(InventoryFolder rootFolder, string itemName, ref UUID itemUUID, int millisecondsTimeout) | + | |
| - | { | + | |
| - |     List< | + | |
| - |         true, true, InventorySortOrder.ByName, | + | |
| - | + | ||
| - | if (contents == null) return false; | + | |
| - | + | ||
| - | foreach (InventoryBase i in contents) | + | |
| - | { | + | |
| - | if (i.Name.Equals(itemName)) | + | |
| - | { | + | |
| - | itemUUID = i.UUID; | + | |
| - | return true; | + | |
| - | } | + | |
| - | + | ||
| - |         var inventoryFolder = i as InventoryFolder; | + | |
| - | if (inventoryFolder == null) continue; | + | |
| - |         SearchInventoryItem(inventoryFolder, | + | |
| - | } | + | |
| - | + | ||
| - | return false; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | ======== Get Parcel of a Simulator at a Given Position ======== | + | |
| - | + | ||
| - | The following function will store a parcel given a simulator and a position: | + | |
| - | + | ||
| - | <code csharp> | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // | + | |
| - | /////////////////////////////////////////////////////////////////////////// | + | |
| - | /// < | + | |
| - | /// Get the parcel of a simulator given a position. | + | |
| - | /// </ | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// <param name=" | + | |
| - | /// < | + | |
| - | private static bool GetParcelAtPosition(Simulator simulator, Vector3 position, int millisecondsTimeout, | + | |
| - | { | + | |
| - | Parcel localParcel = null; | + | |
| - |     var RequestAllSimParcelsEvent = new ManualResetEvent(false); | + | |
| - |     EventHandler< | + | |
| - |     Client.Parcels.SimParcelsDownloaded += SimParcelsDownloadedDelegate; | + | |
| - |     Client.Parcels.RequestAllSimParcels(simulator, | + | |
| - |     if (!RequestAllSimParcelsEvent.WaitOne(millisecondsTimeout * simulator.Stats.LastLag, | + | |
| - | { | + | |
| - |         Client.Parcels.SimParcelsDownloaded -= SimParcelsDownloadedDelegate; | + | |
| - | return false; | + | |
| - | } | + | |
| - |     Client.Parcels.SimParcelsDownloaded -= SimParcelsDownloadedDelegate; | + | |
| - | Client.Network.CurrentSim.Parcels.ForEach(delegate(Parcel currentParcel) | + | |
| - | { | + | |
| - | if (!(position.X >= currentParcel.AABBMin.X) || !(position.X <= currentParcel.AABBMax.X) || | + | |
| - | !(position.Y >= currentParcel.AABBMin.Y) || !(position.Y <= currentParcel.AABBMax.Y)) return; | + | |
| - |         localParcel = currentParcel; | + | |
| - | }); | + | |
| - | if (localParcel == null) return false; | + | |
| - |     parcel = localParcel; | + | |
| - | return true; | + | |
| - | } | + | |
| - | </ | + | |
| - | + | ||
| - | For example, a call such as: | + | |
| - | <code csharp> | + | |
| - | Parcel parcel = null; | + | |
| - | if (!GetParcelAtPosition(Client.Network.CurrentSim, | + | |
| - | { | + | |
| - |     throw new Exception(); | + | |
| - | } | + | |
| - | + | ||
| - | </ | + | |
| - | + | ||
| - | will get the parcel that the scripted agent is currently on by supplying the scripted agent' | + | |
| - | + | ||
| - | ======== Extract Full Avatar Name ======== | + | |
| libopenmetaverse uses different possible avatar name formats when passing avatar names. For example, an avatar name can be in one of the following formats: | libopenmetaverse uses different possible avatar name formats when passing avatar names. For example, an avatar name can be in one of the following formats: | ||
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.