/// <summary>
        ///     Create the calling card inventory item in the user's inventory
        /// </summary>
        /// <param name="client"></param>
        /// <param name="creator"></param>
        /// <param name="folder"></param>
        /// <param name="name"></param>
        public void CreateCallingCard(IClientAPI client, UUID creator, UUID folder, string name)
        {
            MainConsole.Instance.Debug("[Universe CALLING CARD MODULE]: Creating calling card for " + client.Name);
            InventoryItemBase item = new InventoryItemBase
            {
                AssetID             = UUID.Zero,
                AssetType           = (int)AssetType.CallingCard,
                BasePermissions     = (uint)(PermissionMask.Copy | PermissionMask.Modify),
                CurrentPermissions  = (uint)(PermissionMask.Copy | PermissionMask.Modify),
                NextPermissions     = (uint)PermissionMask.None,
                CreationDate        = Util.UnixTimeSinceEpoch(),
                CreatorId           = creator.ToString(),
                Description         = "",
                EveryOnePermissions = (uint)PermissionMask.None,
                Flags      = 0,
                Folder     = folder,
                GroupID    = UUID.Zero,
                GroupOwned = false,
                ID         = UUID.Random(),
                InvType    = (int)InventoryType.CallingCard,
                Name       = name,
                Owner      = client.AgentId,
                SalePrice  = 10,
                SaleType   = (byte)SaleType.Not
            };


            ILLClientInventory inventory = client.Scene.RequestModuleInterface <ILLClientInventory>();

            if (inventory != null)
            {
                inventory.AddInventoryItemAsync(client, item);
            }
        }
        /// <summary>
        /// Create the calling card inventory item in the user's inventory
        /// </summary>
        /// <param name="client"></param>
        /// <param name="creator"></param>
        /// <param name="folder"></param>
        /// <param name="name"></param>
        public void CreateCallingCard(IClientAPI client, UUID creator, UUID folder, string name)
        {
            m_log.Debug("[AURORA CALLING CARD MODULE]: Creating calling card for " + client.Name);
            InventoryItemBase item = new InventoryItemBase();

            item.AssetID             = UUID.Zero;
            item.AssetType           = (int)AssetType.CallingCard;
            item.BasePermissions     = (uint)(PermissionMask.Copy | PermissionMask.Modify);
            item.CreationDate        = Util.UnixTimeSinceEpoch();
            item.CreatorId           = creator.ToString();
            item.CurrentPermissions  = item.BasePermissions;
            item.Description         = "";
            item.EveryOnePermissions = (uint)PermissionMask.None;
            item.Flags           = 0;
            item.Folder          = folder;
            item.GroupID         = UUID.Zero;
            item.GroupOwned      = false;
            item.ID              = UUID.Random();
            item.InvType         = (int)InventoryType.CallingCard;
            item.Name            = name;
            item.NextPermissions = item.EveryOnePermissions;
            item.Owner           = client.AgentId;
            item.SalePrice       = 10;
            item.SaleType        = (byte)SaleType.Not;
            ILLClientInventory inventory = client.Scene.RequestModuleInterface <ILLClientInventory>();

            if (inventory != null)
            {
                inventory.AddInventoryItem(client, item);
            }
        }
Exemple #3
0
        private Hashtable CopyInventoryFromNotecard(Hashtable mDhttpMethod, UUID agentID)
        {
            OSDMap rm       = (OSDMap)OSDParser.DeserializeLLSDXml((string)mDhttpMethod["requestbody"]);
            UUID   FolderID = rm["folder-id"].AsUUID();
            UUID   ItemID   = rm["item-id"].AsUUID();
            //UUID NotecardID = rm["notecard-id"].AsUUID();
            //There is an object-id as well, but objects arn't handled through this currently as of Sept. 2010

            //TODO: Check notecard for this
            //SLUtil.ParseNotecardToList
            InventoryItemBase  item            = null;
            ILLClientInventory inventoryModule = m_scene.RequestModuleInterface <ILLClientInventory>();

            if (inventoryModule != null)
            {
                item = inventoryModule.GiveInventoryItem(agentID, agentID, ItemID, FolderID);
            }

            IClientAPI client;

            m_scene.TryGetClient(agentID, out client);
            client.SendBulkUpdateInventory(item);

            //Send back data
            Hashtable responsedata = new Hashtable();

            responsedata["int_response_code"]   = 200; //501; //410; //404;
            responsedata["content_type"]        = "text/plain";
            responsedata["keepalive"]           = false;
            responsedata["str_response_string"] = "";
            return(responsedata);
        }
Exemple #4
0
        public DateTime llRemoteLoadScriptPin(string target, string name, int pin, int running, int start_param)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.None, "LSL", m_host, "LSL", m_itemID))
            {
                return(DateTime.Now);
            }

            bool found  = false;
            UUID destId = UUID.Zero;
            UUID srcId  = UUID.Zero;

            if (!UUID.TryParse(target, out destId))
            {
                Error("llRemoteLoadScriptPin", "Can't parse key '" + target + "'");
                return(DateTime.Now);
            }

            // target must be a different prim than the one containing the script
            if (m_host.UUID == destId)
            {
                return(DateTime.Now);
            }

            // copy the first script found with this inventory name
            lock (m_host.TaskInventory) {
                foreach (KeyValuePair <UUID, TaskInventoryItem> inv in m_host.TaskInventory)
                {
                    if (inv.Value.Name == name)
                    {
                        // make sure the object is a script
                        if (10 == inv.Value.Type)
                        {
                            found = true;
                            srcId = inv.Key;
                            break;
                        }
                    }
                }
            }

            if (!found)
            {
                Error("llRemoteLoadScriptPin", "Can't find script '" + name + "'");
                return(DateTime.Now);
            }

            // the rest of the permission checks are done in RezScript, so check the pin there as well
            ILLClientInventory inventoryModule = World.RequestModuleInterface <ILLClientInventory>();

            if (inventoryModule != null)
            {
                inventoryModule.RezScript(srcId, m_host, destId, pin, running, start_param);
            }
            // this will cause the delay even if the script pin or permissions were wrong - seems ok
            return(PScriptSleep(m_sleepMsOnRemoteLoadScriptPin));
        }
