public bool Delete(string id)
        {
            string uri = m_ServerURI + "/assets/" + id;

            if (SynchronousRestObjectRequester.
                MakeRequest <int, bool>("DELETE", uri, 0))
            {
                if (m_Cache != null)
                {
                    m_Cache.Expire(id);
                }

                return(true);
            }
            return(false);
        }
        public string Store(AssetBase asset)
        {
            if (asset.Local)
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }

                return(asset.ID);
            }

            string uri = m_ServerURI + "/assets/";

            string newID;

            try
            {
                newID = SynchronousRestObjectRequester.MakeRequest <AssetBase, string>("POST", uri, asset, m_Auth);
            }
            catch (Exception e)
            {
                m_log.Warn(string.Format("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1} ", asset.ID, e.Message), e);
                return(string.Empty);
            }

            // TEMPORARY: SRAS returns 'null' when it's asked to store existing assets
            if (newID == null)
            {
                m_log.DebugFormat("[ASSET CONNECTOR]: Storing of asset {0} returned null; assuming the asset already exists", asset.ID);
                return(asset.ID);
            }

            if (string.IsNullOrEmpty(newID))
            {
                return(string.Empty);
            }

            asset.ID = newID;

            if (m_Cache != null)
            {
                m_Cache.Cache(asset);
            }

            return(newID);
        }
        private void AssetRequestProcessor()
        {
            QueuedAssetRequest r;

            while (true)
            {
                r = m_requestQueue.Dequeue(4500);
                Watchdog.UpdateThread();
                if (r == null)
                {
                    continue;
                }
                string uri = r.uri;
                string id  = r.id;

                try
                {
                    AssetBase a = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0, 30000, m_Auth);

                    if (a != null && m_Cache != null)
                    {
                        m_Cache.Cache(a);
                    }

                    List <AssetRetrievedEx> handlers;
                    lock (m_AssetHandlers)
                    {
                        handlers = m_AssetHandlers[id];
                        m_AssetHandlers.Remove(id);
                    }

                    if (handlers != null)
                    {
                        Util.FireAndForget(x =>
                        {
                            foreach (AssetRetrievedEx h in handlers)
                            {
                                try { h.Invoke(a); }
                                catch { }
                            }
                            handlers.Clear();
                        });
                    }
                }
                catch { }
            }
        }
        private void UndeliveredMessage(GridInstantMessage im)
        {
            if (im.dialog != (byte)InstantMessageDialog.MessageFromObject &&
                im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
                im.dialog != (byte)InstantMessageDialog.GroupNotice &&
                im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
                im.dialog != (byte)InstantMessageDialog.InventoryOffered)
            {
                return;
            }

            if (!m_ForwardOfflineGroupMessages)
            {
                if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
                    im.dialog == (byte)InstantMessageDialog.GroupInvitation)
                {
                    return;
                }
            }

            Scene scene = FindScene(new UUID(im.fromAgentID));

            if (scene == null)
            {
                scene = m_SceneList[0];
            }

            bool success = SynchronousRestObjectRequester.MakeRequest <GridInstantMessage, bool>(
                "POST", m_RestURL + "/SaveMessage/", im);

            if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
            {
                IClientAPI client = FindClient(new UUID(im.fromAgentID));
                if (client == null)
                {
                    return;
                }

                client.SendInstantMessage(new GridInstantMessage(
                                              null, new UUID(im.toAgentID),
                                              "System", new UUID(im.fromAgentID),
                                              (byte)InstantMessageDialog.MessageFromAgent,
                                              "User is not logged in. " +
                                              (success ? "Message saved." : "Message not saved"),
                                              false, new Vector3()));
            }
        }
        public virtual string Store(AssetBase asset)
        {
            if (asset.Local)
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }

                return(asset.ID);
            }

            string        newID      = string.Empty;
            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/";

                try
                {
                    newID = SynchronousRestObjectRequester.
                            MakeRequest <AssetBase, string>("POST", uri, asset);
                }
                catch (Exception e)
                {
                    m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message);
                }

                if (newID != String.Empty)
                {
                    // Placing this here, so that this work with old asset servers that don't send any reply back
                    // SynchronousRestObjectRequester returns somethins that is not an empty string
                    if (newID != null)
                    {
                        asset.ID = newID;
                    }

                    if (m_Cache != null)
                    {
                        m_Cache.Cache(asset);
                    }
                }
            }
            return(newID);
        }
        public virtual bool Delete(string id)
        {
            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id;

                SynchronousRestObjectRequester.
                MakeRequest <int, bool>("DELETE", uri, 0);
            }
            if (m_Cache != null)
            {
                m_Cache.Expire(id);
            }

            return(true);
        }
