Beispiel #1
0
        public InventoryItemBase GetItem(UUID principalID, UUID itemID)
        {
            InventoryItemBase retrieved = null;

            if (m_ItemCache.TryGetValue(itemID, out retrieved))
            {
                return(retrieved);
            }

            try
            {
                Dictionary <string, object> ret = MakeRequest(
                    new Dictionary <string, object> {
                    { "METHOD", "GETITEM" },
                    { "ID", itemID.ToString() },
                    { "PRINCIPAL", principalID.ToString() }
                });

                if (!CheckReturn(ret))
                {
                    return(null);
                }

                retrieved = BuildItem((Dictionary <string, object>)ret["item"]);
            }
            catch (Exception e)
            {
                m_log.Error("[XINVENTORY SERVICES CONNECTOR]: Exception in GetItem: ", e);
            }

            m_ItemCache.AddOrUpdate(itemID, retrieved, CACHE_EXPIRATION_SECONDS);

            return(retrieved);
        }
Beispiel #2
0
 public UserAccount Get(string name, out bool inCache)
 {
     lock (accessLock)
     {
         if (m_NameCache.TryGetValue(name.ToLowerInvariant(), out UserAccount account))
         {
             inCache = true;
             return(account);
         }
     }
     inCache = false;
     return(null);
 }
Beispiel #3
0
 public UserAccount Get(UUID userID, out bool inCache)
 {
     lock (accessLock)
     {
         if (m_UUIDCache.TryGetValue(userID, out UserAccount account))
         {
             //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
             inCache = true;
             return(account);
         }
     }
     inCache = false;
     return(null);
 }
 public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
 {
     if (m_RemoteConnector.SetHome(userID, regionID, position, lookAt))
     {
         if (m_Infos.TryGetValue(userID, KEEPTIME * 1000, out GridUserInfo info))
         {
             info.HomeRegionID = regionID;
             info.HomePosition = position;
             info.HomeLookAt   = lookAt;
         }
         return(true);
     }
     return(false);
 }
        public bool LoginAgent(string userID, UUID sessionID, UUID secureSessionID)
        {
            bool inCache = ByUserCache.TryGetValue(userID, out PresenceData prevUser);

            if (!inCache)
            {
                PresenceData[] dataprv = m_Database.Get("UserID", userID);
                if (dataprv.Length > 0)
                {
                    prevUser = dataprv[0];
                }
            }

            if (!m_allowDuplicatePresences && (prevUser != null))
            {
                m_Database.Delete("UserID", userID.ToString());
                if (inCache)
                {
                    BySessionCache.Remove(prevUser.SessionID);
                    ByUserCache.Remove(userID);
                }
            }

            PresenceData data = new PresenceData();

            data.UserID    = userID;
            data.RegionID  = UUID.Zero;
            data.SessionID = sessionID;
            data.Data      = new Dictionary <string, string>();
            data.Data["SecureSessionID"] = secureSessionID.ToString();

            m_Database.Store(data);
            BySessionCache.Add(sessionID, data, EXPIREMS);
            ByUserCache.Add(userID, data, EXPIREMS);

            string prevUserStr = "";

            if (prevUser != null)
            {
                prevUserStr = string.Format(". This user was already logged-in: session {0}, region {1}", prevUser.SessionID, prevUser.RegionID);
            }

            m_log.DebugFormat("[PRESENCE SERVICE]: LoginAgent: session {0}, user {1}, region {2}, secure session {3}{4}",
                              data.SessionID, data.UserID, data.RegionID, secureSessionID, prevUserStr);

            return(true);
        }
Beispiel #6
0
        public InventoryFolderBase GetRootFolder(UUID userID)
        {
            if (m_RootFolders.TryGetValue(userID, out InventoryFolderBase root))
            {
                return(root);
            }

            return(null);
        }
Beispiel #7
0
        public void Cache(UUID userID, FolderType type, InventoryFolderBase folder)
        {
            if (!m_FolderTypes.TryGetValue(userID, out Dictionary <FolderType, InventoryFolderBase> ff))
            {
                ff = new Dictionary <FolderType, InventoryFolderBase>();
                m_FolderTypes.Add(userID, ff, CACHE_EXPIRATION);
            }

            // We need to lock here since two threads could potentially retrieve the same dictionary
            // and try to add a folder for that type simultaneously.  Dictionary<>.Add() is not described as thread-safe in the SDK
            // even if the folders are identical.
            lock (ff)
            {
                if (!ff.ContainsKey(type))
                {
                    ff.Add(type, folder);
                }
            }
        }
