Exemple #1
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            if (args.Length < 1)
                return ShowUsage(); // " siton UUID";

            int argsUsed;
            SimPosition pos;
            if (!args.TryGetValue("on", out pos))
            {
                sittingOnGround = WorldSystem.TheSimAvatar.SitOnGround();
                return !sittingOnGround
                           ? Failure("$bot did not yet sit on the ground.")
                           : Success("$bot sat on the ground.");
            }
            if (pos is SimObject)
            {
                if (WorldSystem.TheSimAvatar.SitOn(pos as SimObject)) Success("$bot sat on " + pos);
                if (!args.IsTrue("down")) return Failure("$bot did not yet sit on " + pos);
            }
            else if (pos == null)
            {
                return Failure("$bot did not yet find " + args.str);
            }
            // @todo use autoppoiolot to the location andf then sit
            TheSimAvatar.GotoTargetAStar(pos);
            sittingOnGround = WorldSystem.TheSimAvatar.SitOnGround();
            if (sittingOnGround) return Success("$bot sat at " + pos);
            return Failure("$bot did not sit at " + pos);
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool moveInsteadOfCopy = args.IsTrue("--move");
            if (!args.ContainsKey("items") || !args.ContainsKey("to"))
            {
                return ShowUsage();
            }
            int argsUsed;
            List<SimObject> allTargets;
            if (!args.TryGetValue("to", out allTargets))
            {
                return Failure("Cannot find avatar/objects 'to' give to");
            }

            Success("Going to give to " + allTargets.Count + " avatar/objects");

            var man = Client.BotInventory;
            var found = man.FindAll(args.GetProperty("items"), false,
                                    inventoryName => Failure("No inventory item named " + inventoryName + " found."));

            int given = 0;
            foreach (var dest in allTargets)
            {
                foreach (InventoryBase item in found)
                {
                    GiveAll(man, item, dest, moveInsteadOfCopy);
                }
            }
            return SuccessOrFailure();
        }
Exemple #3
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool moveInsteadOfCopy = args.IsTrue("--move");

            if (!args.ContainsKey("items") || !args.ContainsKey("to"))
            {
                return(ShowUsage());
            }
            int argsUsed;
            List <SimObject> allTargets;

            if (!args.TryGetValue("to", out allTargets))
            {
                return(Failure("Cannot find avatar/objects 'to' give to"));
            }

            Success("Going to give to " + allTargets.Count + " avatar/objects");

            var man   = Client.BotInventory;
            var found = man.FindAll(args.GetProperty("items"), false,
                                    inventoryName => Failure("No inventory item named " + inventoryName + " found."));

            int given = 0;

            foreach (var dest in allTargets)
            {
                foreach (InventoryBase item in found)
                {
                    GiveAll(man, item, dest, moveInsteadOfCopy);
                }
            }
            return(SuccessOrFailure());
        }
Exemple #4
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            AutoResetEvent appearanceEvent = new AutoResetEvent(false);
            EventHandler <AppearanceSetEventArgs> callback = (s, e) => appearanceEvent.Set();

            // Start the appearance setting process (with baking enabled or disabled)
            bool bake = !args.IsTrue("nobake");
            bool send = args.IsTrue("send");
            bool wait = args.IsTrue("wait");

            if (wait)
            {
                // Register a handler for the appearance event
                Client.Appearance.AppearanceSet += callback;
            }
            if (send)
            {
                Client.Appearance.RequestSetAppearance();
            }
            else
            {
                Client.Appearance.RequestSetAppearance(bake);
            }
            if (wait)
            {
                bool success = false;
                //// Wait for the process to complete or time out
                if (appearanceEvent.WaitOne(1000 * 120, false))
                {
                    success = true;
                }

                //// Unregister the handler
                Client.Appearance.AppearanceSet -= callback;

                //// Return success or failure message
                if (!success)
                {
                    return(Failure("Timed out while setting appearance"));
                }
            }
            return(Success("Successfully set appearance bake=" + bake));
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            AutoResetEvent appearanceEvent = new AutoResetEvent(false);
            EventHandler<AppearanceSetEventArgs> callback = (s, e) => appearanceEvent.Set();

            // Start the appearance setting process (with baking enabled or disabled)
            bool bake = !args.IsTrue("nobake");
            bool send = args.IsTrue("send");
            bool wait = args.IsTrue("wait");
            if (wait)
            {
                // Register a handler for the appearance event
                Client.Appearance.AppearanceSet += callback;
            }
            if (send)
            {
                Client.Appearance.RequestSetAppearance();
            }
            else
            {
                Client.Appearance.RequestSetAppearance(bake);
            }
            if (wait)
            {
                bool success = false;
                //// Wait for the process to complete or time out
                if (appearanceEvent.WaitOne(1000*120, false))
                    success = true;

                //// Unregister the handler
                Client.Appearance.AppearanceSet -= callback;

                //// Return success or failure message
                if (!success) return Failure("Timed out while setting appearance");
            }
            return Success("Successfully set appearance bake=" + bake);
        }