示例#7
0
        public AssetMetadata GetMetadata(string id)
        {
            if (m_Cache != null)
            {
                AssetBase fullAsset = m_Cache.Get(id);

                if (fullAsset != null)
                {
                    return(fullAsset.Metadata);
                }
            }

            string uri = m_ServerURI + "/assets/" + id + "/metadata";

            AssetMetadata asset = SynchronousRestObjectRequester.MakeRequest <int, AssetMetadata>("GET", uri, 0);

            return(asset);
        }
示例#8
0
        public override Aurora.Framework.AssetBase Get(string id)
        {
            Aurora.Framework.AssetBase asset = null;
            AssetBase rasset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
                if ((asset != null) && ((asset.Data != null) && (asset.Data.Length != 0)))
                {
                    return(asset);
                }
            }

            List <string> serverURIs = m_registry == null
                                          ? null
                                          : m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf(
                "AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            if (serverURIs != null)
            {
                foreach (string mServerUri in serverURIs)
                {
                    string uri = mServerUri + "/" + id;
                    rasset = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0);
                    asset  = TearDown(rasset);
                    if (m_Cache != null && asset != null)
                    {
                        m_Cache.Cache(asset);
                    }
                    if (asset != null)
                    {
                        return(asset);
                    }
                }
            }
            return(null);
        }
示例#9
0
        private void RetrieveInstantMessages(IClientAPI client)
        {
            if (m_RestURL == String.Empty)
            {
                return;
            }
            else
            {
                m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId);

                List <GridInstantMessage> msglist
                    = SynchronousRestObjectRequester.MakeRequest <UUID, List <GridInstantMessage> >(
                          "POST", m_RestURL + "/RetrieveMessages/", client.AgentId);

                if (msglist != null)
                {
                    foreach (GridInstantMessage im in msglist)
                    {
                        if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
                        {
                            // send it directly or else the item will be given twice
                            client.SendInstantMessage(im);
                        }
                        else
                        {
                            // Send through scene event manager so all modules get a chance
                            // to look at this message before it gets delivered.
                            //
                            // Needed for proper state management for stored group
                            // invitations
                            //

                            im.offline = 1;

                            Scene s = FindScene(client.AgentId);
                            if (s != null)
                            {
                                s.EventManager.TriggerIncomingInstantMessage(im);
                            }
                        }
                    }
                }
            }
        }
示例#10
0
        public void RegisterNewReceiver(IScriptModule scriptEngine, UUID channel, UUID objectID, UUID itemID, string uri)
        {
            if (!m_Channels.ContainsKey(itemID))
            {
                XmlRpcInfo info = new XmlRpcInfo();
                info.channel = channel;
                info.uri     = uri;

                bool success = SynchronousRestObjectRequester.MakeRequest <XmlRpcInfo, bool>(
                    "POST", m_ServerURI + "/RegisterChannel/", info);

                if (!success)
                {
                    m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
                }

                m_Channels[itemID] = channel;
            }
        }
示例#11
0
        public AssetBase Get(string id)
        {
            string uri = MapServer(id) + "/assets/" + id;

            AssetBase asset = null;

            if (m_Cache != null)
            {
                if (!m_Cache.Get(id, out asset))
                {
                    return(null);
                }
            }

            if (asset == null || asset.Data == null || asset.Data.Length == 0)
            {
                // XXX: Commented out for now since this has either never been properly operational or not for some time
                // as m_maxAssetRequestConcurrency was being passed as the timeout, not a concurrency limiting option.
                // Wasn't noticed before because timeout wasn't actually used.
                // Not attempting concurrency setting for now as this omission was discovered in release candidate
                // phase for OpenSimulator 0.8.  Need to revisit afterwards.
//                asset
//                    = SynchronousRestObjectRequester.MakeRequest<int, AssetBase>(
//                        "GET", uri, 0, m_maxAssetRequestConcurrency);

                asset = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0, m_Auth);


                if (m_Cache != null)
                {
                    if (asset != null)
                    {
                        m_Cache.Cache(asset);
                    }
                    else
                    {
                        m_Cache.CacheNegative(id);
                    }
                }
            }
            return(asset);
        }
示例#12
0
        public string Store(AssetBase asset)
        {
            if (asset.Temporary || asset.Local)
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }

                return(asset.ID);
            }

            string uri = m_ServerURI + "/assets/";

            string newID = string.Empty;

            try
            {
                newID = SynchronousRestObjectRequester.
                        MakeRequest <AssetBase, string>("POST", uri, asset);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message);
            }

            if (newID != String.Empty)
            {
                // Placing this here, so that this work with old asset servers that don't send any reply back
                // SynchronousRestObjectRequester returns somethins that is not an empty string
                if (newID != null)
                {
                    asset.ID = newID;
                }

                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }
            }
            return(newID);
        }