Exemple #5
0
        public virtual void AddRegion(Scene scene)
        {
            if (!m_Enabled)
            {
                return;
            }

            m_scene = scene;
            m_LLCLientInventoryModule = scene.RequestModuleInterface <ILLClientInventory>();

            scene.RegisterModuleInterface <IInventoryAccessModule>(this);
            scene.EventManager.OnNewClient     += OnNewClient;
            scene.EventManager.OnClosingClient += OnClosingClient;
        }
        private void DoCreateItem(uint callbackID, IClientAPI remoteClient)
        {
            m_asset.ID = m_userTransactions.Manager.MyScene.AssetService.Store(m_asset);

            IMonitorModule monitorModule = m_userTransactions.Manager.MyScene.RequestModuleInterface <IMonitorModule>();

            if (monitorModule != null)
            {
                INetworkMonitor networkMonitor =
                    (INetworkMonitor)
                    monitorModule.GetMonitor(m_userTransactions.Manager.MyScene.RegionInfo.RegionID.ToString(),
                                             MonitorModuleHelper.NetworkMonitor);
                networkMonitor.AddPendingUploads(-1);
            }

            InventoryItemBase item = new InventoryItemBase
            {
                Owner               = remoteClient.AgentId,
                CreatorId           = remoteClient.AgentId.ToString(),
                ID                  = UUID.Random(),
                AssetID             = m_asset.ID,
                Description         = m_description,
                Name                = m_name,
                AssetType           = type,
                InvType             = invType,
                Folder              = InventFolder,
                BasePermissions     = 0x7fffffff,
                CurrentPermissions  = 0x7fffffff,
                GroupPermissions    = 0,
                EveryOnePermissions = 0,
                NextPermissions     = nextPerm,
                Flags               = wearableType,
                CreationDate        = Util.UnixTimeSinceEpoch()
            };

            ILLClientInventory inventoryModule =
                m_userTransactions.Manager.MyScene.RequestModuleInterface <ILLClientInventory>();

            if (inventoryModule != null && inventoryModule.AddInventoryItem(item))
            {
                remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
            }
            else
            {
                remoteClient.SendAlertMessage("Unable to create inventory item");
            }
        }