Exemple #6
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool        asLocal = args.IsTrue("--local");
            SimPosition pos, pos2;

            if (!args.TryGetValue("start", out pos))
            {
                pos = TheSimAvatar;
            }
            if (!args.TryGetValue("end", out pos2))
            {
                pos = TheSimAvatar;
            }
            Vector3d from, to;

            if (pos2 == null)
            {
                pos2 = pos;
                pos  = TheSimAvatar;
            }
            from = pos.GlobalPosition;
            to   = pos2.GlobalPosition;
            Vector3d offset = Vector3d.Zero;

            if (asLocal)
            {
                offset = pos.PathStore.GlobalStart;
            }
            bool onlyStart, faked;
            var  path = SimPathStore.GetPath(null, from, to, 1, out onlyStart, out faked);

            WriteLine("onlyStart=" + onlyStart);
            WriteLine("faked=" + faked);
            WriteLine("start=" + VectorRoundString(from - offset));
            WriteLine("end=" + VectorRoundString(to - offset));
            WriteLine("pstart=" + pos);
            WriteLine("pend=" + pos2);
            WriteLine("len=" + path.Count);
            int step = 0;

            foreach (Vector3d vector3D in path)
            {
                WriteLine("p" + step + "=" + VectorRoundString(vector3D - offset));
                step++;
            }
            return(Success("SUCCESS " + Name));
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            if (args.Length < 1)
            {
                return(ShowUsage()); // " siton UUID";
            }
            int         argsUsed;
            SimPosition pos;

            if (!args.TryGetValue("on", out pos))
            {
                sittingOnGround = WorldSystem.TheSimAvatar.SitOnGround();
                return(!sittingOnGround
                           ? Failure("$bot did not yet sit on the ground.")
                           : Success("$bot sat on the ground."));
            }
            if (pos is SimObject)
            {
                if (WorldSystem.TheSimAvatar.SitOn(pos as SimObject))
                {
                    Success("$bot sat on " + pos);
                }
                if (!args.IsTrue("down"))
                {
                    return(Failure("$bot did not yet sit on " + pos));
                }
            }
            else if (pos == null)
            {
                return(Failure("$bot did not yet find " + args.str));
            }
            // @todo use autoppoiolot to the location andf then sit
            TheSimAvatar.GotoTargetAStar(pos);
            sittingOnGround = WorldSystem.TheSimAvatar.SitOnGround();
            if (sittingOnGround)
            {
                return(Success("$bot sat at " + pos));
            }
            return(Failure("$bot did not sit at " + pos));
        }
Exemple #8
0
 public override CmdResult ExecuteRequest(CmdRequest args)
 {
     bool asLocal = args.IsTrue("--local");
     SimPosition pos, pos2;
     if (!args.TryGetValue("start", out pos)) pos = TheSimAvatar;
     if (!args.TryGetValue("end", out pos2)) pos = TheSimAvatar;
     Vector3d from, to;
     if (pos2 == null)
     {
         pos2 = pos;
         pos = TheSimAvatar;
     }
     from = pos.GlobalPosition;
     to = pos2.GlobalPosition;
     Vector3d offset = Vector3d.Zero;
     if (asLocal)
     {
         offset = pos.PathStore.GlobalStart;
     }
     bool onlyStart, faked;
     var path = SimPathStore.GetPath(null, from, to, 1, out onlyStart, out faked);
     WriteLine("onlyStart=" + onlyStart);
     WriteLine("faked=" + faked);
     WriteLine("start=" + VectorRoundString(from - offset));
     WriteLine("end=" + VectorRoundString(to - offset));
     WriteLine("pstart=" + pos);
     WriteLine("pend=" + pos2);
     WriteLine("len=" + path.Count);
     int step = 0;
     foreach (Vector3d vector3D in path)
     {
         WriteLine("p" + step + "=" + VectorRoundString(vector3D - offset));
         step++;
     }
     return Success("SUCCESS " + Name);
 }