示例#13
0
        public virtual bool[] AssetsExist(string[] ids)
        {
            string uri = m_ServerURI + "/get_assets_exist";

            bool[] exist = null;
            try
            {
                exist = SynchronousRestObjectRequester.MakeRequest<string[], bool[]>("POST", uri, ids, m_Auth);
            }
            catch (Exception)
            {
                // This is most likely to happen because the server doesn't support this function,
                // so just silently return "doesn't exist" for all the assets.
            }
            
            if (exist == null)
                exist = new bool[ids.Length];

            return exist;
        }
示例#14
0
        public void ScriptRemoved(UUID itemID)
        {
            if (!m_Enabled)
            {
                return;
            }

            if (m_Channels.ContainsKey(itemID))
            {
                bool success = SynchronousRestObjectRequester.MakeRequest <UUID, bool>(
                    "POST", m_ServerURI + "/RemoveChannel/", m_Channels[itemID]);

                if (!success)
                {
                    m_log.Error("[XMLRPC GRID ROUTER] Error contacting server");
                }

                m_Channels.Remove(itemID);
            }
        }
示例#15
0
        public virtual bool UpdateContent(string id, byte[] data)
        {
            AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset == null)
            {
                AssetMetadata metadata = GetMetadata(id);
                if (metadata == null)
                {
                    return(false);
                }

                asset          = new AssetBase(metadata.FullID, metadata.Name, metadata.Type, UUID.Zero.ToString());
                asset.Metadata = metadata;
            }
            asset.Data = data;

            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id;

                if (SynchronousRestObjectRequester.
                    MakeRequest <AssetBase, bool>("POST", uri, asset))
                {
                    if (m_Cache != null)
                    {
                        m_Cache.Cache(asset);
                    }

                    return(true);
                }
            }
            return(false);
        }
示例#16
0
        private void OnMuteListRequest(IClientAPI client, uint crc)
        {
            //m_log.DebugFormat("[NSL MUTE LIST] Got MUTE LIST request for crc {0}", crc);

            int    cnt = 0;
            string str = "";
            string url = m_RestURL + "/RequestList/";

            //List<GridMuteList> mllist = SynchronousRestObjectPoster.BeginPostObject<UUID, List<GridMuteList>>("POST", url, client.AgentId);
            List <GridMuteList> mllist = SynchronousRestObjectRequester.MakeRequest <UUID, List <GridMuteList> >("POST", url, client.AgentId);

            while (mllist == null && cnt < 10)                          // retry
            //mllist = SynchronousRestObjectPoster.BeginPostObject<UUID, List<GridMuteList>>("POST", url, client.AgentId);
            {
                mllist = SynchronousRestObjectRequester.MakeRequest <UUID, List <GridMuteList> >("POST", url, client.AgentId);
                cnt++;
            }

            if (mllist != null)
            {
                foreach (GridMuteList ml in mllist)
                {
                    str += ml.muteType.ToString() + " " + ml.muteID.ToString() + " " + ml.muteName + "|" + ml.muteFlags.ToString() + "\n";
                }
            }
            else
            {
                m_log.ErrorFormat("[NSL MUTE LIST] Not response from mute.php");
                return;
            }

            string filename = "mutes" + client.AgentId.ToString();
            IXfer  xfer     = client.Scene.RequestModuleInterface <IXfer>();

            if (xfer != null)
            {
                byte[] byteArray = System.Text.Encoding.GetEncoding("UTF-8").GetBytes(str);
                xfer.AddNewFile(filename, byteArray);
                client.SendMuteListUpdate(filename);
            }
        }
示例#17
0
        private UUID CloneInventoryItem(UUID avatarID, UUID avatarFolder, InventoryItemBase item, bool modifyPerms)
        {
            if (avatarFolder != UUID.Zero)
            {
                InventoryItemBase clonedItem = new InventoryItemBase();
                clonedItem.Owner               = avatarID;
                clonedItem.AssetID             = item.AssetID;
                clonedItem.AssetType           = item.AssetType;
                clonedItem.BasePermissions     = item.BasePermissions;
                clonedItem.CreationDate        = item.CreationDate;
                clonedItem.CreatorId           = item.CreatorId;
                clonedItem.CreatorIdAsUuid     = item.CreatorIdAsUuid;
                clonedItem.CurrentPermissions  = item.CurrentPermissions;
                clonedItem.Description         = item.Description;
                clonedItem.EveryOnePermissions = item.EveryOnePermissions;
                clonedItem.Flags               = item.Flags;
                clonedItem.Folder              = avatarFolder;
                clonedItem.GroupID             = item.GroupID;
                clonedItem.GroupOwned          = item.GroupOwned;
                clonedItem.GroupPermissions    = item.GroupPermissions;
                clonedItem.ID              = UUID.Random();
                clonedItem.InvType         = item.InvType;
                clonedItem.Name            = item.Name;
                clonedItem.NextPermissions = item.NextPermissions;
                clonedItem.SalePrice       = item.SalePrice;
                clonedItem.SaleType        = item.SaleType;

                if (modifyPerms)
                {
                    ModifyPermissions(ref clonedItem);
                }

                SynchronousRestObjectRequester.MakeRequest <InventoryItemBase, bool>(
                    "POST", m_inventoryServerUrl + "AddNewItem/", clonedItem);

                return(clonedItem.ID);
            }

            return(UUID.Zero);
        }
