Exemplo n.º 1
0
        override public Dictionary <UUID, FriendRegionInfo> GetFriendRegionInfos(List <UUID> uuids)
        {
            MySQLSuperManager dbm = GetLockedConnection("GetFriendRegionInfos");
            Dictionary <UUID, FriendRegionInfo> infos = new Dictionary <UUID, FriendRegionInfo>();

            try
            {
                foreach (UUID uuid in uuids)
                {
                    Dictionary <string, object> param = new Dictionary <string, object>();
                    param["?uuid"] = uuid.ToString();
                    IDbCommand result = dbm.Manager.Query("select agentOnline,currentHandle from " + m_agentsTableName + " where UUID = ?uuid", param);

                    IDataReader reader = result.ExecuteReader();

                    while (reader.Read())
                    {
                        FriendRegionInfo fri = new FriendRegionInfo();
                        fri.isOnline     = (sbyte)reader["agentOnline"] != 0;
                        fri.regionHandle = (ulong)reader["currentHandle"];

                        infos[uuid] = fri;
                    }

                    reader.Dispose();
                    result.Dispose();
                }
            }

            catch (Exception e)
            {
                m_log.Warn("[MYSQL]: Got exception on trying to find friends regions:", e);
                dbm.Manager.Reconnect();
                m_log.Error(e.ToString());
            }

            finally
            {
                dbm.Release();
            }

            return(infos);
        }
        public override Dictionary <UUID, FriendRegionInfo> GetFriendRegionInfos(List <UUID> friendsIds)
        {
            Dictionary <UUID, FriendRegionInfo> friendRegionInfos = new Dictionary <UUID, FriendRegionInfo>();

            foreach (UUID friendId in friendsIds)
            {
                UserAgentData agent = GetAgentByUUID(friendId);
                if (agent != null)
                {
                    FriendRegionInfo fri = new FriendRegionInfo();
                    fri.isOnline     = agent.AgentOnline;
                    fri.regionHandle = agent.Handle;

                    friendRegionInfos[friendId] = fri;
                }
            }

            return(friendRegionInfos);
        }
Exemplo n.º 3
0
        public virtual Dictionary <UUID, FriendRegionInfo> GetFriendRegionInfos(List <UUID> uuids)
        {
            Dictionary <UUID, FriendRegionInfo> result = new Dictionary <UUID, FriendRegionInfo>();

            // ask MessageServer about the current on-/offline status and regions the friends are in
            ArrayList parameters = new ArrayList();
            Hashtable map        = new Hashtable();

            ArrayList list = new ArrayList();

            foreach (UUID uuid in uuids)
            {
                list.Add(uuid.ToString());
                list.Add(uuid.ToString());
            }
            map["uuids"] = list;

            map["recv_key"] = m_commsManager.NetworkServersInfo.UserRecvKey;
            map["send_key"] = m_commsManager.NetworkServersInfo.UserSendKey;

            parameters.Add(map);

            try
            {
                XmlRpcRequest  req      = new XmlRpcRequest("get_presence_info_bulk", parameters);
                XmlRpcResponse resp     = req.Send(m_commsManager.NetworkServersInfo.MessagingURL, 8000);
                Hashtable      respData = resp != null ? (Hashtable)resp.Value : null;

                if (respData == null || respData.ContainsKey("faultMessage"))
                {
                    m_log.WarnFormat("[OGS1 USER SERVICES]: Contacting MessagingServer about user-regions resulted in error: {0}",
                                     respData == null ? "<unknown error>" : respData["faultMessage"]);
                }
                else if (!respData.ContainsKey("count"))
                {
                    m_log.WarnFormat("[OGS1 USER SERVICES]: Wrong format in response for MessagingServer request get_presence_info_bulk: missing 'count' field");
                }
                else
                {
                    int count = (int)respData["count"];
                    m_log.DebugFormat("[OGS1 USER SERVICES]: Request returned {0} results.", count);
                    for (int i = 0; i < count; ++i)
                    {
                        if (respData.ContainsKey("uuid_" + i) && respData.ContainsKey("isOnline_" + i) && respData.ContainsKey("regionHandle_" + i))
                        {
                            UUID uuid;
                            if (UUID.TryParse((string)respData["uuid_" + i], out uuid))
                            {
                                FriendRegionInfo info = new FriendRegionInfo();
                                info.isOnline = (bool)respData["isOnline_" + i];
                                if (info.isOnline)
                                {
                                    // TODO remove this after the next protocol update (say, r7800?)
                                    info.regionHandle = Convert.ToUInt64(respData["regionHandle_" + i]);

                                    // accept missing id
                                    if (respData.ContainsKey("regionID_" + i))
                                    {
                                        UUID.TryParse((string)respData["regionID_" + i], out info.regionID);
                                    }
                                }

                                result.Add(uuid, info);
                            }
                        }
                        else
                        {
                            m_log.WarnFormat("[OGS1 USER SERVICES]: Response to get_presence_info_bulk contained an error in entry {0}", i);
                        }
                    }
                }
            }
            catch (WebException e)
            {
                m_log.ErrorFormat("[OGS1 USER SERVICES]: Network problems when trying to fetch friend infos: {0}", e.Message);
            }

            m_log.DebugFormat("[OGS1 USER SERVICES]: Returning {0} entries", result.Count);

            return(result);
        }