public InventoryItemBase GetItem(InventoryItemBase item)
        {
            InventoryItemBase retrieved = null;

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

            try
            {
                Dictionary <string, object> ret = MakeRequest("GETITEM",
                                                              new Dictionary <string, object> {
                    { "ID", item.ID.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(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);

            return(retrieved);
        }
Esempio n. 2
0
        public override bool AddFolder(InventoryFolderBase folder)
        {
            //m_log.WarnFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder {0} {1}", folder.Name, folder.ParentID);
            // Let's do a bit of sanity checking, more than the base service does
            // make sure the given folder's parent folder exists under the suitcase tree of this user

            if (!IsWithinSuitcaseTree(folder.Owner, folder.ParentID))
            {
                m_log.DebugFormat("[HG SUITCASE INVENTORY SERVICE]: AddFolder: folder {0} (user {1}) is not within Suitcase tree", folder.ParentID, folder.Owner);
                return(false);
            }

            // OK, it's legit
            if (base.AddFolder(folder))
            {
                List <XInventoryFolder> tree;
                if (m_SuitcaseTrees.TryGetValue(folder.Owner, out tree))
                {
                    tree.Add(ConvertFromOpenSim(folder));
                }

                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        public bool UpdateUserFields(UUID userID, OSDMap fields)
        {
            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "AddUserData" },
                { "UserID", userID.ToString() }
            };

            foreach (KeyValuePair <string, OSD> kvp in fields)
            {
                requestArgs[kvp.Key] = OSDParser.SerializeJsonString(kvp.Value);
            }

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);
            bool   success  = response["Success"].AsBoolean();

            if (success)
            {
                // Update the cache
                User user;
                if (m_userCache.TryGetValue(userID, out user))
                {
                    foreach (KeyValuePair <string, OSD> kvp in fields)
                    {
                        user.SetField(kvp.Key, kvp.Value);
                    }
                }
            }
            else
            {
                m_log.Warn("Failed saving user data for " + userID + ": " + response["Message"].AsString());
            }

            return(success);
        }
        public bool Get(UUID userID, out T account)
        {
            if (m_UUIDCache.TryGetValue(userID, out account))
            {
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        public bool Get(UUID userID, out UserAccount account)
        {
            if (m_UUIDCache.TryGetValue(userID, out account))
            {
                //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
                return(true);
            }

            return(false);
        }
Esempio n. 6
0
        public InventoryCollection GetUserInventory(UUID userID)
        {
            InventoryCollection inv = null;

            if (m_Inventories.TryGetValue(userID, out inv))
            {
                return(inv);
            }
            return(null);
        }
Esempio n. 7
0
        public UserAccount Get(UUID userID, out bool inCache)
        {
            UserAccount account = null;

            inCache = false;
            if (m_UUIDCache.TryGetValue(userID, out account))
            {
                //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
                inCache = true;
                return(account);
            }

            return(null);
        }
Esempio n. 8
0
        public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache)
        {
            inCache = false;

            GridRegion       rinfo = null;
            ScopedRegionUUID id    = new ScopedRegionUUID(scopeID, regionID);

            if (m_UUIDCache.TryGetValue(id, out rinfo))
            {
                inCache = true;
                return(rinfo);
            }

            return(null);
        }
        public GridUserInfo GetGridUserInfo(string userID)
        {
            GridUserInfo info = null;

            if (m_Infos.TryGetValue(userID, out info))
            {
                return(info);
            }

            info = m_RemoteConnector.GetGridUserInfo(userID);

            m_Infos.AddOrUpdate(userID, info, KEEPTIME);

            return(info);
        }
Esempio n. 10
0
 public void Cache(UUID userID, AssetType type, InventoryFolderBase folder)
 {
     lock (m_FolderTypes)
     {
         Dictionary <AssetType, InventoryFolderBase> ff = null;
         if (!m_FolderTypes.TryGetValue(userID, out ff))
         {
             ff = new Dictionary <AssetType, InventoryFolderBase>();
             m_FolderTypes.Add(userID, ff, CACHE_EXPIRATION_SECONDS);
         }
         if (!ff.ContainsKey(type))
         {
             ff.Add(type, folder);
         }
     }
 }
Esempio n. 11
0
        public bool TryGetScene(UUID sceneID, out SceneInfo sceneInfo)
        {
            // Cache check
            if (m_sceneCache.TryGetValue(sceneID, out sceneInfo))
            {
                return(true);
            }

            // Remote fetch
            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetScene" },
                { "SceneID", sceneID.ToString() },
                { "Enabled", "1" }
            };

            OSDMap response = WebUtil.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean())
            {
                sceneInfo = ResponseToSceneInfo(response);
                m_sceneCache.AddOrUpdate(sceneID, sceneInfo, CACHE_TIMEOUT);
                return(true);
            }
            else
            {
                m_log.Warn("Grid service did not find a match for region " + sceneID);
                sceneInfo = null;
                return(false);
            }
        }
        public UserAccount GetUserAccount(UUID scopeID, UUID userID)
        {
            // Cache check
            UserAccount account;

            if (m_accountCache.TryGetValue(userID, out account))
            {
                return(account);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetUser" },
                { "UserID", userID.ToString() }
            };

            account = GetUser(requestArgs);

            if (account == null)
            {
                // Store null responses too, to avoid repeated lookups for missing accounts
                m_accountCache.AddOrUpdate(userID, null, CACHE_EXPIRATION_SECONDS);
            }

            return(account);
        }
        private string IncomingCommand(byte[] data, string path, string param)
        {
            using (MemoryStream str = new MemoryStream(data))
            {
                OSDMap map = (OSDMap)OSDParser.DeserializeJson(str);

                UUID sessionID = map["sessionId"].AsUUID();
                UUID userID    = map["userId"].AsUUID();
                UUID regionID  = map["regionId"].AsUUID();

                Scene scene = _scenes.FirstOrDefault((s) => s.RegionInfo.RegionID == regionID);
                if (scene == null)//No scene found...
                {
                    return(BuildCommandResponse(RemoteCommandResponse.NOTFOUND, null));
                }

                if (!scene.ConnectionManager.IsAuthorized(userID, sessionID))
                {
                    //They might not be in the scene, check if they have left recently
                    LeavingRegionInfo info = null;
                    if (!_avatarRegionCache.TryGetValue(userID, out info) || info.SessionID != sessionID)
                    {
                        return(BuildCommandResponse(RemoteCommandResponse.UNAUTHORIZED, null));//Wrong sessionID or was never here
                    }
                    //They moved out of this region
                    return(BuildMovedCommandResponse(userID));
                }

                ScenePresence presence = scene.GetScenePresence(userID);
                if (presence == null || presence.IsChildAgent)//Make sure that they are actually in the region
                {
                    return(BuildMovedCommandResponse(userID));
                }

                //Process the command
                RemoteCommandType commandID = (RemoteCommandType)map["id"].AsInteger();
                switch (commandID)
                {
                case RemoteCommandType.AvatarChatCommand:
                    return(ProcessAvatarChatCommand(presence, map));

                case RemoteCommandType.AvatarTeleportCommand:
                    return(ProcessAvatarTeleportCommand(presence, map));
                }
            }
            return(BuildCommandResponse(RemoteCommandResponse.INVALID, null));
        }
        public bool SetHome(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
        {
            if (m_RemoteConnector.SetHome(userID, regionID, position, lookAt))
            {
                // Update the cache too
                GridUserInfo info = null;
                if (m_Infos.TryGetValue(userID, out info))
                {
                    info.HomeRegionID = regionID;
                    info.HomePosition = position;
                    info.HomeLookAt   = lookAt;
                }
                return(true);
            }

            return(false);
        }
Esempio n. 15
0
        public List <int> GetEstatesAll()
        {
            List <int> eids = new List <int>();
            // If we don't have them, load them from the server
            List <EstateSettings> estates = null;

            if (!m_EstateCache.TryGetValue("estates", out estates))
            {
                estates = LoadEstateSettingsAll();
            }

            foreach (EstateSettings es in estates)
            {
                eids.Add((int)es.EstateID);
            }

            return(eids);
        }
Esempio n. 16
0
        public bool Get(string id, out AssetBase asset)
        {
            asset = null;

            m_Requests++;

            object dummy;

            if (m_negativeCache.TryGetValue(id, out dummy))
            {
                return(false);
            }

            asset = GetFromWeakReference(id);
            if (asset != null && m_updateFileTimeOnCacheHit)
            {
                string filename = GetFileName(id);
                UpdateFileLastAccessTime(filename);
            }

            if (m_MemoryCacheEnabled && asset == null)
            {
                asset = GetFromMemoryCache(id);
                if (asset != null)
                {
                    UpdateWeakReference(id, asset);
                    if (m_updateFileTimeOnCacheHit)
                    {
                        string filename = GetFileName(id);
                        UpdateFileLastAccessTime(filename);
                    }
                }
            }

            if (asset == null && m_FileCacheEnabled)
            {
                asset = GetFromFileCache(id);
                if (asset != null)
                {
                    UpdateWeakReference(id, asset);
                }
            }

            if (m_MemoryCacheEnabled && asset != null)
            {
                UpdateMemoryCache(id, asset);
            }

            if (((m_LogLevel >= 1)) && (m_HitRateDisplay != 0) && (m_Requests % m_HitRateDisplay == 0))
            {
                m_log.InfoFormat("[FLOTSAM ASSET CACHE]: Cache Get :: {0} :: {1}", id, asset == null ? "Miss" : "Hit");

                GenerateCacheHitReport().ForEach(l => m_log.InfoFormat("[FLOTSAM ASSET CACHE]: {0}", l));
            }

            return(true);
        }
Esempio n. 17
0
        private AvatarAppearance GetAppearance(UUID principalID)
        {
            AvatarAppearance a = null;
            if (m_Appearances.TryGetValue(principalID, out a))
                return a;

            a = m_AvatarService.GetAppearance(principalID);
            m_Appearances.AddOrUpdate(principalID, a, 5 * 60); // 5minutes
            return a;
        }
Esempio n. 18
0
        public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
//                m_log.DebugFormat(
//                    "[J2KDecoderModule]: Returning existing cached {0} layers j2k decode for {1}",
//                    result.Length, assetID);

                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList[assetID].Add(callback);
                    }
                    else
                    {
                        List <DecodedCallback> notifylist = new List <DecodedCallback>();
                        notifylist.Add(callback);
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                {
                    Util.FireAndForget(delegate { Decode(assetID, j2kData); });
                }
            }
        }
Esempio n. 19
0
        public InventoryFolderBase GetRootFolder(UUID userID)
        {
            InventoryFolderBase root = null;

            if (m_RootFolders.TryGetValue(userID, out root))
            {
                return(root);
            }

            return(null);
        }
Esempio n. 20
0
        /// <summary>
        /// Try to get an asset from the in-memory cache.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        private AssetBase GetFromMemoryCache(string id)
        {
            AssetBase asset = null;

            if (m_MemoryCache.TryGetValue(id, out asset))
            {
                m_MemoryHits++;
            }

            return(asset);
        }
Esempio n. 21
0
        public void Cache(UUID userID, AssetType type, InventoryFolderBase folder)
        {
            Dictionary <AssetType, InventoryFolderBase> ff = null;

            if (!m_FolderTypes.TryGetValue(userID, out ff))
            {
                ff = new Dictionary <AssetType, InventoryFolderBase>();
                m_FolderTypes.Add(userID, ff, CACHE_EXPIRATION_SECONDS);
            }

            // 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);
                }
            }
        }