Exemple #9
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            //base.acceptInput(verb, args);

            BotClient Client   = TheBotClient;
            string    onlyShow = "";

            args.SetValue("--kill", true);
            bool thread   = args.IsTrue("--thread");
            bool queue    = args.IsTrue("--queue");
            bool all      = args.IsTrue("--all");
            bool current  = args.IsTrue("--current");
            bool movement = args.IsTrue("--movement");
            bool pointing = args.IsTrue("--pointing");

            ThreadCommand.ExecuteRequestProc(args, this);
            if (all)
            {
                current  = true;
                movement = true;
                pointing = true;
            }
            if (current && TheSimAvatar.CurrentAction != null)
            {
                WriteLine("Killing " + TheSimAvatar.CurrentAction);
                TheSimAvatar.CurrentAction = null;
                IncrResult("killed", 1);
            }
            if (movement)
            {
                WriteLine("Killing movement");
                WorldSystem.TheSimAvatar.StopMoving();
            }
            if (pointing)
            {
                Client.ExecuteCommand("pointat", args.CallerAgent, WriteLine, CMDFLAGS.Backgrounded);
            }
            return(Success("Stopped " + base.ResultValue("killed")));
        }
Exemple #10
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            //base.acceptInput(verb, args);

            BotClient Client = TheBotClient;
            string onlyShow = "";
            args.SetValue("--kill", true);
            bool thread = args.IsTrue("--thread");
            bool queue = args.IsTrue("--queue");
            bool all = args.IsTrue("--all");
            bool current = args.IsTrue("--current");
            bool movement = args.IsTrue("--movement");
            bool pointing = args.IsTrue("--pointing");

            ThreadCommand.ExecuteRequestProc(args, this);
            if (all)
            {
                current = true;
                movement = true;
                pointing = true;
            }
            if (current && TheSimAvatar.CurrentAction != null)
            {
                WriteLine("Killing " + TheSimAvatar.CurrentAction);
                TheSimAvatar.CurrentAction = null;
                IncrResult("killed", 1);
            }
            if (movement)
            {
                WriteLine("Killing movement");
                WorldSystem.TheSimAvatar.StopMoving();
            }
            if (pointing)
            {
                Client.ExecuteCommand("pointat", args.CallerAgent, WriteLine, CMDFLAGS.Backgrounded);
            }
            return Success("Stopped " + base.ResultValue("killed"));
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool detatchAll = args.IsTrue("--detatchall");

            SimAvatar simAv;

            if (args.TryGetValue("target", out simAv))
            {
                UUID   target     = simAv.ID;
                string targetName = simAv.GetName();
                targetName += String.Format(" ({0})", target);
                if (Client.Appearances.ContainsKey(target))
                {
                    #region AvatarAppearance to AgentSetAppearance

                    AvatarAppearancePacket   appearance = TheBotClient.Appearances[target];
                    AgentSetAppearancePacket set        = Client.Appearance.MakeAppearancePacket();
                    set.AgentData.AgentID   = Client.Self.AgentID;
                    set.AgentData.SessionID = Client.Self.SessionID;
                    set.AgentData.SerialNum = SerialNum++;
                    set.AgentData.Size      = new Vector3(2f, 2f, 2f); // HACK

                    set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[0];
                    set.VisualParam  = new AgentSetAppearancePacket.VisualParamBlock[appearance.VisualParam.Length];

                    for (int i = 0; i < appearance.VisualParam.Length; i++)
                    {
                        set.VisualParam[i]            = new AgentSetAppearancePacket.VisualParamBlock();
                        set.VisualParam[i].ParamValue = appearance.VisualParam[i].ParamValue;
                    }

                    set.ObjectData.TextureEntry = appearance.ObjectData.TextureEntry;

                    #endregion AvatarAppearance to AgentSetAppearance

                    // Detach everything we are currently wearing
                    if (detatchAll)
                    {
                        Client.Appearance.AddAttachments(new List <InventoryItem>(), true);
                    }

                    // Send the new appearance packet
                    Client.Network.SendPacket(set);

                    return(Success("Cloned " + targetName));
                }
                else
                {
                    /// allow clone thyself
                    if (Client.Self.AgentID == target)
                    {
                        AgentSetAppearancePacket set = Client.Appearance.MakeAppearancePacket();

                        Client.Network.SendPacket(set);
                        Logger.DebugLog("Send AgentSetAppearance packet");

                        return(Success("Cloned " + targetName));
                    }
                    return(Failure("Don't know the appearance of avatar " + targetName));
                }
            }
            else
            {
                return(Failure("Couldn't find avatar " + args.str));
            }
        }
 public override CmdResult ExecuteRequest(CmdRequest args)
 {
     //AutoResetEvent are = new AutoResetEvent(false);
     // AppearanceManager.AppearanceUpdatedCallback callback = (Primitive.TextureEntry te) => are.Set();
     try
     {
         //Client.Appearance.OnAppearanceUpdated += callback;
         // base.acceptInput(verb, args);
         string target = String.Empty;
         if (args.Length == 0) return ShowUsage();
         bool bake = true;
         string wear = args.str.Trim();
         if (args.IsTrue("nobake"))
         {
             bake = false;
             wear = wear.Substring(6).Trim();
         }
         if (args.IsTrue("test"))
         {
             bake = true;
             wear = wear.Substring(4).Trim();
             TheBotClient.wearFolder(wear);
             // if (!are.WaitOne(WEARABLE_TIMEOUT * 2))
             //   return Success("Timeout wearing " + wear + " " + (bake ? " (baked)" : " (not baked)");
             // else
             return Success("wearing folder: " + wear + " " + (bake ? " (baked)" : " (not baked)"));
         }
         try
         {
             WriteLine("wearing folder: " + wear + " " + (bake ? " (baked)" : " (not baked)"));
             if (false)
             {
                 List<InventoryItem> outfit = Client.GetFolderItems(wear);
                 if (outfit != null)
                 {
                     Client.Appearance.ReplaceOutfit(outfit);
                     return Success(wear);
                 }
                 WriteLine("no folder found attaching item: " + wear);
             }
             string lwear = wear.ToLower();
             BotInventoryEval searcher = new BotInventoryEval(Client);
             InventoryFolder rootFolder = Client.Inventory.Store.RootFolder;
             if (rootFolder.UUID == UUID.Zero) return Success("Cant get roiot folder yet");
             bool found = searcher.findInFolders(rootFolder, (ib) =>
                                                                 {
                                                                     if (ib.Name.ToLower() == lwear)
                                                                     {
                                                                         if (ib is InventoryItem)
                                                                         {
                                                                             Client.Appearance.Attach(
                                                                                 ib as InventoryItem,
                                                                                 AttachmentPoint.Default);
                                                                             return true;
                                                                         }
                                                                         else
                                                                         {
                                                                             var fldr = ib as InventoryFolder;
                                                                             List<InventoryBase>
                                                                                 clientInventoryFolderContents =
                                                                                     Client.Inventory.
                                                                                         FolderContents(ib.UUID,
                                                                                                        Client.
                                                                                                            Self.
                                                                                                            AgentID,
                                                                                                        false,
                                                                                                        true,
                                                                                                        InventorySortOrder
                                                                                                            .
                                                                                                            ByName,
                                                                                                        40000);
                                                                             if (clientInventoryFolderContents ==
                                                                                 null)
                                                                                 return false;
                                                                             List<InventoryItem> items =
                                                                                 new List<InventoryItem>();
                                                                             foreach (
                                                                                 InventoryBase content in
                                                                                     clientInventoryFolderContents
                                                                                 )
                                                                             {
                                                                                 var it =
                                                                                     content as InventoryItem;
                                                                                 if (it != null) items.Add(it);
                                                                             }
                                                                             if (items.Count > 0)
                                                                             {
                                                                                 Client.Appearance.ReplaceOutfit(
                                                                                     items);
                                                                                 return true;
                                                                             }
                                                                         }
                                                                     }
                                                                     return false;
                                                                 });
             if (found) return Success("attaching " + wear);
             return Failure("did not find " + wear);
             //  if (!are.WaitOne(WEARABLE_TIMEOUT * 2))
             //     return Success("Timeout wearing " + wear + " " + (bake ? " (baked)" : " (not baked)");
             // else
         }
         catch (Exception ex)
         {
             return Failure("(Invalid outfit (" + ex.Message + ")" + args.str + ".");
         }
     }
     finally
     {
         // Client.Appearance.OnAppearanceUpdated -= callback;
     }
 }