Exemple #7
0
 public virtual void RegionLoaded(IScene scene)
 {
     m_LLCLientInventoryModule = scene.RequestModuleInterface <ILLClientInventory>();
 }
        private void OnInstantMessage(IClientAPI client, GridInstantMessage im)
        {
            //MainConsole.Instance.InfoFormat("[INVENTORY TRANSFER]: OnInstantMessage {0}", im.dialog);
            IScene clientScene = FindClientScene(client.AgentId);

            if (clientScene == null) // Something seriously wrong here.
            {
                MainConsole.Instance.DebugFormat("[INVENTORY TRANSFER]: Cannot find originating user scene");
                return;
            }

            if (im.Dialog == (byte)InstantMessageDialog.InventoryOffered)
            {
                //MainConsole.Instance.DebugFormat("Asset type {0}", ((AssetType)im.binaryBucket[0]));

                if (im.BinaryBucket.Length < 17) // Invalid
                {
                    MainConsole.Instance.DebugFormat("[INVENTORY TRANSFER]: Invalid length {0} for asset type {1}",
                                                     im.BinaryBucket.Length, ((AssetType)im.BinaryBucket[0]));
                    return;
                }

                UUID           receipientID       = im.ToAgentID;
                IScenePresence recipientUser      = null;
                IScene         recipientUserScene = FindClientScene(client.AgentId);
                if (recipientUserScene != null)
                {
                    recipientUser = recipientUserScene.GetScenePresence(receipientID);
                }
                UUID copyID;

                // user is online now...
                if (recipientUser != null)
                {
                    // First byte is the asset type
                    AssetType assetType = (AssetType)im.BinaryBucket [0];

                    if (assetType == AssetType.Folder)
                    {
                        UUID folderID = new UUID(im.BinaryBucket, 1);

                        MainConsole.Instance.DebugFormat(
                            "[INVENTORY TRANSFER]: Inserting original folder {0} into agent {1}'s inventory",
                            folderID, im.ToAgentID);


                        clientScene.InventoryService.GiveInventoryFolderAsync(
                            receipientID,
                            client.AgentId,
                            folderID,
                            UUID.Zero,
                            (folder) =>
                        {
                            if (folder == null)
                            {
                                client.SendAgentAlertMessage("Can't find folder to give. Nothing given.", false);
                                return;
                            }

                            // The outgoing binary bucket should contain only the byte which signals an asset folder is
                            // being copied and the following bytes for the copied folder's UUID
                            copyID              = folder.ID;
                            byte[] copyIDBytes  = copyID.GetBytes();
                            im.BinaryBucket     = new byte[1 + copyIDBytes.Length];
                            im.BinaryBucket [0] = (byte)AssetType.Folder;
                            Array.Copy(copyIDBytes, 0, im.BinaryBucket, 1, copyIDBytes.Length);

//                                m_currencyService.UserCurrencyTransfer(im.FromAgentID, im.ToAgentID, 0,
//                                    "Inworld inventory folder transfer", TransactionType.GiveInventory, UUID.Zero);
                            if (moneyService != null)
                            {
                                moneyService.Transfer(im.ToAgentID, im.FromAgentID, 0,
                                                      "Inworld inventory folder transfer", TransactionType.GiveInventory);
                            }

                            if (recipientUser != null)
                            {
                                recipientUser.ControllingClient.SendBulkUpdateInventory(folder);
                                im.SessionID = copyID;
                                recipientUser.ControllingClient.SendInstantMessage(im);
                            }
                        });
                    }
                    else
                    {
                        // First byte of the array is probably the item type
                        // Next 16 bytes are the UUID

                        UUID itemID = new UUID(im.BinaryBucket, 1);

                        MainConsole.Instance.DebugFormat(
                            "[INVENTORY TRANSFER]: (giving) Inserting item {0} into agent {1}'s inventory",
                            itemID, im.ToAgentID);

                        clientScene.InventoryService.GiveInventoryItemAsync(
                            im.ToAgentID,
                            im.FromAgentID,
                            itemID,
                            UUID.Zero,
                            false,
                            (itemCopy) =>
                        {
                            if (itemCopy == null)
                            {
                                MainConsole.Instance.DebugFormat(
                                    "[INVENTORY TRANSFER]: (giving) Unable to find item {0} to give to agent {1}'s inventory",
                                    itemID, im.ToAgentID);
                                client.SendAgentAlertMessage("Can't find item to give. Nothing given.", false);
                                return;
                            }

                            copyID = itemCopy.ID;
                            Array.Copy(copyID.GetBytes(), 0, im.BinaryBucket, 1, 16);

                            if (moneyService != null)
                            {
                                moneyService.Transfer(im.ToAgentID, im.FromAgentID, 0,
                                                      "Inworld inventory item transfer", TransactionType.GiveInventory);
                            }

                            if (recipientUser != null)
                            {
                                recipientUser.ControllingClient.SendBulkUpdateInventory(itemCopy);
                                im.SessionID = itemCopy.ID;
                                recipientUser.ControllingClient.SendInstantMessage(im);
                            }
                        });
                    }
                }
                else
                {
                    // recipient is offline.
                    // Send the IM to the recipient. The item is already
                    // in their inventory, so it will not be lost if
                    // they are offline.
                    //
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im);
                    }
                }
            }
            else if (im.Dialog == (byte)InstantMessageDialog.InventoryAccepted)
            {
                IScenePresence user = clientScene.GetScenePresence(im.ToAgentID);
                MainConsole.Instance.DebugFormat("[INVENTORY TRANSFER]: Acceptance message received");

                if (user != null) // Local
                {
                    user.ControllingClient.SendInstantMessage(im);
                }
                else
                {
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im);
                    }
                }
            }
            else if (im.Dialog == (byte)InstantMessageDialog.InventoryDeclined)
            {
                // Here, the recipient is local and we can assume that the
                // inventory is loaded. Courtesy of the above bulk update,
                // It will have been pushed to the client, too
                //
                IInventoryService invService = clientScene.InventoryService;
                MainConsole.Instance.DebugFormat("[INVENTORY TRANSFER]: Declined message received");

                InventoryFolderBase trashFolder =
                    invService.GetFolderForType(client.AgentId, InventoryType.Unknown, AssetType.TrashFolder);

                UUID inventoryID = im.SessionID; // The inventory item/folder, back from it's trip

                InventoryItemBase   item   = invService.GetItem(client.AgentId, inventoryID);
                InventoryFolderBase folder = null;

                if (item != null && trashFolder != null)
                {
                    item.Folder = trashFolder.ID;

                    // Diva comment: can't we just update this item???
                    List <UUID> uuids = new List <UUID> {
                        item.ID
                    };
                    invService.DeleteItems(item.Owner, uuids);
                    ILLClientInventory inventory = client.Scene.RequestModuleInterface <ILLClientInventory>();
                    if (inventory != null)
                    {
                        inventory.AddInventoryItemAsync(client, item);
                    }
                }
                else
                {
                    folder = new InventoryFolderBase(inventoryID, client.AgentId);
                    folder = invService.GetFolder(folder);

                    if (folder != null & trashFolder != null)
                    {
                        folder.ParentID = trashFolder.ID;
                        invService.MoveFolder(folder);
                        client.SendBulkUpdateInventory(folder);
                    }
                }

                if ((null == item && null == folder) | null == trashFolder)
                {
                    string reason = String.Empty;

                    if (trashFolder == null)
                    {
                        reason += " Trash folder not found.";
                    }
                    if (item == null)
                    {
                        reason += " Item not found.";
                    }
                    if (folder == null)
                    {
                        reason += " Folder not found.";
                    }

                    client.SendAgentAlertMessage("Unable to delete " +
                                                 "received inventory" + reason, false);
                }

                //m_currencyService.UserCurrencyTransfer(im.FromAgentID, im.ToAgentID, 0,
                //    "Inworld inventory transfer declined", TransactionType.GiveInventory, UUID.Zero);
                if (moneyService != null)
                {
                    moneyService.Transfer(im.ToAgentID, im.FromAgentID, 0,
                                          "Inworld inventory transfer declined", TransactionType.GiveInventory);
                }

                IScenePresence user = clientScene.GetScenePresence(im.ToAgentID);

                if (user != null) // Local
                {
                    user.ControllingClient.SendInstantMessage(im);
                }
                else
                {
                    if (m_TransferModule != null)
                    {
                        m_TransferModule.SendInstantMessage(im);
                    }
                }
            }
        }
        public bool BuyObject(IClientAPI remoteClient, UUID categoryID, uint localID, byte saleType, int salePrice)
        {
            ISceneChildEntity part = m_scene.GetSceneObjectPart(localID);

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

            if (part.ParentEntity == null)
            {
                return(false);
            }

            ISceneEntity       group           = part.ParentEntity;
            ILLClientInventory inventoryModule = m_scene.RequestModuleInterface <ILLClientInventory>();

            switch (saleType)
            {
            case 1:     // Sell as original (in-place sale)
                uint effectivePerms = group.GetEffectivePermissions();

                if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
                    }
                    return(false);
                }

                group.SetOwnerId(remoteClient.AgentId);
                group.SetRootPartOwner(part, remoteClient.AgentId, remoteClient.ActiveGroupId);

                if (m_scene.Permissions.PropagatePermissions())
                {
                    foreach (ISceneChildEntity child in group.ChildrenEntities())
                    {
                        child.Inventory.ChangeInventoryOwner(remoteClient.AgentId);
                        child.TriggerScriptChangedEvent(Changed.OWNER);
                        child.ApplyNextOwnerPermissions();
                    }
                }

                part.ObjectSaleType = 0;
                part.SalePrice      = 10;

                group.HasGroupChanged = true;
                part.GetProperties(remoteClient);
                part.TriggerScriptChangedEvent(Changed.OWNER);
                group.ResumeScripts();
                part.ScheduleUpdate(PrimUpdateFlags.ForcedFullUpdate);

                break;

            case 2:     // Sell a copy
                Vector3 inventoryStoredPosition = new Vector3
                                                      (((group.AbsolutePosition.X > m_scene.RegionInfo.RegionSizeX)
                              ? m_scene.RegionInfo.RegionSizeX - 1
                              : group.AbsolutePosition.X)
                                                      ,
                                                      (group.AbsolutePosition.X > m_scene.RegionInfo.RegionSizeY)
                             ? m_scene.RegionInfo.RegionSizeY - 1
                             : group.AbsolutePosition.X,
                                                      group.AbsolutePosition.Z);

                Vector3 originalPosition = group.AbsolutePosition;

                group.AbsolutePosition = inventoryStoredPosition;

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)group);
                group.AbsolutePosition = originalPosition;

                uint perms = group.GetEffectivePermissions();

                if ((perms & (uint)PermissionMask.Transfer) == 0)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(remoteClient, "This item doesn't appear to be for sale");
                    }
                    return(false);
                }

                AssetBase asset = new AssetBase(UUID.Random(), part.Name,
                                                AssetType.Object, group.OwnerID)
                {
                    Description = part.Description, Data = Utils.StringToBytes(sceneObjectXml)
                };
                asset.ID = m_scene.AssetService.Store(asset);

                InventoryItemBase item = new InventoryItemBase
                {
                    CreatorId   = part.CreatorID.ToString(),
                    CreatorData = part.CreatorData,
                    ID          = UUID.Random(),
                    Owner       = remoteClient.AgentId,
                    AssetID     = asset.ID,
                    Description = asset.Description,
                    Name        = asset.Name,
                    AssetType   = asset.Type,
                    InvType     = (int)InventoryType.Object,
                    Folder      = categoryID
                };


                uint nextPerms = (perms & 7) << 13;
                if ((nextPerms & (uint)PermissionMask.Copy) == 0)
                {
                    perms &= ~(uint)PermissionMask.Copy;
                }
                if ((nextPerms & (uint)PermissionMask.Transfer) == 0)
                {
                    perms &= ~(uint)PermissionMask.Transfer;
                }
                if ((nextPerms & (uint)PermissionMask.Modify) == 0)
                {
                    perms &= ~(uint)PermissionMask.Modify;
                }

                item.BasePermissions     = perms & part.NextOwnerMask;
                item.CurrentPermissions  = perms & part.NextOwnerMask;
                item.NextPermissions     = part.NextOwnerMask;
                item.EveryOnePermissions = part.EveryoneMask &
                                           part.NextOwnerMask;
                item.GroupPermissions = part.GroupMask &
                                        part.NextOwnerMask;
                item.CurrentPermissions |= 16;     // Slam!
                item.CreationDate        = Util.UnixTimeSinceEpoch();

                if (inventoryModule != null)
                {
                    if (inventoryModule.AddInventoryItem(item))
                    {
                        remoteClient.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else
                    {
                        if (m_dialogModule != null)
                        {
                            m_dialogModule.SendAlertToUser(remoteClient,
                                                           "Cannot buy now. Your inventory is unavailable");
                        }
                        return(false);
                    }
                }
                break;

            case 3:     // Sell contents
                List <UUID> invList = part.Inventory.GetInventoryList();

#if (!ISWIN)
                bool okToSell = true;
                foreach (UUID invId in invList)
                {
                    TaskInventoryItem item1 = part.Inventory.GetInventoryItem(invId);
                    if ((item1.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
                    {
                        okToSell = false;
                        break;
                    }
                }
#else
                bool okToSell = invList.Select(invID => part.Inventory.GetInventoryItem(invID)).All(item1 => (item1.CurrentPermissions & (uint)PermissionMask.Transfer) != 0);
#endif

                if (!okToSell)
                {
                    if (m_dialogModule != null)
                    {
                        m_dialogModule.SendAlertToUser(
                            remoteClient, "This item's inventory doesn't appear to be for sale");
                    }
                    return(false);
                }

                if (invList.Count > 0)
                {
                    if (inventoryModule != null)
                    {
                        inventoryModule.MoveTaskInventoryItemsToUserInventory(remoteClient.AgentId, part.Name, part,
                                                                              invList);
                    }
                }
                break;
            }

            return(true);
        }
Exemple #10
0
        public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
                                          UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
                                          string assetType, UUID AgentID)
        {
            sbyte assType = 0;
            sbyte inType  = 0;

            if (inventoryType == "sound")
            {
                inType  = 1;
                assType = 1;
            }
            else if (inventoryType == "animation")
            {
                inType  = 19;
                assType = 20;
            }
            else if (inventoryType == "wearable")
            {
                inType = 18;
                switch (assetType)
                {
                case "bodypart":
                    assType = 13;
                    break;

                case "clothing":
                    assType = 5;
                    break;
                }
            }
            else if (inventoryType == "mesh")
            {
                inType  = (sbyte)InventoryType.Mesh;
                assType = (sbyte)AssetType.Mesh;
            }

            AssetBase asset;

            asset      = new AssetBase(assetID, assetName, assType, AgentID.ToString());
            asset.Data = data;

            if (m_scene.AssetService != null)
            {
                m_scene.AssetService.Store(asset);
            }

            InventoryItemBase item = new InventoryItemBase();

            item.Owner               = AgentID;
            item.CreatorId           = AgentID.ToString();
            item.ID                  = inventoryItem;
            item.AssetID             = asset.FullID;
            item.Description         = assetDescription;
            item.Name                = assetName;
            item.AssetType           = assType;
            item.InvType             = inType;
            item.Folder              = parentFolder;
            item.CurrentPermissions  = (uint)PermissionMask.All;
            item.BasePermissions     = (uint)PermissionMask.All;
            item.EveryOnePermissions = 0;
            item.NextPermissions     = (uint)(PermissionMask.Move | PermissionMask.Modify | PermissionMask.Transfer);
            item.CreationDate        = Util.UnixTimeSinceEpoch();
            ILLClientInventory inventoryModule = m_scene.RequestModuleInterface <ILLClientInventory>();

            if (inventoryModule != null)
            {
                inventoryModule.AddInventoryItem(item);
            }
        }