示例#18
0
        private void UndeliveredMessage(GridInstantMessage im)
        {
            if (im.dialog != (byte)InstantMessageDialog.MessageFromObject &&
                im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
                im.dialog != (byte)InstantMessageDialog.GroupNotice &&
                im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
                im.dialog != (byte)InstantMessageDialog.InventoryOffered)
            {
                return;
            }

            if (!m_ForwardOfflineGroupMessages)
            {
                if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
                    im.dialog == (byte)InstantMessageDialog.GroupInvitation)
                {
                    return;
                }
            }

            bool success = SynchronousRestObjectRequester.MakeRequest <GridInstantMessage, bool>(
                "POST", m_RestURL + "/SaveMessage/", im, 10000);

            if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
            {
                IClientAPI client = FindClient(new UUID(im.fromAgentID));
                if (client == null)
                {
                    return;
                }

                client.SendInstantMessage(new GridInstantMessage(
                                              null, new UUID(im.toAgentID),
                                              "System", new UUID(im.fromAgentID),
                                              (byte)InstantMessageDialog.MessageFromAgent,
                                              "DSGrid: User not online - " +
                                              (success ? "message will be stored and delivered later." : "message will NOT be stored failed to deliver."),
                                              false, new Vector3()));
            }
        }
        public virtual bool GetExists(string id)
        {
            AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset != null)
            {
                return(true);
            }

            List <string> serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
#if (!ISWIN)
            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id + "/exists";

                bool exists = SynchronousRestObjectRequester.
                              MakeRequest <int, bool>("GET", uri, 0);
                if (exists)
                {
                    return(exists);
                }
            }
            return(false);
#else
            return(serverURIs.Select(m_ServerURI => m_ServerURI + "/" + id + "/exists").Select(uri => SynchronousRestObjectRequester.MakeRequest <int, bool>("GET", uri, 0)).FirstOrDefault(exists => exists));
#endif
        }
示例#20
0
        public AssetMetadata GetMetadata(string id)
        {
            if (m_Cache != null)
            {
                AssetBase fullAsset;
                if (!m_Cache.Get(id, out fullAsset))
                {
                    return(null);
                }

                if (fullAsset != null)
                {
                    return(fullAsset.Metadata);
                }
            }

            string uri = MapServer(id) + "/assets/" + id + "/metadata";

            AssetMetadata asset = SynchronousRestObjectRequester.MakeRequest <int, AssetMetadata>("GET", uri, 0, m_Auth);

            return(asset);
        }
示例#21
0
        public bool UpdateContent(string id, byte[] data)
        {
            AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset == null)
            {
                AssetMetadata metadata = GetMetadata(id);

                if (metadata == null)
                {
                    return(false);
                }

                asset          = new AssetBase();
                asset.Metadata = metadata;
            }

            asset.Data = data;

            string uri = m_ServerURI + "/assets/" + id;

            if (SynchronousRestObjectRequester.MakeRequest <AssetBase, bool>("POST", uri, asset))
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }

                return(true);
            }

            return(false);
        }
示例#22
0
        public AssetBase Get(string id)
        {
            string uri = m_ServerURI + "/assets/" + id;

            AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset == null)
            {
                asset = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0);

                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }
            }

            return(asset);
        }