Exemple #13
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool detatchAll = args.IsTrue("--detatchall");

            SimAvatar simAv;
            if (args.TryGetValue("target", out simAv))
            {
                UUID target = simAv.ID;
                string targetName = simAv.GetName();
                targetName += String.Format(" ({0})", target);
                if (Client.Appearances.ContainsKey(target))
                {
                    #region AvatarAppearance to AgentSetAppearance

                    AvatarAppearancePacket appearance = TheBotClient.Appearances[target];
                    AgentSetAppearancePacket set = Client.Appearance.MakeAppearancePacket();
                    set.AgentData.AgentID = Client.Self.AgentID;
                    set.AgentData.SessionID = Client.Self.SessionID;
                    set.AgentData.SerialNum = SerialNum++;
                    set.AgentData.Size = new Vector3(2f, 2f, 2f); // HACK

                    set.WearableData = new AgentSetAppearancePacket.WearableDataBlock[0];
                    set.VisualParam = new AgentSetAppearancePacket.VisualParamBlock[appearance.VisualParam.Length];

                    for (int i = 0; i < appearance.VisualParam.Length; i++)
                    {
                        set.VisualParam[i] = new AgentSetAppearancePacket.VisualParamBlock();
                        set.VisualParam[i].ParamValue = appearance.VisualParam[i].ParamValue;
                    }

                    set.ObjectData.TextureEntry = appearance.ObjectData.TextureEntry;

                    #endregion AvatarAppearance to AgentSetAppearance

                    // Detach everything we are currently wearing
                    if (detatchAll) Client.Appearance.AddAttachments(new List<InventoryItem>(), true);

                    // Send the new appearance packet
                    Client.Network.SendPacket(set);

                    return Success("Cloned " + targetName);
                }
                else
                {
                    /// allow clone thyself
                    if (Client.Self.AgentID == target)
                    {
                        AgentSetAppearancePacket set = Client.Appearance.MakeAppearancePacket();

                        Client.Network.SendPacket(set);
                        Logger.DebugLog("Send AgentSetAppearance packet");

                        return Success("Cloned " + targetName);
                    }
                    return Failure("Don't know the appearance of avatar " + targetName);
                }
            }
            else
            {
                return Failure("Couldn't find avatar " + args.str);
            }
        }