Exemple #11
0
        void Heartbeat()
        {
            IMonitorModule             monitorModule           = RequestModuleInterface <IMonitorModule>();
            ISimFrameMonitor           simFrameMonitor         = monitorModule.GetMonitor <ISimFrameMonitor>(this);
            ITotalFrameTimeMonitor     totalFrameMonitor       = monitorModule.GetMonitor <ITotalFrameTimeMonitor>(this);
            ILastFrameTimeMonitor      lastFrameMonitor        = monitorModule.GetMonitor <ILastFrameTimeMonitor>(this);
            IOtherFrameMonitor         otherFrameMonitor       = monitorModule.GetMonitor <IOtherFrameMonitor>(this);
            ISleepFrameMonitor         sleepFrameMonitor       = monitorModule.GetMonitor <ISleepFrameMonitor>(this);
            IPhysicsFrameMonitor       physicsFrameMonitor     = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this);
            IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this);

            IPhysicsMonitor    physicsMonitor  = RequestModuleInterface <IPhysicsMonitor>();
            ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();

            while (true)
            {
                if (!ShouldRunHeartbeat) //If we aren't supposed to be running, kill ourselves
                {
                    return;
                }

                int maintc             = Util.EnvironmentTickCount();
                int BeginningFrameTime = maintc;
                // Increment the frame counter
                ++Frame;

                try
                {
                    int            OtherFrameTime = Util.EnvironmentTickCount();
                    ISceneEntity[] entities       = null;
                    lock (PhysicsReturns)
                    {
                        if (PhysicsReturns.Count != 0)
                        {
                            entities = PhysicsReturns.ToArray();
                            PhysicsReturns.Clear();
                        }
                    }
                    if (entities != null && inventoryModule != null)
                    {
                        inventoryModule.ReturnObjects(entities, UUID.Zero);
                    }

                    if (Frame % m_update_entities == 0)
                    {
                        m_sceneGraph.UpdateEntities();
                    }

                    if (Frame % m_update_events == 0)
                    {
                        m_sceneGraph.PhysicsScene.UpdatesLoop();
                    }

                    if (Frame % m_update_events == 0)
                    {
                        m_eventManager.TriggerOnFrame();
                    }

                    if (Frame % m_update_coarse_locations == 0)
                    {
                        List <Vector3> coarseLocations;
                        List <UUID>    avatarUUIDs;
                        if (SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60))
                        {
                            // Send coarse locations to clients
                            foreach (IScenePresence presence in GetScenePresences())
                            {
                                presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
                            }
                        }
                    }

                    int PhysicsUpdateTime = Util.EnvironmentTickCount();

                    if (Frame % m_update_physics == 0)
                    {
                        TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate;
                        if (!RegionInfo.RegionSettings.DisablePhysics &&
                            ApproxEquals((float)SinceLastFrame.TotalMilliseconds,
                                         m_updatetimespan, 3))
                        {
                            m_sceneGraph.UpdatePreparePhysics();
                            m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds);
                            m_lastphysupdate = DateTime.UtcNow;
                            int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime);

                            if (MonitorPhysicsUpdateTime != 0)
                            {
                                if (physicsFrameTimeMonitor != null)
                                {
                                    physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                                }
                                if (physicsMonitor != null)
                                {
                                    physicsMonitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                                }
                                if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                                {
                                    StartPhysicsScene();
                                }
                            }
                            if (physicsFrameMonitor != null)
                            {
                                physicsFrameMonitor.AddFPS(1);
                            }
                        }
                        else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                        {
                            StopPhysicsScene();
                        }
                        m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics;
                    }

                    //Now fix the sim stats
                    int MonitorOtherFrameTime     = Util.EnvironmentTickCountSubtract(OtherFrameTime);
                    int MonitorLastCompletedFrame = Util.EnvironmentTickCount();

                    simFrameMonitor.AddFPS(1);
                    lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                    otherFrameMonitor.AddTime(MonitorOtherFrameTime);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.Error("[Scene]: Failed with exception " + e + " in region: " +
                                               RegionInfo.RegionName);
                    return;
                }

                //Get the time between beginning and end
                maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime);
                //Beginning + (time between beginning and end) = end
                int MonitorEndFrameTime = BeginningFrameTime + maintc;

                int getSleepTime = GetHeartbeatSleepTime(maintc);
                if (getSleepTime > 0)
                {
                    Thread.Sleep(getSleepTime);
                }

                if (sleepFrameMonitor != null)
                {
                    sleepFrameMonitor.AddTime(getSleepTime);
                    totalFrameMonitor.AddFrameTime(MonitorEndFrameTime);
                }
            }
        }