示例#23
0
        public AssetBase Get(string id)
        {
//            m_log.DebugFormat("[ASSET SERVICE CONNECTOR]: Synchronous get request for {0}", id);

            string uri = m_ServerURI + "/assets/" + id;

            AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset == null)
            {
                asset = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0, m_Auth);

                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }
            }
            return(asset);
        }
        public bool IsAuthorizedForRegion(string userID, string firstname, string surname, string email, string regionName, string regionID, out string message)
        {
            // do a remote call to the authorization server specified in the AuthorizationServerURI
            m_log.InfoFormat("[AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} at remote server {1}", userID, m_ServerURI);

            string uri = m_ServerURI;

            AuthorizationRequest req = new AuthorizationRequest(userID, firstname, surname, email, regionName, regionID);

            AuthorizationResponse response;

            try
            {
                response = SynchronousRestObjectRequester.MakeRequest <AuthorizationRequest, AuthorizationResponse>("POST", uri, req);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[AUTHORIZATION CONNECTOR]: Unable to send authorize {0} for region {1} error thrown during comms with remote server. Reason: {2}", userID, regionID, e.Message);
                message = e.Message;
                return(m_ResponseOnFailure);
            }
            if (response == null)
            {
                message = "Null response";
                return(m_ResponseOnFailure);
            }
            m_log.DebugFormat("[AUTHORIZATION CONNECTOR] response from remote service was {0}", response.Message);
            message = response.Message;

            if (!response.IsAuthorized && message == "authorized")
            {
                message = "Not Authorized";
            }

            return(response.IsAuthorized);
        }
示例#25
0
        private bool CloneFolder(List <InventoryFolderBase> avatarInventory, UUID avID, UUID parentFolder, AvatarAppearance appearance, InventoryFolderBase templateFolder, List <InventoryFolderBase> templateFolders, bool modifyPermissions)
        {
            bool success          = false;
            UUID templateFolderId = templateFolder.ID;

            if (templateFolderId != UUID.Zero)
            {
                InventoryFolderBase toFolder = FindFolder(templateFolder.Name, parentFolder.Guid, avatarInventory);
                if (toFolder == null)
                {
                    //create new folder
                    toFolder          = new InventoryFolderBase();
                    toFolder.ID       = UUID.Random();
                    toFolder.Name     = templateFolder.Name;
                    toFolder.Owner    = avID;
                    toFolder.Type     = templateFolder.Type;
                    toFolder.Version  = 1;
                    toFolder.ParentID = parentFolder;
                    if (!SynchronousRestObjectRequester.MakeRequest <InventoryFolderBase, bool>(
                            "POST", m_inventoryServerUrl + "CreateFolder/", toFolder))
                    {
                        m_log.InfoFormat("[AvatarApperance] Couldn't make new folder {0} in users inventory", toFolder.Name);
                        return(false);
                    }
                    else
                    {
                        // m_log.InfoFormat("made new folder {0} in users inventory", toFolder.Name);
                    }
                }

                List <InventoryItemBase> templateItems = SynchronousRestObjectRequester.MakeRequest <Guid, List <InventoryItemBase> >(
                    "POST", m_inventoryServerUrl + "GetItems/", templateFolderId.Guid);
                if ((templateItems != null) && (templateItems.Count > 0))
                {
                    List <ClothesAttachment> wornClothes   = new List <ClothesAttachment>();
                    List <ClothesAttachment> attachedItems = new List <ClothesAttachment>();

                    foreach (InventoryItemBase item in templateItems)
                    {
                        UUID clonedItemId = CloneInventoryItem(avID, toFolder.ID, item, modifyPermissions);
                        if (clonedItemId != UUID.Zero)
                        {
                            int appearanceType = ItemIsPartOfAppearance(item, appearance);
                            if (appearanceType >= 0)
                            {
                                // UpdateAvatarAppearance(avID, appearanceType, clonedItemId, item.AssetID);
                                wornClothes.Add(new ClothesAttachment(appearanceType, clonedItemId, item.AssetID));
                            }

                            if (appearance != null)
                            {
                                int attachment = appearance.GetAttachpoint(item.ID);
                                if (attachment > 0)
                                {
                                    //UpdateAvatarAttachment(avID, attachment, clonedItemId, item.AssetID);
                                    attachedItems.Add(new ClothesAttachment(attachment, clonedItemId, item.AssetID));
                                }
                            }
                            success = true;
                        }
                    }

                    if ((wornClothes.Count > 0) || (attachedItems.Count > 0))
                    {
                        //Update the worn clothes and attachments
                        AvatarAppearance targetAppearance = GetAppearance(avID);
                        if (targetAppearance != null)
                        {
                            foreach (ClothesAttachment wornItem in wornClothes)
                            {
                                targetAppearance.Wearables[wornItem.Type].AssetID = wornItem.AssetID;
                                targetAppearance.Wearables[wornItem.Type].ItemID  = wornItem.ItemID;
                            }

                            foreach (ClothesAttachment wornItem in attachedItems)
                            {
                                targetAppearance.SetAttachment(wornItem.Type, wornItem.ItemID, wornItem.AssetID);
                            }

                            m_userDataBaseService.UpdateUserAppearance(avID, targetAppearance);
                            wornClothes.Clear();
                            attachedItems.Clear();
                        }
                    }
                }

                List <InventoryFolderBase> subFolders = FindSubFolders(templateFolder.ID.Guid, templateFolders);
                foreach (InventoryFolderBase subFolder in subFolders)
                {
                    if (subFolder.Name.ToLower() != "trash")
                    {
                        success = CloneFolder(avatarInventory, avID, toFolder.ID, appearance, subFolder, templateFolders, modifyPermissions);
                    }
                }
            }
            else
            {
                m_log.Info("[AvatarAppearance] Failed to find the template folder");
            }
            return(success);
        }