Exemple #14
0
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            bool   kill = args.IsTrue("--kill");
            bool   createFresh;
            string id = GetTaskID(args, out createFresh);

            if (kill && createFresh)
            {
                return(Failure("Cannot create and kill in the same operation"));
            }
            int secondsOfSleep;

            if (!args.TryGetValue("seconds", out secondsOfSleep))
            {
                return(ShowUsage());
            }
            // remove the time
            string[] cmdS;
            args.TryGetValue("command", out cmdS);
            string      cmd    = Parser.Rejoin(cmdS, 0);
            ThreadStart thread = () =>
            {
                try
                {
                    while (true)
                    {
                        try
                        {
                            Client.ExecuteCommand(cmd, args.CallerAgent, WriteLine,
                                                  args.CmdFlags);
                        }
                        catch (ThreadAbortException e)
                        {
                            WriteLine("Aborting " + cmd);
                        }
                        catch (Exception e)
                        {
                            WriteLine("Problem with " + cmd + " " + e);
                            return;
                        }
                        Thread.Sleep(secondsOfSleep * 1000);
                    }
                }
                finally
                {
                    try
                    {
                        TheBotClient.RemoveThread(Thread.CurrentThread);
                    }
                    catch (OutOfMemoryException)
                    {
                    }
                    catch (StackOverflowException)
                    {
                    }
                    catch (Exception)
                    {
                    }
                    WriteLine("done with " + cmd);
                }
            };
            String threadName = "Repeating " + cmd;
            string message    = TheBotClient.CreateTask(id, thread, threadName, createFresh, kill, null, WriteLine);

            SetResult("taskid", id);
            return(Success(message));
        }