Beispiel #8
0
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection c;

            if (m_Inventories.TryGetValue(userID, out InventoryCollection inv))
            {
                c         = new InventoryCollection();
                c.OwnerID = userID;

                c.Folders = inv.Folders.FindAll(delegate(InventoryFolderBase f)
                {
                    return(f.ParentID == folderID);
                });
                c.Items = inv.Items.FindAll(delegate(InventoryItemBase i)
                {
                    return(i.Folder == folderID);
                });
                return(c);
            }
            return(null);
        }
        public bool LogoutAgent(UUID sessionID)
        {
            bool inCache = BySessionCache.TryGetValue(sessionID, out PresenceData presence);

            if (!inCache)
            {
                presence = m_Database.Get(sessionID);
            }

            m_log.DebugFormat("[PRESENCE SERVICE]: LogoutAgent: session {0}, user {1}, region {2}",
                              sessionID,
                              (presence == null) ? null : presence.UserID,
                              (presence == null) ? null : presence.RegionID.ToString());

            bool ret = m_Database.Delete("SessionID", sessionID.ToString());

            if (inCache && presence != null)
            {
                BySessionCache.Remove(presence.SessionID);
                ByUserCache.Remove(presence.UserID);
            }
            return(ret);
        }
Beispiel #10
0
        private AssetServicesConnector GetConnector(string url)
        {
            AssetServicesConnector connector = null;

            lock (m_connectors)
            {
                if (!m_connectors.TryGetValue(url, 60000, out connector))
                {
                    connector = new AssetServicesConnector(url);
                    m_connectors.Add(url, connector);
                }
            }
            return(connector);
        }