Esempio n. 22
0
        bool SendIMToRegion(PresenceInfo upd, GridInstantMessage im, UUID toAgentID, bool foreigner)
        {
            bool       imresult = false;
            GridRegion reginfo  = null;

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

            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));
            }
        }
Esempio n. 23
0
        public void BeginDecode(UUID assetID, byte[] j2kData, DecodedCallback callback)
        {
            OpenJPEG.J2KLayerInfo[] result;

            // If it's cached, return the cached results
            if (m_decodedCache.TryGetValue(assetID, out result))
            {
                callback(assetID, result);
            }
            else
            {
                // Not cached, we need to decode it.
                // Add to notify list and start decoding.
                // Next request for this asset while it's decoding will only be added to the notify list
                // once this is decoded, requests will be served from the cache and all clients in the notifylist will be updated
                bool decode = false;
                lock (m_notifyList)
                {
                    if (m_notifyList.ContainsKey(assetID))
                    {
                        m_notifyList[assetID].Add(callback);
                    }
                    else
                    {
                        List <DecodedCallback> notifylist = new List <DecodedCallback> {
                            callback
                        };
                        m_notifyList.Add(assetID, notifylist);
                        decode = true;
                    }
                }

                // Do Decode!
                if (decode)
                {
                    DoJ2KDecode(assetID, j2kData);
                }
            }
        }