Exemple #15
0
        public static CmdResult ExecuteRequestProc(CmdRequest args, Command thizcmd)
        {
            var TheBotClient = thizcmd.TheBotClient;
            OutputDelegate WriteLine = thizcmd.WriteLine;
            bool thread = args.IsTrue("--thread");
            bool queue = args.IsTrue("--queue");
            bool all = args.IsTrue("--all");
            bool kill = args.IsTrue("--kill");
            bool asyc = args.IsTrue("--async") || thread;
            TimeSpan wait;
            ManualResetEvent mre = null;
            if (args.TryGetValue("--wait", out wait))
            {
                mre = new ManualResetEvent(false);
            }
            bool newDebug = args.IsTrue("--debug");
            bool changeDebug = newDebug || args.IsTrue("--nodebug");

            bool createFresh = false;
            string id = args.Length == 0 ? "list" : GetTaskID(args, out createFresh);
            id = (id == "list") ? "" : id;
            int n = 0;
            int found = 0;
            if (id == "" || kill || changeDebug)
            {
                List<string> list = new List<string>();
                lock (TaskQueueHandler.TaskQueueHandlers)
                {
                    var atq = TheBotClient != null
                                  ? TheBotClient.AllTaskQueues()
                                  : ClientManager.SingleInstance.AllTaskQueues();
                    foreach (var queueHandler in atq)
                    {
                        if (!queueHandler.MatchesId(id)) continue;
                        bool isQueue = queueHandler.Impl == queueHandler;
                        if (isQueue) found++;
                        else n++;
                        if (changeDebug) queueHandler.DebugQueue = newDebug;
                        if (queueHandler.IsAlive)
                        {
                            string str = queueHandler.ToDebugString(true);
                            if (kill)
                            {
                                if (!all)
                                {
                                    if (!isQueue && !thread || isQueue && !queue)
                                    {
                                        WriteLine("Not killing " + str);
                                        continue;
                                    }
                                }
                                queueHandler.Abort();
                                str = "Killing " + str;
                                thizcmd.IncrResult("killed", 1);
                            }

                            WriteLine(str);
                        }
                        else
                        {
                            list.Add(queueHandler.ToDebugString(true));
                        }
                    }
                }
                foreach (var s in list)
                {
                    WriteLine(s);
                }
            }

            if (kill && createFresh)
            {
                return thizcmd.Failure("Cannot create and kill in the same operation");
            }
            string[] cmdS;
            args.TryGetValue("command", out cmdS);
            thizcmd.IncrResult("taskqueues", found);
            thizcmd.IncrResult("threads", n);
            if (cmdS == null || cmdS.Length == 0)
            {
                return thizcmd.Success("TaskQueueHandlers: " + found + ", threads: " + n);
            }

            /// task is killed if request.. now making a new one
            string cmd = Parser.Rejoin(cmdS, 0);
            bool needResult = mre != null;
            CmdResult[] result = null;
            if (createFresh) needResult = false;
            if (needResult)
            {
                result = new CmdResult[1];
            }
            CMDFLAGS flags = needResult ? CMDFLAGS.ForceResult : CMDFLAGS.Inherit;
            if (asyc) flags |= CMDFLAGS.ForceAsync;

            ThreadStart task = () =>
                                   {
                                       try
                                       {
                                           var res = TheBotClient.ExecuteCommand(cmd, args.CallerAgent, args.Output,
                                                                                 flags);
                                           if (result != null) result[0] = res;
                                       }
                                       catch (Exception)
                                       {
                                           throw;
                                       }
                                   };
            string message = TheBotClient.CreateTask(id, task, cmd, createFresh, false, mre, WriteLine);
            thizcmd.SetResult("taskid", id);
            if (mre != null)
            {
                if (!mre.WaitOne(wait)) return thizcmd.Failure("Timeout: " + message);
                if (result == null) return thizcmd.Success(message);
                return result[0] ?? thizcmd.Success(message);
            }
            return thizcmd.Success(message);
        }
 public override CmdResult ExecuteRequest(CmdRequest args)
 {
     //AutoResetEvent are = new AutoResetEvent(false);
     // AppearanceManager.AppearanceUpdatedCallback callback = (Primitive.TextureEntry te) => are.Set();
     try
     {
         //Client.Appearance.OnAppearanceUpdated += callback;
         // base.acceptInput(verb, args);
         string target = String.Empty;
         if (args.Length == 0)
         {
             return(ShowUsage());
         }
         bool   bake = true;
         string wear = args.str.Trim();
         if (args.IsTrue("nobake"))
         {
             bake = false;
             wear = wear.Substring(6).Trim();
         }
         if (args.IsTrue("test"))
         {
             bake = true;
             wear = wear.Substring(4).Trim();
             TheBotClient.wearFolder(wear);
             // if (!are.WaitOne(WEARABLE_TIMEOUT * 2))
             //   return Success("Timeout wearing " + wear + " " + (bake ? " (baked)" : " (not baked)");
             // else
             return(Success("wearing folder: " + wear + " " + (bake ? " (baked)" : " (not baked)")));
         }
         try
         {
             WriteLine("wearing folder: " + wear + " " + (bake ? " (baked)" : " (not baked)"));
             if (false)
             {
                 List <InventoryItem> outfit = Client.GetFolderItems(wear);
                 if (outfit != null)
                 {
                     Client.Appearance.ReplaceOutfit(outfit);
                     return(Success(wear));
                 }
                 WriteLine("no folder found attaching item: " + wear);
             }
             string           lwear      = wear.ToLower();
             BotInventoryEval searcher   = new BotInventoryEval(Client);
             InventoryFolder  rootFolder = Client.Inventory.Store.RootFolder;
             if (rootFolder.UUID == UUID.Zero)
             {
                 return(Success("Cant get roiot folder yet"));
             }
             bool found = searcher.findInFolders(rootFolder, (ib) =>
             {
                 if (ib.Name.ToLower() == lwear)
                 {
                     if (ib is InventoryItem)
                     {
                         Client.Appearance.Attach(
                             ib as InventoryItem,
                             AttachmentPoint.Default);
                         return(true);
                     }
                     else
                     {
                         var fldr = ib as InventoryFolder;
                         List <InventoryBase>
                         clientInventoryFolderContents =
                             Client.Inventory.
                             FolderContents(ib.UUID,
                                            Client.
                                            Self.
                                            AgentID,
                                            false,
                                            true,
                                            InventorySortOrder
                                            .
                                            ByName,
                                            40000);
                         if (clientInventoryFolderContents ==
                             null)
                         {
                             return(false);
                         }
                         List <InventoryItem> items =
                             new List <InventoryItem>();
                         foreach (
                             InventoryBase content in
                             clientInventoryFolderContents
                             )
                         {
                             var it =
                                 content as InventoryItem;
                             if (it != null)
                             {
                                 items.Add(it);
                             }
                         }
                         if (items.Count > 0)
                         {
                             Client.Appearance.ReplaceOutfit(
                                 items);
                             return(true);
                         }
                     }
                 }
                 return(false);
             });
             if (found)
             {
                 return(Success("attaching " + wear));
             }
             return(Failure("did not find " + wear));
             //  if (!are.WaitOne(WEARABLE_TIMEOUT * 2))
             //     return Success("Timeout wearing " + wear + " " + (bake ? " (baked)" : " (not baked)");
             // else
         }
         catch (Exception ex)
         {
             return(Failure("(Invalid outfit (" + ex.Message + ")" + args.str + "."));
         }
     }
     finally
     {
         // Client.Appearance.OnAppearanceUpdated -= callback;
     }
 }