示例#26
0
        public string Store(AssetBase asset)
        {
            // Have to assign the asset ID here. This isn't likely to
            // trigger since current callers don't pass emtpy IDs
            // We need the asset ID to route the request to the proper
            // cluster member, so we can't have the server assign one.
            if (asset.ID == string.Empty || asset.ID == stringUUIDZero)
            {
                if (asset.FullID == UUID.Zero)
                {
                    asset.FullID = UUID.Random();
                }
                m_log.WarnFormat("[Assets] Zero ID: {0}", asset.Name);
                asset.ID = asset.FullID.ToString();
            }

            if (asset.FullID == UUID.Zero)
            {
                UUID uuid = UUID.Zero;
                if (UUID.TryParse(asset.ID, out uuid))
                {
                    asset.FullID = uuid;
                }
                if (asset.FullID == UUID.Zero)
                {
                    m_log.WarnFormat("[Assets] Zero IDs: {0}", asset.Name);
                    asset.FullID = UUID.Random();
                    asset.ID     = asset.FullID.ToString();
                }
            }

            if (m_Cache != null)
            {
                m_Cache.Cache(asset);
            }

            if (asset.Temporary || asset.Local)
            {
                return(asset.ID);
            }

            string uri = MapServer(asset.FullID.ToString()) + "/assets/";

            string newID = null;

            try
            {
                newID = SynchronousRestObjectRequester.
                        MakeRequest <AssetBase, string>("POST", uri, asset, 10000, m_Auth);
            }
            catch
            {
                newID = null;
            }

            if (newID == null || newID == String.Empty || newID == stringUUIDZero)
            {
                //The asset upload failed, try later
                lock (m_sendRetries)
                {
                    if (m_sendRetries[0] == null)
                    {
                        m_sendRetries[0] = new List <AssetBase>();
                    }
                    List <AssetBase> m_queue = m_sendRetries[0];
                    m_queue.Add(asset);
                    m_log.WarnFormat("[Assets] Upload failed: {0} type {1} will retry later",
                                     asset.ID.ToString(), asset.Type.ToString());
                    m_retryTimer.Start();
                }
            }
            else
            {
                if (newID != asset.ID)
                {
                    // Placing this here, so that this work with old asset servers that don't send any reply back
                    // SynchronousRestObjectRequester returns somethins that is not an empty string

                    asset.ID = newID;
                }
            }
            if (m_Cache != null)
            {
                m_Cache.Cache(asset);
            }

            return(asset.ID);
        }
        private void UndeliveredMessage(GridInstantMessage im)
        {
            if (im.dialog != (byte)InstantMessageDialog.MessageFromObject &&
                im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
                im.dialog != (byte)InstantMessageDialog.GroupNotice &&
                im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
                im.dialog != (byte)InstantMessageDialog.InventoryOffered &&
                im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered)
            {
                return;
            }

            if (!m_ForwardOfflineGroupMessages)
            {
                if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
                    im.dialog == (byte)InstantMessageDialog.GroupInvitation)
                {
                    return;
                }
            }

            Scene scene = FindScene(new UUID(im.fromAgentID));

            if (scene == null)
            {
                scene = m_SceneList[0];
            }

// Avination new code
//            SendReply reply = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, SendReply>(
//                    "POST", m_RestURL+"/SaveMessage/?scope=" +
//                    scene.RegionInfo.ScopeID.ToString(), im);

// current opensim and osgrid compatible
            bool success = SynchronousRestObjectRequester.MakeRequest <GridInstantMessage, bool>(
                "POST", m_RestURL + "/SaveMessage/", im, 10000);

