private byte[] GetAgentsLocations(OSDMap request)
        {
            OSDArray userIDs   = (OSDArray)request["userIDs"];
            string   requestor = request["requestor"].AsString();

            string[] users = new string[userIDs.Count];
            for (int i = 0; i < userIDs.Count; i++)
            {
                users[i] = userIDs[i];
            }

            string[] result = m_AgentInfoService.GetAgentsLocations(requestor, users);

            OSDArray resultArray = new OSDArray();

            foreach (string info in result)
            {
                resultArray.Add(info);
            }

            OSDMap resultMap = new OSDMap();

            resultMap["Result"] = resultArray;
            return(Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(resultMap)));
        }
Ejemplo n.º 2
0
 public string[] GetAgentsLocations(string requestor, string[] userIDs)
 {
     string[] info  = m_localService.GetAgentsLocations(requestor, userIDs);
     string[] info2 = m_remoteService.GetAgentsLocations(requestor, userIDs);
     if (info == null)
     {
         info = info2;
     }
     else
     {
         for (int i = 0; i < userIDs.Length; i++)
         {
             if (info[i] == "NotOnline" && info2.Length < i)
             {
                 info[i] = info2[i];
             }
         }
     }
     return(info);
 }
        public List <string> GetAgentsLocations(string requestor, List <string> userIDs)
        {
            List <string> info  = m_localService.GetAgentsLocations(requestor, userIDs);
            List <string> info2 = (List <string>)DoRemoteForced(userIDs);

            if (info == null || info.Count == 0)
            {
                info = info2;
            }
            else
            {
                for (int i = 0; i < userIDs.Count; i++)
                {
                    if (info[i] == "NotOnline" && info2.Count < i)
                    {
                        info[i] = info2[i];
                    }
                }
            }
            return(info);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///   Recursive SendGridInstantMessage over XMLRPC method.
        ///   This is called from within a dedicated thread.
        ///   The first time this is called, prevRegionHandle will be 0 Subsequent times this is called from
        ///   itself, prevRegionHandle will be the last region handle that we tried to send.
        ///   If the handles are the same, we look up the user's location using the grid.
        ///   If the handles are still the same, we end.  The send failed.
        /// </summary>
        /// <param name = "prevRegionHandle">
        ///   Pass in 0 the first time this method is called.  It will be called recursively with the last
        ///   regionhandle tried
        /// </param>
        protected virtual void SendGridInstantMessageViaXMLRPCAsync(GridInstantMessage im,
                                                                    GridRegion prevRegion)
        {
            UUID   toAgentID = im.toAgentID;
            string HTTPPath  = "";

            Hashtable msgdata = ConvertGridInstantMessageToXMLRPC(im);

            lock (IMUsersCache)
            {
                if (!IMUsersCache.TryGetValue(toAgentID, out HTTPPath))
                {
                    HTTPPath = "";
                }
            }

            if (HTTPPath != "")
            {
                //We've tried to send an IM to them before, pull out their info
                //Send the IM to their last location
                if (!doIMSending(HTTPPath, msgdata))
                {
                    msgdata = ConvertGridInstantMessageToXMLRPCXML(im);
                    if (!doIMSending(HTTPPath, msgdata))
                    {
                        //If this fails, the user has either moved from their stored location or logged out
                        //Since it failed, let it look them up again and rerun
                        lock (IMUsersCache)
                        {
                            IMUsersCache.Remove(toAgentID);
                        }
                        //Clear the path and let it continue trying again.
                        HTTPPath = "";
                    }
                }
                else
                {
                    //Send the IM, and it made it to the user, return true
                    return;
                }
            }

            //Now query the grid server for the agent
            IAgentInfoService ais = m_Scenes[0].RequestModuleInterface <IAgentInfoService>();

            string[] AgentLocations = ais.GetAgentsLocations(im.fromAgentID.ToString(), new[] { toAgentID.ToString() });
            if (AgentLocations.Length > 0)
            {
                //No agents, so this user is offline
                if (AgentLocations[0] == "NotOnline")
                {
                    lock (IMUsersCache)
                    {
                        //Remove them so we keep testing against the db
                        IMUsersCache.Remove(toAgentID);
                    }
                    MainConsole.Instance.Info("[GRID INSTANT MESSAGE]: Unable to deliver an instant message");
                    HandleUndeliveredMessage(im, "User is not set as online by presence service.");
                    return;
                }
                if (AgentLocations[0] == "NonExistant")
                {
                    IMUsersCache.Remove(toAgentID);
                    MainConsole.Instance.Info("[GRID INSTANT MESSAGE]: Unable to deliver an instant message to " + toAgentID +
                                              ", user does not exist");
                    HandleUndeliveredMessage(im, "User does not exist.");
                    return;
                }
                HTTPPath = AgentLocations[0];
            }

            //We found the agent's location, now ask them about the user
            if (HTTPPath != "")
            {
                if (!doIMSending(HTTPPath, msgdata))
                {
                    msgdata = ConvertGridInstantMessageToXMLRPCXML(im);
                    if (!doIMSending(HTTPPath, msgdata))
                    {
                        //It failed, stop now
                        lock (IMUsersCache)
                        {
                            //Remove them so we keep testing against the db
                            IMUsersCache.Remove(toAgentID);
                        }
                        MainConsole.Instance.Info(
                            "[GRID INSTANT MESSAGE]: Unable to deliver an instant message as the region could not be found");
                        HandleUndeliveredMessage(im, "Failed to send IM to destination.");
                        return;
                    }
                }
                else
                {
                    //Add to the cache
                    if (!IMUsersCache.ContainsKey(toAgentID))
                    {
                        IMUsersCache.Add(toAgentID, HTTPPath);
                    }
                    //Send the IM, and it made it to the user, return true
                    return;
                }
            }
            else
            {
                //Couldn't find them, stop for now
                lock (IMUsersCache)
                {
                    //Remove them so we keep testing against the db
                    IMUsersCache.Remove(toAgentID);
                }
                MainConsole.Instance.Info(
                    "[GRID INSTANT MESSAGE]: Unable to deliver an instant message as the region could not be found");
                HandleUndeliveredMessage(im, "Agent Location was blank.");
            }
        }
Ejemplo n.º 5
0
        protected virtual void SendMultipleGridInstantMessageViaXMLRPC(GridInstantMessage im, List <UUID> users)
        {
            Dictionary <UUID, string> HTTPPaths = new Dictionary <UUID, string> ();

            foreach (UUID agentID in users)
            {
                lock (IMUsersCache) {
                    string HTTPPath = "";
                    if (!IMUsersCache.TryGetValue(agentID, out HTTPPath))
                    {
                        HTTPPath = "";
                    }
                    else
                    {
                        HTTPPaths.Add(agentID, HTTPPath);
                    }
                }
            }
            List <UUID> CompletedUsers = new List <UUID> ();

            foreach (KeyValuePair <UUID, string> kvp in HTTPPaths)
            {
                //Fix the agentID
                im.ToAgentID = kvp.Key;
                //We've tried to send an IM to them before, pull out their info
                //Send the IM to their last location
                if (!doIMSending(kvp.Value, im))
                {
                    //If this fails, the user has either moved from their stored location or logged out
                    //Since it failed, let it look them up again and rerun
                    lock (IMUsersCache) {
                        IMUsersCache.Remove(kvp.Key);
                    }
                }
                else
                {
                    //Send the IM, and it made it to the user, return true
                    CompletedUsers.Add(kvp.Key);
                }
            }

            //Remove the finished users
            foreach (UUID agentID in CompletedUsers)
            {
                users.Remove(agentID);
            }
            HTTPPaths.Clear();

            //Now query the grid server for the agents
            List <string> Queries = users.Select(agentID => agentID.ToString()).ToList();

            if (Queries.Count == 0)
            {
                return; //All done
            }
            //Ask for the user new style first
            List <string> AgentLocations = m_agentInfoService.GetAgentsLocations(im.FromAgentID.ToString(),
                                                                                 Queries);

            //If this is false, this doesn't exist on the presence server and we use the legacy way
            if (AgentLocations != null && AgentLocations.Count != 0)
            {
                for (int i = 0; i < users.Count; i++)
                {
                    //No agents, so this user is offline
                    if (AgentLocations [i] == "NotOnline")
                    {
                        IMUsersCache.Remove(users [i]);
                        MainConsole.Instance.Debug("[GRID INSTANT MESSAGE]: Unable to deliver an instant message to " +
                                                   users [i] +
                                                   ", user was not online");
                        im.ToAgentID = users [i];
                        HandleUndeliveredMessage(im, "User is not online.");
                        continue;
                    }
                    if (AgentLocations [i] == "NonExistant")
                    {
                        IMUsersCache.Remove(users [i]);
                        MainConsole.Instance.Info("[GRID INSTANT MESSAGE]: Unable to deliver an instant message to " +
                                                  users [i] +
                                                  ", user does not exist");
                        im.ToAgentID = users [i];
                        HandleUndeliveredMessage(im, "User does not exist.");
                        continue;
                    }
                    HTTPPaths.Add(users [i], AgentLocations [i]);
                }
            }
            else
            {
                MainConsole.Instance.Info(
                    "[GRID INSTANT MESSAGE]: Unable to deliver an instant message, no users found.");
                return;
            }

            //We found the agent's location, now ask them about the user
            foreach (KeyValuePair <UUID, string> kvp in HTTPPaths)
            {
                if (kvp.Value != "")
                {
                    im.ToAgentID = kvp.Key;
                    if (!doIMSending(kvp.Value, im))
                    {
                        //It failed
                        lock (IMUsersCache) {
                            //Remove them so we keep testing against the db
                            IMUsersCache.Remove(kvp.Key);
                        }
                        HandleUndeliveredMessage(im, "Failed to send IM to destination.");
                    }
                    else
                    {
                        //Add to the cache
                        if (!IMUsersCache.ContainsKey(kvp.Key))
                        {
                            IMUsersCache.Add(kvp.Key, kvp.Value);
                        }
                        //Send the IM, and it made it to the user, return true
                        continue;
                    }
                }
                else
                {
                    lock (IMUsersCache) {
                        //Remove them so we keep testing against the db
                        IMUsersCache.Remove(kvp.Key);
                    }
                    HandleUndeliveredMessage(im, "Agent Location was blank.");
                }
            }
        }