Exemple #12
0
        private bool PhysUpdate()
        {
            IMonitorModule             monitorModule           = RequestModuleInterface <IMonitorModule>();
            IPhysicsFrameMonitor       physicsFrameMonitor     = monitorModule.GetMonitor <IPhysicsFrameMonitor>(this);
            IPhysicsUpdateFrameMonitor physicsFrameTimeMonitor = monitorModule.GetMonitor <IPhysicsUpdateFrameMonitor>(this);

            IPhysicsMonitor    monitor2        = RequestModuleInterface <IPhysicsMonitor>();
            ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();

            while (true)
            {
                if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves
                {
                    return(false);
                }
                int maintc             = Util.EnvironmentTickCount();
                int BeginningFrameTime = maintc;

                ISceneEntity[] entities = null;
                lock (PhysicsReturns)
                {
                    if (PhysicsReturns.Count != 0)
                    {
                        entities = PhysicsReturns.ToArray();
                        PhysicsReturns.Clear();
                    }
                }
                if (entities != null && inventoryModule != null)
                {
                    inventoryModule.ReturnObjects(entities, UUID.Zero);
                }

                int PhysicsUpdateTime = Util.EnvironmentTickCount();

                if (m_frame % m_update_physics == 0)
                {
                    TimeSpan SinceLastFrame = DateTime.UtcNow - m_lastphysupdate;
                    if (!RegionInfo.RegionSettings.DisablePhysics &&
                        ApproxEquals((float)SinceLastFrame.TotalMilliseconds,
                                     m_updatetimespan, 3))
                    {
                        m_sceneGraph.UpdatePreparePhysics();
                        m_sceneGraph.UpdatePhysics((float)SinceLastFrame.TotalSeconds);
                        m_lastphysupdate = DateTime.UtcNow;
                        int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime);

                        if (MonitorPhysicsUpdateTime != 0)
                        {
                            if (physicsFrameTimeMonitor != null)
                            {
                                physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                            }
                            if (monitor2 != null)
                            {
                                monitor2.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                            }
                            if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                            {
                                StartPhysicsScene();
                            }
                        }
                        if (physicsFrameMonitor != null)
                        {
                            physicsFrameMonitor.AddFPS(1);
                        }
                    }
                    else if (m_lastPhysicsChange != RegionInfo.RegionSettings.DisablePhysics)
                    {
                        StopPhysicsScene();
                    }
                    m_lastPhysicsChange = RegionInfo.RegionSettings.DisablePhysics;
                }

                //Get the time between beginning and end
                maintc = Util.EnvironmentTickCountSubtract(BeginningFrameTime);
                if (maintc == 0)
                {
                    continue;
                }
                int getSleepTime = GetHeartbeatSleepTime(maintc, true);
                if (getSleepTime > 0)
                {
                    Thread.Sleep(getSleepTime);
                }
            }
        }
 public virtual void RegionLoaded(IScene scene)
 {
     m_LLCLientInventoryModule = scene.RequestModuleInterface<ILLClientInventory>();
 }
        /// <summary>
        ///     Move the given scene object into a new region depending on which region its absolute position has moved
        ///     into.
        ///     This method locates the new region handle and offsets the prim position for the new region
        /// </summary>
        /// <param name="attemptedPosition">the attempted out of region position of the scene object</param>
        /// <param name="grp">the scene object that we're crossing</param>
        /// <param name="destination"></param>
        public bool CrossGroupToNewRegion(ISceneEntity grp, Vector3 attemptedPosition, GridRegion destination)
        {
            if (grp == null)
            {
                return(false);
            }
            if (grp.IsDeleted)
            {
                return(false);
            }

            if (grp.Scene == null)
            {
                return(false);
            }
            if (grp.RootChild.DIE_AT_EDGE)
            {
                // We remove the object here
                try {
                    IBackupModule backup = grp.Scene.RequestModuleInterface <IBackupModule> ();
                    if (backup != null)
                    {
                        return(backup.DeleteSceneObjects(new [] { grp }, true, true));
                    }
                } catch (Exception) {
                    MainConsole.Instance.Warn(
                        "[Database]: exception when trying to remove the prim that crossed the border.");
                }
                return(false);
            }

            if (grp.RootChild.RETURN_AT_EDGE)
            {
                // We remove the object here
                try {
                    List <ISceneEntity> objects = new List <ISceneEntity> {
                        grp
                    };
                    ILLClientInventory inventoryModule = grp.Scene.RequestModuleInterface <ILLClientInventory> ();
                    if (inventoryModule != null)
                    {
                        return(inventoryModule.ReturnObjects(objects.ToArray(), UUID.Zero));
                    }
                } catch (Exception) {
                    MainConsole.Instance.Warn(
                        "[Scene]: exception when trying to return the prim that crossed the border.");
                }
                return(false);
            }

            Vector3 oldGroupPosition = grp.RootChild.GroupPosition;

            // If we fail to cross the border, then reset the position of the scene object on that border.
            if (destination != null && !CrossPrimGroupIntoNewRegion(destination, grp, attemptedPosition))
            {
                grp.OffsetForNewRegion(oldGroupPosition);
                grp.ScheduleGroupUpdate(PrimUpdateFlags.ForcedFullUpdate);

                return(false);
            }
            return(true);
        }