// current opensim and osgrid compatible end

            if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
            {
                IClientAPI client = FindClient(new UUID(im.fromAgentID));
                if (client == null)
                {
                    return;
                }

/* Avination new code
 *              if (reply.Message == String.Empty)
 *                  reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved");
 *
 *              bool sendReply = true;
 *
 *              switch (reply.Disposition)
 *              {
 *              case 0: // Normal
 *                  break;
 *              case 1: // Only once per user
 *                  if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID)))
 *                  {
 *                      sendReply = false;
 *                  }
 *                  else
 *                  {
 *                      if (!m_repliesSent.ContainsKey(client))
 *                          m_repliesSent[client] = new List<UUID>();
 *                      m_repliesSent[client].Add(new UUID(im.toAgentID));
 *                  }
 *                  break;
 *              }
 *
 *              if (sendReply)
 *              {
 *                  client.SendInstantMessage(new GridInstantMessage(
 *                          null, new UUID(im.toAgentID),
 *                          "System", new UUID(im.fromAgentID),
 *                          (byte)InstantMessageDialog.MessageFromAgent,
 *                          reply.Message,
 *                          false, new Vector3()));
 *              }
 */
// current opensim and osgrid compatible
                client.SendInstantMessage(new GridInstantMessage(
                                              null, new UUID(im.toAgentID),
                                              "System", new UUID(im.fromAgentID),
                                              (byte)InstantMessageDialog.MessageFromAgent,
                                              "User is not logged in. " +
                                              (success ? "Message saved." : "Message not saved"),
                                              false, new Vector3()));
// current opensim and osgrid compatible end
            }
        }
示例#28
0
        private void UndeliveredMessage(GridInstantMessage im)
        {
            if (im.dialog != (byte)InstantMessageDialog.MessageFromObject &&
                im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
                im.dialog != (byte)InstantMessageDialog.GroupNotice &&
                im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
                im.dialog != (byte)InstantMessageDialog.InventoryOffered &&
                im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered)
            {
                return;
            }

            if (!m_ForwardOfflineGroupMessages)
            {
                if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
                    im.dialog == (byte)InstantMessageDialog.GroupInvitation)
                {
                    return;
                }
            }

            if (m_UseNewAvnCode)
            {
                Scene scene = FindScene(new UUID(im.fromAgentID));
                if (scene == null)
                {
                    scene = m_SceneList[0];
                }

                UUID      scopeID = scene.RegionInfo.ScopeID;
                SendReply reply   = SynchronousRestObjectRequester.MakeRequest <GridInstantMessage, SendReply>(
                    "POST", m_RestURL + "/SaveMessage/?scope=" + scopeID.ToString(), im, 20000);

                if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
                {
                    IClientAPI client = FindClient(new UUID(im.fromAgentID));
                    if (client == null)
                    {
                        return;
                    }

                    if (string.IsNullOrEmpty(reply.Message))
                    {
                        reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved");
                    }

                    bool sendReply = true;

                    switch (reply.Disposition)
                    {
                    case 0:     // Normal
                        break;

                    case 1:     // Only once per user
                        if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID)))
                        {
                            sendReply = false;
                        }
                        else
                        {
                            if (!m_repliesSent.ContainsKey(client))
                            {
                                m_repliesSent[client] = new List <UUID>();
                            }
                            m_repliesSent[client].Add(new UUID(im.toAgentID));
                        }
                        break;
                    }

                    if (sendReply)
                    {
                        client.SendInstantMessage(new GridInstantMessage(
                                                      null, new UUID(im.toAgentID),
                                                      "System", new UUID(im.fromAgentID),
                                                      (byte)InstantMessageDialog.MessageFromAgent,
                                                      reply.Message,
                                                      false, new Vector3()));
                    }
                }
            }
            else
            {
                bool success = SynchronousRestObjectRequester.MakeRequest <GridInstantMessage, bool>(
                    "POST", m_RestURL + "/SaveMessage/", im, 20000);

                if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
                {
                    IClientAPI client = FindClient(new UUID(im.fromAgentID));
                    if (client == null)
                    {
                        return;
                    }

                    client.SendInstantMessage(new GridInstantMessage(
                                                  null, new UUID(im.toAgentID),
                                                  "System", new UUID(im.fromAgentID),
                                                  (byte)InstantMessageDialog.MessageFromAgent,
                                                  "User is not logged in. " +
                                                  (success ? "Message saved." : "Message not saved"),
                                                  false, new Vector3()));
                }
            }
        }
        public virtual string Store(AssetBase asset)
        {
            // Have to assign the asset ID here. This isn't likely to
            // trigger since current callers don't pass emtpy IDs
            // We need the asset ID to route the request to the proper
            // cluster member, so we can't have the server assign one.
            if (asset.ID == string.Empty || asset.ID == stringUUIDZero)
            {
                if (asset.FullID == UUID.Zero)
                {
                    asset.FullID = UUID.Random();
                }
                m_log.WarnFormat("[Assets] Zero ID: {0}", asset.Name);
                asset.ID = asset.FullID.ToString();
            }

            if (asset.FullID == UUID.Zero)
            {
                UUID uuid = UUID.Zero;
                if (UUID.TryParse(asset.ID, out uuid))
                {
                    asset.FullID = uuid;
                }
                if (asset.FullID == UUID.Zero)
                {
                    m_log.WarnFormat("[Assets] Zero IDs: {0}", asset.Name);
                    asset.FullID = UUID.Random();
                    asset.ID     = asset.FullID.ToString();
                }
            }

            if (m_Cache != null)
            {
                m_Cache.Cache(asset);
            }

            if (asset.Temporary || asset.Local)
            {
                return(asset.ID);
            }

            if (m_ServerURI == null)
            {
                return(null);
            }

            string uri = m_ServerURI + "/assets/";

            string newID = null;

            try
            {
                newID = SynchronousRestObjectRequester.MakeRequest <AssetBase, string>("POST", uri, asset, 10000, m_Auth);
            }
            catch
            {
                newID = null;
            }

            if (string.IsNullOrEmpty(newID) || newID == stringUUIDZero)
            {
                return(string.Empty);
            }
            else
            {
                if (newID != asset.ID)
                {
                    // Placing this here, so that this work with old asset servers that don't send any reply back
                    // SynchronousRestObjectRequester returns somethins that is not an empty string
                    asset.ID = newID;
                    if (m_Cache != null)
                    {
                        m_Cache.Cache(asset);
                    }
                }
            }

            return(asset.ID);
        }
