Beispiel #1
0
        /// <summary>
        /// Requests a name for thew given agentId.
        ///
        /// If the name is cached, the callback will be called immediately. (on the main thread)
        ///
        /// If the name is not cached, a look up will be requested and the callback will be called
        /// when the response arrives from the server. (On the main thread)
        /// </summary>
        /// <param name="agentId"></param>
        /// <param name="callback"></param>
        /// <returns></returns>
        public bool Get(Guid agentId, Action <Guid, AvatarName> callback)
        {
            bool foundName    = false;
            bool shallRequest = true;

            if (NameCache.ContainsKey(agentId))
            {
                AvatarName avatarName = NameCache[agentId];
                ThreadManager.ExecuteOnMainThread(() => callback.Invoke(agentId, avatarName));
                foundName = true;

                if (avatarName.ExpiresOn < ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds())
                {
                    shallRequest = false;
                }
            }

            if (shallRequest)
            {
                lock (PendingRequests)
                {
                    if (PendingRequests.ContainsKey(agentId) == false)
                    {
                        PendingRequests[agentId] = new Request
                        {
                            AgentId   = agentId,
                            Callbacks = new List <Action <Guid, AvatarName> >()
                        };
                    }
                    PendingRequests[agentId].Callbacks.Add(callback);
                }
            }

            return(foundName);
        }
Beispiel #2
0
            public override bool Add(Guid buddyId, Relationship relationship)
            {
                if (relationship.IsOnline)
                {
                    AvatarName avatarName = AvatarNameCache.Instance.GetImmediate(buddyId);
                    Buddies[buddyId] = avatarName != null?avatarName.GetUserName() : "";
                }

                return(true);
            }
Beispiel #3
0
            public override bool Add(Guid buddyId, Relationship relationship)
            {
                if (relationship.IsOnline && relationship.IsRightGrantedFrom(Relationship.Rights.MapLocation))
                {
                    AvatarName avatarName = AvatarNameCache.Instance.GetImmediate(buddyId);
                    Buddies[buddyId] = avatarName != null ? avatarName.DisplayName : "";
                }

                return(true);
            }
Beispiel #4
0
            public override bool Add(Guid buddyId, Relationship relationship)
            {
                AvatarName avatarName = AvatarNameCache.Instance.GetImmediate(buddyId);

                if (relationship.IsOnline)
                {
                    BuddiesOnline[buddyId] = avatarName != null?avatarName.GetCompleteName() : "";
                }
                else
                {
                    BuddiesOffline[buddyId] = avatarName != null?avatarName.GetCompleteName() : "";
                }

                return(true);
            }
Beispiel #5
0
        protected void ParseResponseAgents(XmlNode node)
        {
            if (node.Name != "array")
            {
                throw new Exception($"Expected <array> got <{node.Name}>");
            }

            foreach (object childObject in node.ChildNodes)
            {
                XmlNode child = (XmlNode)childObject;
                if (child.Name != "map")
                {
                    throw new Exception($"Expected <map> got <{child.Name}>");
                }

                Guid       agentId    = Guid.Empty;
                AvatarName avatarName = new AvatarName();

                child = child.FirstChild;
                while (child != null)
                {
                    string key = child.InnerText;
                    child = child.NextSibling; // Move to value
                    if (child == null)
                    {
                        throw new Exception("Expected a value.");
                    }

                    switch (key)
                    {
                    case "username":
                        // We don't care about this since UserNames are always constructed.
                        //
                        //if (child.Name != "string")
                        //{
                        //    Logger.LogWarning($"AvatarNameCache.ParseResponseAgents: Expected username type string, got \"{child.Name}\"");
                        //}
                        //else
                        //{
                        //    avatarName.UserName = XmlRpcValue.EscapeString(child.InnerText.Trim()); // TODO: Not nice to depend on XmlRpc here
                        //}
                        break;

                    case "display_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $": Expected display_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.DisplayName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "display_name_next_update":
                        if (child.Name != "date")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected display_name_next_update type date, got \"{child.Name}\"");
                        }
                        else
                        {
                            DateTime time = DateTime.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                            // TODO: Get the seconds from UNIX epoch
                        }
                        break;

                    case "legacy_first_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected legacy_first_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.FirstName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "legacy_last_name":
                        if (child.Name != "string")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected legacy_last_name type string, got \"{child.Name}\"");
                        }
                        else
                        {
                            avatarName.LastName = XmlRpcValue.EscapeString(child.InnerText.Trim());     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "id":
                        if (child.Name != "uuid")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected id type uuid, got \"{child.Name}\"");
                        }
                        else
                        {
                            agentId = Guid.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    case "is_display_name_default":
                        if (child.Name != "boolean")
                        {
                            Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Expected is_display_name_default type boolean, got \"{child.Name}\"");
                        }
                        else
                        {
                            bool x = bool.Parse(XmlRpcValue.EscapeString(child.InnerText.Trim()));     // TODO: Not nice to depend on XmlRpc here
                        }
                        break;

                    default:
                        Logger.LogWarning("AvatarNameCache.ParseResponseAgents", $"Unexpected key \"{child.InnerText}\"");
                        break;
                    }

                    child = child.NextSibling; // Move to next key
                }
                Logger.LogDebug("AvatarNameCache.ParseResponseAgents", $"Parsed: First=\"{avatarName.FirstName}\", Last=\"{avatarName.LastName}\", DisplayName=\"{avatarName.DisplayName}\"");

                // TODO: What if agentId was never received?
                NameCache[agentId] = avatarName;

                if (PendingRequests.ContainsKey(agentId))
                {
                    Request request = PendingRequests[agentId];
                    lock (PendingRequests)
                    {
                        PendingRequests.Remove(agentId);
                    }

                    foreach (Action <Guid, AvatarName> callback in request.Callbacks)
                    {
                        ThreadManager.ExecuteOnMainThread(() => callback.Invoke(agentId, avatarName));
                    }
                }
            }
        }
Beispiel #6
0
 protected void OnAvatarNameReceived(Guid agentId, AvatarName avatarName)
 {
     //Logger.LogDebug("AvatarTracker.OnAvatarNameReceived", $"FirstName=\"{avatarName.FirstName}\", LastName=\"{avatarName.LastName}\", DisplayName=\"{avatarName.DisplayName}\"");
 }