Exemple #15
0
        private bool Update()
        {
            if (!ShouldRunHeartbeat) //If we arn't supposed to be running, kill ourselves
            {
                return(false);
            }

            ISimFrameMonitor       simFrameMonitor         = (ISimFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "SimFrameStats");
            ITotalFrameTimeMonitor totalFrameMonitor       = (ITotalFrameTimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Frame Time");
            ISetMonitor            lastFrameMonitor        = (ISetMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Last Completed Frame At");
            ITimeMonitor           otherFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Other Frame Time");
            ITimeMonitor           sleepFrameMonitor       = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Sleep Frame Time");
            IPhysicsFrameMonitor   physicsFrameMonitor     = (IPhysicsFrameMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Total Physics Frame Time");
            ITimeMonitor           physicsSyncFrameMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Sync Frame Time");
            ITimeMonitor           physicsFrameTimeMonitor = (ITimeMonitor)RequestModuleInterface <IMonitorModule>().GetMonitor(RegionInfo.RegionID.ToString(), "Physics Update Frame Time");
            int maintc             = Util.EnvironmentTickCount();
            int BeginningFrameTime = maintc;

            // Increment the frame counter
            ++m_frame;

            try
            {
                int OtherFrameTime = Util.EnvironmentTickCount();
                if (PhysicsReturns.Count != 0)
                {
                    lock (PhysicsReturns)
                    {
                        ILLClientInventory inventoryModule = RequestModuleInterface <ILLClientInventory>();
                        if (inventoryModule != null)
                        {
                            inventoryModule.ReturnObjects(PhysicsReturns.ToArray(), UUID.Zero);
                        }
                        PhysicsReturns.Clear();
                    }
                }
                if (m_frame % m_update_coarse_locations == 0)
                {
                    List <Vector3> coarseLocations;
                    List <UUID>    avatarUUIDs;
                    SceneGraph.GetCoarseLocations(out coarseLocations, out avatarUUIDs, 60);
                    // Send coarse locations to clients
                    foreach (IScenePresence presence in GetScenePresences())
                    {
                        presence.SendCoarseLocations(coarseLocations, avatarUUIDs);
                    }
                }

                if (m_frame % m_update_entities == 0)
                {
                    m_sceneGraph.UpdateEntities();
                }

                if (m_frame % m_update_events == 0)
                {
                    m_eventManager.TriggerOnFrame();
                }

                int      PhysicsSyncTime = Util.EnvironmentTickCount();
                TimeSpan SinceLastFrame  = DateTime.UtcNow - m_lastphysupdate;

                if ((m_frame % m_update_physics == 0) && !RegionInfo.RegionSettings.DisablePhysics)
                {
                    m_sceneGraph.UpdatePreparePhysics();
                }

                int MonitorPhysicsSyncTime = Util.EnvironmentTickCountSubtract(PhysicsSyncTime);

                int PhysicsUpdateTime = Util.EnvironmentTickCount();

                if (m_frame % m_update_physics == 0)
                {
                    if (!RegionInfo.RegionSettings.DisablePhysics && SinceLastFrame.TotalSeconds > m_physicstimespan)
                    {
                        m_sceneGraph.UpdatePhysics(SinceLastFrame.TotalSeconds);
                        m_lastphysupdate = DateTime.UtcNow;
                    }
                }

                int MonitorPhysicsUpdateTime = Util.EnvironmentTickCountSubtract(PhysicsUpdateTime) + MonitorPhysicsSyncTime;

                physicsFrameTimeMonitor.AddTime(MonitorPhysicsUpdateTime);
                physicsFrameMonitor.AddFPS(1);
                physicsSyncFrameMonitor.AddTime(MonitorPhysicsSyncTime);

                IPhysicsMonitor monitor = RequestModuleInterface <IPhysicsMonitor>();
                if (monitor != null)
                {
                    monitor.AddPhysicsStats(RegionInfo.RegionID, PhysicsScene);
                }

                //Now fix the sim stats
                int MonitorOtherFrameTime     = Util.EnvironmentTickCountSubtract(OtherFrameTime);
                int MonitorLastCompletedFrame = Util.EnvironmentTickCount();

                simFrameMonitor.AddFPS(1);
                lastFrameMonitor.SetValue(MonitorLastCompletedFrame);
                otherFrameMonitor.AddTime(MonitorOtherFrameTime);

                maintc = Util.EnvironmentTickCountSubtract(maintc);
                maintc = (int)(m_updatetimespan * 1000) - maintc;
            }
            catch (Exception e)
            {
                m_log.Error("[REGION]: Failed with exception " + e.ToString() + " in region: " + RegionInfo.RegionName);
                return(true);
            }

            int MonitorEndFrameTime = Util.EnvironmentTickCountSubtract(BeginningFrameTime) + maintc;

            if (maintc > 0)
            {
                Thread.Sleep(maintc);
            }

            sleepFrameMonitor.AddTime(maintc);

            totalFrameMonitor.AddFrameTime(MonitorEndFrameTime);
            return(true);
        }
        public virtual void AddRegion(Scene scene)
        {
            if (!m_Enabled)
                return;

            m_Scene = scene;
            m_LLCLientInventoryModule = scene.RequestModuleInterface<ILLClientInventory>();

            scene.RegisterModuleInterface<IInventoryAccessModule>(this);
            scene.EventManager.OnNewClient += OnNewClient;
            scene.EventManager.OnClosingClient += OnClosingClient;
        }
        private Hashtable CopyInventoryFromNotecard(Hashtable mDhttpMethod, UUID agentID)
        {
            OSDMap            rm           = (OSDMap)OSDParser.DeserializeLLSDXml((string)mDhttpMethod["requestbody"]);
            UUID              FolderID     = rm["folder-id"].AsUUID();
            UUID              ItemID       = rm["item-id"].AsUUID();
            UUID              NotecardID   = rm["notecard-id"].AsUUID();
            UUID              ObjectID     = rm["object-id"].AsUUID();
            InventoryItemBase notecardItem = null;

            if (ObjectID != UUID.Zero)
            {
                ISceneChildEntity part = m_scene.GetSceneObjectPart(ObjectID);
                if (part != null)
                {
                    TaskInventoryItem item = part.Inventory.GetInventoryItem(NotecardID);
                    if (m_scene.Permissions.CanCopyObjectInventory(NotecardID, ObjectID, agentID))
                    {
                        notecardItem = new InventoryItemBase(NotecardID, agentID)
                        {
                            AssetID = item.AssetID
                        };
                    }
                }
            }
            else
            {
                notecardItem = m_scene.InventoryService.GetItem(new InventoryItemBase(NotecardID));
            }
            if (notecardItem != null && notecardItem.Owner == agentID)
            {
                AssetBase asset = m_scene.AssetService.Get(notecardItem.AssetID.ToString());
                if (asset != null)
                {
                    UTF8Encoding enc =
                        new UTF8Encoding();
                    List <string> notecardData  = SLUtil.ParseNotecardToList(enc.GetString(asset.Data));
                    AssetNotecard noteCardAsset = new AssetNotecard(UUID.Zero, asset.Data);
                    noteCardAsset.Decode();
                    bool found       = false;
                    UUID lastOwnerID = UUID.Zero;
#if (!ISWIN)
                    foreach (InventoryItem notecardObjectItem in noteCardAsset.EmbeddedItems)
                    {
                        if (notecardObjectItem.UUID == ItemID)
                        {
                            //Make sure that it exists
                            found       = true;
                            lastOwnerID = notecardObjectItem.OwnerID;
                            break;
                        }
                    }
#else
                    foreach (InventoryItem notecardObjectItem in noteCardAsset.EmbeddedItems.Where(notecardObjectItem => notecardObjectItem.UUID == ItemID))
                    {
                        //Make sure that it exists
                        found       = true;
                        lastOwnerID = notecardObjectItem.OwnerID;
                        break;
                    }
#endif
                    if (found)
                    {
                        InventoryItemBase  item            = null;
                        ILLClientInventory inventoryModule = m_scene.RequestModuleInterface <ILLClientInventory>();
                        if (inventoryModule != null)
                        {
                            item = inventoryModule.GiveInventoryItem(agentID, lastOwnerID, ItemID, FolderID);
                        }

                        IClientAPI client;
                        m_scene.ClientManager.TryGetValue(agentID, out client);
                        if (item != null)
                        {
                            client.SendBulkUpdateInventory(item);
                        }
                        else
                        {
                            client.SendAlertMessage("Failed to retrieve item");
                        }
                    }
                }
            }

            //Send back data
            Hashtable responsedata = new Hashtable();
            responsedata["int_response_code"]   = 200; //501; //410; //404;
            responsedata["content_type"]        = "text/plain";
            responsedata["keepalive"]           = false;
            responsedata["str_response_string"] = "";
            return(responsedata);
        }