Beispiel #11
0
        private GridUserData GetGridUserData(string userID)
        {
            if (userID.Length > 36)
            {
                userID = userID.Substring(0, 36);
            }

            if (cache.TryGetValue(userID, out GridUserData d))
            {
                return(d);
            }

            GridUserData[] ds = m_Database.GetAll(userID);
            if (ds == null || ds.Length == 0)
            {
                cache.Add(userID, null, 300000);
                return(null);
            }

            d = ds[0];
            if (ds.Length > 1)
            {
                // try find most recent record
                try
                {
                    int tsta = int.Parse(d.Data["Login"]);
                    int tstb = int.Parse(d.Data["Logout"]);
                    int cur  = tstb > tsta? tstb : tsta;

                    for (int i = 1; i < ds.Length; ++i)
                    {
                        GridUserData dd = ds[i];
                        tsta = int.Parse(dd.Data["Login"]);
                        tstb = int.Parse(dd.Data["Logout"]);
                        if (tsta > tstb)
                        {
                            tstb = tsta;
                        }
                        if (tstb > cur)
                        {
                            cur = tstb;
                            d   = dd;
                        }
                    }
                }
                catch { }
            }
            cache.Add(userID, d, 300000);
            return(d);
        }
        bool SendIMToRegion(PresenceInfo upd, GridInstantMessage im, UUID toAgentID, bool foreigner)
        {
            bool       imresult = false;
            GridRegion reginfo  = null;

            if (!m_RegionCache.TryGetValue(upd.RegionID, REGIONCACHE_EXPIRATION, out reginfo))
            {
                reginfo = m_GridService.GetRegionByUUID(UUID.Zero /*!!!*/, upd.RegionID);
                m_RegionCache.AddOrUpdate(upd.RegionID, reginfo, reginfo == null ? 60000 : REGIONCACHE_EXPIRATION);
            }

            if (reginfo != null)
            {
                imresult = InstantMessageServiceConnector.SendInstantMessage(reginfo.ServerURI, im, m_messageKey);
            }
            else
            {
                m_log.DebugFormat("[HG IM SERVICE]: Failed to deliver message to {0}", reginfo.ServerURI);
                return(false);
            }

            if (imresult)
            {
                // IM delivery successful, so store the Agent's location in our local cache.
                lock (m_UserLocationMap)
                {
                    if (m_UserLocationMap.ContainsKey(toAgentID))
                    {
                        m_UserLocationMap[toAgentID] = upd;
                    }
                    else
                    {
                        m_UserLocationMap.Add(toAgentID, upd);
                    }
                }
                return(true);
            }
            else
            {
                // try again, but lookup user this time.
                // Warning, this must call the Async version
                // of this method or we'll be making thousands of threads
                // The version within the spawned thread is SendGridInstantMessageViaXMLRPCAsync
                // The version that spawns the thread is SendGridInstantMessageViaXMLRPC

                // This is recursive!!!!!
                return(TrySendInstantMessage(im, upd, false, foreigner));
            }
        }
        public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
        {
            if (!(client.Scene is Scene))
            {
                return;
            }

            //Scene scene = (Scene)(client.Scene);
            if (m_PendingLures.TryGetValue(lureID, out GridInstantMessage im))
            {
                m_PendingLures.Remove(lureID);
                Lure(client, teleportFlags, im);
            }
            else
            {
                m_log.DebugFormat("[HG LURE MODULE]: pending lure {0} not found", lureID);
            }
        }
        protected virtual void HandleUUIDNameRequest(UUID uuid, IClientAPI client)
        {
//            m_log.DebugFormat(
//                "[USER MANAGEMENT MODULE]: Handling request for name binding of UUID {0} from {1}",
//                uuid, remote_client.Name);
            if (m_Scenes.Count <= 0)
            {
                return;
            }

            if (m_userCacheByID.TryGetValue(uuid, out UserData user))
            {
                if (user.HasGridUserTried)
                {
                    client.SendNameReply(uuid, user.FirstName, user.LastName);
                    return;
                }
            }

            if (m_ServiceThrottle == null)
            {
                return;
            }

            IClientAPI deferedcli = client;

            // Not found in cache, queue continuation
            m_ServiceThrottle.Enqueue("uuidname", uuid.ToString(), delegate
            {
                if (deferedcli.IsActive)
                {
                    if (GetUser(uuid, deferedcli.ScopeId, out UserData defuser))
                    {
                        if (deferedcli.IsActive)
                        {
                            deferedcli.SendNameReply(uuid, defuser.FirstName, defuser.LastName);
                        }
                    }
                }
                deferedcli = null;
            });
        private IInventoryService GetConnector(string url)
        {
            IInventoryService connector = null;

            lock (m_connectors)
            {
                if (!m_connectors.TryGetValue(url, out connector))
                {
                    // Still not as flexible as I would like this to be,
                    // but good enough for now
                    RemoteXInventoryServicesConnector rxisc = new RemoteXInventoryServicesConnector(url);
                    rxisc.Scene = m_Scenes[0];
                    connector   = rxisc;
                }
                if (connector != null)
                {
                    m_connectors.AddOrUpdate(url, connector, CONNECTORS_CACHE_EXPIRE);
                }
            }
            return(connector);
        }
        public ExtendedGroupRecord GetGroupRecord(string RequestingAgentID, UUID GroupID, string GroupName, GroupRecordDelegate d)
        {
            //if (GroupID == UUID.Zero && (GroupName == null || GroupName != null && GroupName == string.Empty))
            //    return null;

            object group     = null;
            bool   firstCall = false;
            string cacheKey  = "group-";

            if (GroupID != UUID.Zero)
            {
                cacheKey += GroupID.ToString();
            }
            else
            {
                cacheKey += GroupName;
            }

            //m_log.DebugFormat("[XXX]: GetGroupRecord {0}", cacheKey);

            while (true)
            {
                lock (m_Cache)
                {
                    if (m_Cache.TryGetValue(cacheKey, out group))
                    {
                        //m_log.DebugFormat("[XXX]: GetGroupRecord {0} cached!", cacheKey);
                        return((ExtendedGroupRecord)group);
                    }

                    // not cached
                    if (!m_ActiveRequests.Contains(cacheKey))
                    {
                        m_ActiveRequests.Add(cacheKey);
                        firstCall = true;
                    }
                }

                if (firstCall)
                {
                    try
                    {
                        //group = m_GroupsService.GetGroupRecord(RequestingAgentID, GroupID, GroupName);
                        group = d();

                        lock (m_Cache)
                        {
                            m_Cache.AddOrUpdate(cacheKey, group, GROUPS_CACHE_TIMEOUT);
                            return((ExtendedGroupRecord)group);
                        }
                    }
                    finally
                    {
                        m_ActiveRequests.Remove(cacheKey);
                    }
                }
                else
                {
                    Thread.Sleep(50);
                }
            }
        }