/// <summary>
        /// Add a simple script to the given part.
        /// </summary>
        /// <remarks>
        /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather
        /// than a random component.
        /// </remarks>
        /// <param name="assetService"></param>
        /// <param name="part"></param>
        /// <param name="itemId">Item UUID for the script</param>
        /// <param name="assetId">Asset UUID for the script</param>
        /// <param name="scriptName">Name of the script to add</param>
        /// <param name="scriptSource">LSL script source</param>
        /// <returns>The item that was added</returns>
        public static TaskInventoryItem AddScript(
            IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource)
        {
            AssetScriptText ast = new AssetScriptText();

            ast.Source = scriptSource;
            ast.Encode();

            AssetBase asset
                = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero);

            assetService.Store(asset);
            TaskInventoryItem item
                = new TaskInventoryItem
                {
                Name    = scriptName,
                AssetID = assetId,
                ItemID  = itemId,
                Type    = (int)AssetType.LSLText,
                InvType = (int)InventoryType.LSL
                };

            part.Inventory.AddInventoryItem(item, true);

            return(item);
        }
示例#2
0
        public bool SendScript(string name, string content, UUID sendToUUID)
        {
            bool returnstatus = true;

            Client.Inventory.RequestCreateItem(
                Client.Inventory.FindFolderForType(AssetType.LSLText),
                name,
                name,
                AssetType.LSLText,
                UUID.Random(),
                InventoryType.LSL,
                PermissionMask.All,
                (bool Success, InventoryItem item) =>
            {
                if (Success)
                {
                    AssetScriptText empty = new AssetScriptText {
                        Source = "\n"
                    };
                    empty.Encode();
                    Client.Inventory.RequestUpdateScriptAgentInventory(new byte[] { }, item.UUID, true,
                                                                       (bool uploadSuccess, string uploadStatus, bool compileSuccess, List <string> compileMessages, UUID itemID, UUID assetID) =>
                    {
                        if (uploadSuccess)
                        {
                            empty.AssetData = Encoding.ASCII.GetBytes(content);
                            Client.Inventory.RequestUpdateScriptAgentInventory(empty.AssetData, itemID, true,
                                                                               (bool finaluploadSuccess, string finaluploadStatus, bool finalcompileSuccess, List <string> finalcompileMessages, UUID finalitemID, UUID finalassetID) =>
                            {
                                if (finalcompileSuccess == false)
                                {
                                    ConsoleLog.Warn("Script failed to compile, sending anyway.");
                                }
                                Client.Inventory.GiveItem(finalitemID, name, AssetType.LSLText, sendToUUID, false);
                            });
                        }
                        else
                        {
                            ConsoleLog.Crit("The f**k empty success Script create");
                            returnstatus = false;
                        }
                    });
                }
                else
                {
                    ConsoleLog.Warn("Unable to find default Scripts folder");
                    returnstatus = false;
                }
            }
                );
            return(returnstatus);
        }
        /// <summary>
        /// Add a simple script to the given part.
        /// </summary>
        /// <remarks>
        /// TODO: Accept input for item and asset IDs so that we have completely replicatable regression tests rather
        /// than a random component.
        /// </remarks>
        /// <param name="assetService"></param>
        /// <param name="part"></param>
        /// <param name="itemId">Item UUID for the script</param>
        /// <param name="assetId">Asset UUID for the script</param>
        /// <param name="scriptName">Name of the script to add</param>
        /// <param name="scriptSource">LSL script source</param>
        /// <returns>The item that was added</returns>
        public static TaskInventoryItem AddScript(
            IAssetService assetService, SceneObjectPart part, UUID itemId, UUID assetId, string scriptName, string scriptSource)
        {
            AssetScriptText ast = new AssetScriptText();
            ast.Source = scriptSource;
            ast.Encode();

            AssetBase asset
                = AssetHelpers.CreateAsset(assetId, AssetType.LSLText, ast.AssetData, UUID.Zero);
            assetService.Store(asset);
            TaskInventoryItem item
                = new TaskInventoryItem 
            { Name = scriptName, AssetID = assetId, ItemID = itemId,
                Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
            part.Inventory.AddInventoryItem(item, true);

            return item;
        }
示例#4
0
        private void tbtbSave_Click(object sender, EventArgs e)
        {
            InventoryManager.ScriptUpdatedCallback handler = (bool uploadSuccess, string uploadStatus, bool compileSuccess, List<string> compileMessages, UUID itemID, UUID assetID) =>
            {
                if (!IsHandleCreated && instance.MonoRuntime) return;

                BeginInvoke(new MethodInvoker(() =>
                {
                    if (uploadSuccess && compileSuccess)
                    {
                        lblScripStatus.Text = "Saved OK";
                    }
                    else
                    {
                        if (!compileSuccess)
                        {
                            lblScripStatus.Text = "Compilation failed";
                            if (compileMessages != null)
                            {
                                txtStatus.Show();
                                txtStatus.Text = string.Empty;
                                for (int i = 0; i < compileMessages.Count; i++)
                                {
                                    Match m = Regex.Match(compileMessages[i], @"\((?<line>\d+),\s*(?<column>\d+)\s*\)\s*:\s*(?<kind>\w+)\s*:\s*(?<msg>.*)", RegexOptions.IgnoreCase);

                                    if (m.Success)
                                    {
                                        int line = 1 + int.Parse(m.Groups["line"].Value, Utils.EnUsCulture);
                                        int column = 1 + int.Parse(m.Groups["column"].Value, Utils.EnUsCulture);
                                        string kind = m.Groups["kind"].Value;
                                        string msg = m.Groups["msg"].Value;
                                        instance.TabConsole.DisplayNotificationInChat(
                                            string.Format("{0} on line {1}, column {2}: {3}", kind, line, column, msg),
                                            ChatBufferTextStyle.Invisible);
                                        txtStatus.Text += string.Format("{0} (Ln {1}, Col {2}): {3}", kind, line, column, msg);

                                        if (i == 0)
                                        {
                                            rtb.CursorPosition = new RRichTextBox.CursorLocation(line - 1, column - 1);
                                            ReadCursorPosition();
                                            rtb.Focus();
                                        }
                                    }
                                    else
                                    {
                                        txtStatus.Text += compileMessages[i] + Environment.NewLine;
                                        instance.TabConsole.DisplayNotificationInChat(compileMessages[i]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            lblScripStatus.Text = rtb.Text = "Failed to download.";
                        }

                    }
                }
                ));
            };

            lblScripStatus.Text = "Saving...";
            txtStatus.Hide();
            txtStatus.Text = string.Empty;

            AssetScriptText n = new AssetScriptText();
            n.Source = rtb.Text;
            n.Encode();

            if (prim != null)
            {
                client.Inventory.RequestUpdateScriptTask(n.AssetData, script.UUID, prim.ID, cbMono.Checked, cbRunning.Checked, handler);
            }
            else
            {
                client.Inventory.RequestUpdateScriptAgentInventory(n.AssetData, script.UUID, cbMono.Checked, handler);
            }
        }
示例#5
0
        private void tbtbSave_Click(object sender, EventArgs e)
        {
            InventoryManager.ScriptUpdatedCallback handler = (bool uploadSuccess, string uploadStatus, bool compileSuccess, List <string> compileMessages, UUID itemID, UUID assetID) =>
            {
                if (!IsHandleCreated && instance.MonoRuntime)
                {
                    return;
                }

                BeginInvoke(new MethodInvoker(() =>
                {
                    if (uploadSuccess && compileSuccess)
                    {
                        lblScripStatus.Text = "Saved OK";
                    }
                    else
                    {
                        if (!compileSuccess)
                        {
                            lblScripStatus.Text = "Compilation failed";
                            if (compileMessages != null)
                            {
                                txtStatus.Show();
                                txtStatus.Text = string.Empty;
                                for (int i = 0; i < compileMessages.Count; i++)
                                {
                                    Match m = Regex.Match(compileMessages[i], @"\((?<line>\d+),\s*(?<column>\d+)\s*\)\s*:\s*(?<kind>\w+)\s*:\s*(?<msg>.*)", RegexOptions.IgnoreCase);

                                    if (m.Success)
                                    {
                                        int line    = 1 + int.Parse(m.Groups["line"].Value, Utils.EnUsCulture);
                                        int column  = 1 + int.Parse(m.Groups["column"].Value, Utils.EnUsCulture);
                                        string kind = m.Groups["kind"].Value;
                                        string msg  = m.Groups["msg"].Value;
                                        instance.TabConsole.DisplayNotificationInChat(
                                            string.Format("{0} on line {1}, column {2}: {3}", kind, line, column, msg),
                                            ChatBufferTextStyle.Invisible);
                                        txtStatus.Text += string.Format("{0} (Ln {1}, Col {2}): {3}", kind, line, column, msg);

                                        if (i == 0)
                                        {
                                            rtb.CursorPosition = new RRichTextBox.CursorLocation(line - 1, column - 1);
                                            ReadCursorPosition();
                                            rtb.Focus();
                                        }
                                    }
                                    else
                                    {
                                        txtStatus.Text += compileMessages[i] + Environment.NewLine;
                                        instance.TabConsole.DisplayNotificationInChat(compileMessages[i]);
                                    }
                                }
                            }
                        }
                        else
                        {
                            lblScripStatus.Text = rtb.Text = "Failed to download.";
                        }
                    }
                }
                                              ));
            };


            lblScripStatus.Text = "Saving...";
            txtStatus.Hide();
            txtStatus.Text = string.Empty;

            AssetScriptText n = new AssetScriptText();

            n.Source = rtb.Text;
            n.Encode();

            if (prim != null)
            {
                client.Inventory.RequestUpdateScriptTask(n.AssetData, script.UUID, prim.ID, cbMono.Checked, cbRunning.Checked, handler);
            }
            else
            {
                client.Inventory.RequestUpdateScriptAgentInventory(n.AssetData, script.UUID, cbMono.Checked, handler);
            }
        }