示例#30
0
        public string Store(AssetBase asset)
        {
            if (asset.Local)
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }

                try {
                    // it is also possible to disable Surabaya. I'd favor to configure
                    // Surabaya in the CAPS Section of the OpenSim.ini but right now with still some
                    // old Viwers which do not support http getTexture() I stick to this hack.
                    if (surabayaServerEnabled)
                    {
                        // Create an XML of the Texture in order to transport the Asset to Surabaya.
                        if (asset.Type == (sbyte)AssetType.Texture)
                        {
                            XmlSerializer xs           = new XmlSerializer(typeof(AssetBase));
                            byte[]        result       = ServerUtils.SerializeResult(xs, asset);
                            string        resultString = Util.UTF8.GetString(result);
                            // AKIDO: remove commented code
                            //m_log.DebugFormat("Dump of XML: {0}", resultString);
                            OSDMap serializedAssetCaps = new OSDMap();
                            serializedAssetCaps.Add("assetID", asset.ID);
                            if (asset.Temporary)
                            {
                                serializedAssetCaps.Add("temporary", "true");
                            }
                            else
                            {
                                serializedAssetCaps.Add("temporary", "false");
                            }
                            serializedAssetCaps.Add("serializedAsset", resultString);

                            int tickstart = Util.EnvironmentTickCount();

                            OSDMap surabayaAnswer = WebUtil.PostToService(surabayaServerURI + "/cachetexture", serializedAssetCaps, 3000);

                            if (surabayaAnswer != null)
                            {
                                // m_log.InfoFormat("Caching baked Texture: {0}",surabayaAnswer.ToString());
                                OSDBoolean isSuccess = (OSDBoolean)surabayaAnswer["Success"];
                                if (isSuccess)
                                {
                                    OSDMap answer         = (OSDMap)surabayaAnswer["_Result"];
                                    string surabayaResult = answer["result"];
                                    if (!surabayaResult.Equals("ok"))
                                    {
                                        m_log.ErrorFormat("Error PostingAgent Data: {0}", surabayaAnswer["reason"]);
                                    }
                                    else
                                    {
                                        m_log.InfoFormat("Caching baked Texture {0} was successful in {1}ms", asset.ID, Util.EnvironmentTickCountSubtract(tickstart));
                                    }
                                }
                                else
                                {
                                    m_log.InfoFormat("Caching baked Texture {0} was not successful: {1}", asset.ID, surabayaAnswer["Message"]);
                                }
                            }
                            else
                            {
                                m_log.ErrorFormat("Caching baked texture {0} to Surabaya returned NULL after {1}ms", asset.ID, Util.EnvironmentTickCountSubtract(tickstart));
                            }
                        }
                    }
                } catch (Exception ex) {
                    m_log.Error("Exception while caching baked texture to Surabaya: ", ex);
                }

                return(asset.ID);
            }

            string uri = m_ServerURI + "/assets/";

            string newID = string.Empty;

            try
            {
                newID = SynchronousRestObjectRequester.
                        MakeRequest <AssetBase, string>("POST", uri, asset);
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message);
            }

            if (newID != String.Empty)
            {
                // Placing this here, so that this work with old asset servers that don't send any reply back
                // SynchronousRestObjectRequester returns somethins that is not an empty string
                if (newID != null)
                {
                    asset.ID = newID;
                }

                if (m_Cache != null)
                {
                    m_Cache.Cache(asset);
                }
            }
            return(newID);
        }