Esempio n. 24
0
        public UserAccount Get(string name, out bool inCache)
        {
            inCache = false;
            if (!m_NameCache.Contains(name))
            {
                return(null);
            }

            UserAccount account = null;
            UUID        uuid    = UUID.Zero;

            if (m_NameCache.TryGetValue(name, out uuid))
            {
                if (m_UUIDCache.TryGetValue(uuid, out account))
                {
                    inCache = true;
                    return(account);
                }
            }

            return(null);
        }
Esempio n. 25
0
        public InventoryCollection GetFolderContent(UUID userID, UUID folderID)
        {
            InventoryCollection inv = null;
            InventoryCollection c;

            if (m_Inventories.TryGetValue(userID, out inv))
            {
                c        = new InventoryCollection();
                c.UserID = 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);
        }
Esempio n. 26
0
        public GridRegion Get(UUID scopeID, ulong handle, out bool inCache)
        {
            inCache = false;

            GridRegion           rinfo = null;
            ScopedRegionPosition pos   = new ScopedRegionPosition(scopeID, handle);

            if (m_PositionCache.TryGetValue(pos, out rinfo))
            {
                inCache = true;
                return(rinfo);
            }

            return(null);
        }
        public bool Get(string name, out T account)
        {
            account = default(T);

            UUID uuid = UUID.Zero;

            if (m_NameCache.TryGetValue(name, out uuid))
            {
                if (m_UUIDCache.TryGetValue(uuid, out account))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 28
0
        public UserAccount GetUserAccount(UUID scopeID, UUID userID)
        {
            // Cache check
            UserAccount account;

            if (m_accountCache.TryGetValue(userID, out account))
            {
                return(account);
            }

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetUser" },
                { "UserID", userID.ToString() }
            };

            return(GetUser(requestArgs));
        }
Esempio n. 29
0
        public void OnTeleportLureRequest(UUID lureID, uint teleportFlags, IClientAPI client)
        {
            ulong handle;
            uint  x;
            uint  y;
            uint  z;

            Util.ParseFakeParcelID(lureID, out handle, out x, out y, out z);

            Vector3 position = new Vector3 {
                X = x, Y = y, Z = z
            };
            IEntityTransferModule entityTransfer = client.Scene.RequestModuleInterface <IEntityTransferModule> ();

            if (entityTransfer != null)
            {
                GridInstantMessage im;
                if (m_PendingLures.TryGetValue(lureID, out im))
                {
                    string[] parts = im.message.Split(new[] { '@' });
                    if (parts.Length > 1)
                    {
                        string url = parts[parts.Length - 1]; // the last part
                        if (url.Trim(new[] { '/' }) != GetMainGridURL().Trim(new[] { '/' }))
                        {
                            GridRegion gatekeeper = new GridRegion
                            {
                                ServerURI = url,
                                RegionID  = im.RegionID,
                                Flags     =
                                    (int)
                                    (Framework.RegionFlags.Foreign |
                                     Framework.RegionFlags.Hyperlink)
                            };
                            entityTransfer.RequestTeleportLocation(client, gatekeeper, position,
                                                                   Vector3.Zero, teleportFlags);
                            return;
                        }
                    }
                }
                entityTransfer.RequestTeleportLocation(client, handle, position,
                                                       Vector3.Zero, teleportFlags);
            }
        }
        /// <summary>
        /// Get an item, given by its UUID
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public InventoryItemBase GetItem(InventoryItemBase item)
        {
            InventoryItemBase retrieved = null;

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

            NameValueCollection requestArgs = new NameValueCollection
            {
                { "RequestMethod", "GetInventoryNode" },
                { "ItemID", item.ID.ToString() },
                { "OwnerID", item.Owner.ToString() },
                { "IncludeFolders", "1" },
                { "IncludeItems", "1" },
                { "ChildrenOnly", "1" }
            };

            OSDMap response = SimianGrid.PostToService(m_serverUrl, requestArgs);

            if (response["Success"].AsBoolean() && response["Items"] is OSDArray)
            {
                List <InventoryItemBase> items = GetItemsFromResponse((OSDArray)response["Items"]);
                if (items.Count > 0)
                {
                    // The requested item should be the first in this list, but loop through
                    // and sanity check just in case
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].ID == item.ID)
                        {
                            retrieved = items[i];
                            m_ItemCache.AddOrUpdate(item.ID, retrieved, CACHE_EXPIRATION_SECONDS);
                            return(retrieved);
                        }
                    }
                }
            }

            m_log.Warn("[SIMIAN INVENTORY CONNECTOR]: Item " + item.ID + " owned by " + item.Owner + " not found");
            return(null);
        }