Exemple #17
0
 public override CmdResult ExecuteRequest(CmdRequest args)
 {
     bool kill = args.IsTrue("--kill");
     bool createFresh;
     string id = GetTaskID(args, out createFresh);
     if (kill && createFresh)
     {
         return Failure("Cannot create and kill in the same operation");
     }
     int secondsOfSleep;
     if (!args.TryGetValue("seconds", out secondsOfSleep))
     {
         return ShowUsage();
     }
     // remove the time
     string[] cmdS;
     args.TryGetValue("command", out cmdS);
     string cmd = Parser.Rejoin(cmdS, 0);
     ThreadStart thread = () =>
                              {
                                  try
                                  {
                                      while (true)
                                      {
                                          try
                                          {
                                              Client.ExecuteCommand(cmd, args.CallerAgent, WriteLine,
                                                                    args.CmdFlags);
                                          }
                                          catch (ThreadAbortException e)
                                          {
                                              WriteLine("Aborting " + cmd);
                                          }
                                          catch (Exception e)
                                          {
                                              WriteLine("Problem with " + cmd + " " + e);
                                              return;
                                          }
                                          Thread.Sleep(secondsOfSleep*1000);
                                      }
                                  }
                                  finally
                                  {
                                      try
                                      {
                                          TheBotClient.RemoveThread(Thread.CurrentThread);
                                      }
                                      catch (OutOfMemoryException)
                                      {
                                      }
                                      catch (StackOverflowException)
                                      {
                                      }
                                      catch (Exception)
                                      {
                                      }
                                      WriteLine("done with " + cmd);
                                  }
                              };
     String threadName = "Repeating " + cmd;
     string message = TheBotClient.CreateTask(id, thread, threadName, createFresh, kill, null, WriteLine);
     SetResult("taskid", id);
     return Success(message);
 }
        public static CmdResult ExecuteRequestProc(CmdRequest args, Command thizcmd)
        {
            var              TheBotClient = thizcmd.TheBotClient;
            OutputDelegate   WriteLine    = thizcmd.WriteLine;
            bool             thread       = args.IsTrue("--thread");
            bool             queue        = args.IsTrue("--queue");
            bool             all          = args.IsTrue("--all");
            bool             kill         = args.IsTrue("--kill");
            bool             asyc         = args.IsTrue("--async") || thread;
            TimeSpan         wait;
            ManualResetEvent mre = null;

            if (args.TryGetValue("--wait", out wait))
            {
                mre = new ManualResetEvent(false);
            }
            bool newDebug    = args.IsTrue("--debug");
            bool changeDebug = newDebug || args.IsTrue("--nodebug");

            bool   createFresh = false;
            string id          = args.Length == 0 ? "list" : GetTaskID(args, out createFresh);

            id = (id == "list") ? "" : id;
            int n     = 0;
            int found = 0;

            if (id == "" || kill || changeDebug)
            {
                List <string> list = new List <string>();
                lock (TaskQueueHandler.TaskQueueHandlers)
                {
                    var atq = TheBotClient != null
                                  ? TheBotClient.AllTaskQueues()
                                  : ClientManager.SingleInstance.AllTaskQueues();

                    foreach (var queueHandler in atq)
                    {
                        if (!queueHandler.MatchesId(id))
                        {
                            continue;
                        }
                        bool isQueue = queueHandler.Impl == queueHandler;
                        if (isQueue)
                        {
                            found++;
                        }
                        else
                        {
                            n++;
                        }
                        if (changeDebug)
                        {
                            queueHandler.DebugQueue = newDebug;
                        }
                        if (queueHandler.IsAlive)
                        {
                            string str = queueHandler.ToDebugString(true);
                            if (kill)
                            {
                                if (!all)
                                {
                                    if (!isQueue && !thread || isQueue && !queue)
                                    {
                                        WriteLine("Not killing " + str);
                                        continue;
                                    }
                                }
                                queueHandler.Abort();
                                str = "Killing " + str;
                                thizcmd.IncrResult("killed", 1);
                            }

                            WriteLine(str);
                        }
                        else
                        {
                            list.Add(queueHandler.ToDebugString(true));
                        }
                    }
                }
                foreach (var s in list)
                {
                    WriteLine(s);
                }
            }

            if (kill && createFresh)
            {
                return(thizcmd.Failure("Cannot create and kill in the same operation"));
            }
            string[] cmdS;
            args.TryGetValue("command", out cmdS);
            thizcmd.IncrResult("taskqueues", found);
            thizcmd.IncrResult("threads", n);
            if (cmdS == null || cmdS.Length == 0)
            {
                return(thizcmd.Success("TaskQueueHandlers: " + found + ", threads: " + n));
            }

            /// task is killed if request.. now making a new one
            string cmd        = Parser.Rejoin(cmdS, 0);
            bool   needResult = mre != null;

            CmdResult[] result = null;
            if (createFresh)
            {
                needResult = false;
            }
            if (needResult)
            {
                result = new CmdResult[1];
            }
            CMDFLAGS flags = needResult ? CMDFLAGS.ForceResult : CMDFLAGS.Inherit;

            if (asyc)
            {
                flags |= CMDFLAGS.ForceAsync;
            }

            ThreadStart task = () =>
            {
                try
                {
                    var res = TheBotClient.ExecuteCommand(cmd, args.CallerAgent, args.Output,
                                                          flags);
                    if (result != null)
                    {
                        result[0] = res;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            };
            string message = TheBotClient.CreateTask(id, task, cmd, createFresh, false, mre, WriteLine);

            thizcmd.SetResult("taskid", id);
            if (mre != null)
            {
                if (!mre.WaitOne(wait))
                {
                    return(thizcmd.Failure("Timeout: " + message));
                }
                if (result == null)
                {
                    return(thizcmd.Success(message));
                }
                return(result[0] ?? thizcmd.Success(message));
            }
            return(thizcmd.Success(message));
        }