Inheritance: OpenMetaverse.TestClient.Command
Example #1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="fromAgentID"></param>
        /// <param name="imSessionID"></param>
        public void DoCommandAll(string cmd, UUID fromAgentID)
        {
            string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' });
            if (tokens.Length == 0)
                return;
            
            string firstToken = tokens[0].ToLower();
            if (String.IsNullOrEmpty(firstToken))
                return;

            // Allow for comments when cmdline begins with ';' or '#'
            if (firstToken[0] == ';' || firstToken[0] == '#')
                return;
            
            string[] args = new string[tokens.Length - 1];
            if (args.Length > 0)
                Array.Copy(tokens, 1, args, 0, args.Length);

            if (firstToken == "login")
            {
                Login(args);
            }
            else if (firstToken == "quit")
            {
                Quit();
                Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info);
            }
            else if (firstToken == "help")
            {
                if (Clients.Count > 0)
                {
                    foreach (TestClient client in Clients.Values)
                    {
                        Console.WriteLine(client.Commands["help"].Execute(args, UUID.Zero));
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You must login at least one bot to use the help command");
                }
            }
            else if (firstToken == "script")
            {
                // No reason to pass this to all bots, and we also want to allow it when there are no bots
                ScriptCommand command = new ScriptCommand(null);
                Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
            }
            else
            {
                // Make an immutable copy of the Clients dictionary to safely iterate over
                Dictionary<UUID, TestClient> clientsCopy = new Dictionary<UUID, TestClient>(Clients);

                int completed = 0;

                foreach (TestClient client in clientsCopy.Values)
                {
                    ThreadPool.QueueUserWorkItem((WaitCallback)
                        delegate(object state)
                        {
                            TestClient testClient = (TestClient)state;
                            if (testClient.Commands.ContainsKey(firstToken))
                                Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
                                    Helpers.LogLevel.Info, testClient);
                            else
                                Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);

                            ++completed;
                        },
                        client);
                }

                while (completed < clientsCopy.Count)
                    Thread.Sleep(50);
            }
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="fromAgentID"></param>
        /// <param name="imSessionID"></param>
        public void DoCommandAll(string cmd, UUID fromAgentID)
        {
            string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' });
            if (tokens.Length == 0)
                return;
            
            string firstToken = tokens[0].ToLower();
            if (String.IsNullOrEmpty(firstToken))
                return;

            // Allow for comments when cmdline begins with ';' or '#'
            if (firstToken[0] == ';' || firstToken[0] == '#')
                return;

            if ('@' == firstToken[0]) {
                onlyAvatar = String.Empty;
                if (tokens.Length == 3) {
                    bool found = false;
                    onlyAvatar = tokens[1]+" "+tokens[2];
                    foreach (TestClient client in Clients.Values) {
                        if ((client.ToString() == onlyAvatar) && (client.Network.Connected)) {
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        Logger.Log("Commanding only "+onlyAvatar+" now", Helpers.LogLevel.Info);
                    } else {
                        Logger.Log("Commanding nobody now. Avatar "+onlyAvatar+" is offline", Helpers.LogLevel.Info);
                    }
                } else {
                    Logger.Log("Commanding all avatars now", Helpers.LogLevel.Info);
                }
                return;
            }
            
            string[] args = new string[tokens.Length - 1];
            if (args.Length > 0)
                Array.Copy(tokens, 1, args, 0, args.Length);

            if (firstToken == "login")
            {
                Login(args);
            }
            else if (firstToken == "quit")
            {
                Quit();
                Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info);
            }
            else if (firstToken == "help")
            {
                if (Clients.Count > 0)
                {
                    foreach (TestClient client in Clients.Values)
                    {
                        Console.WriteLine(client.Commands["help"].Execute(args, UUID.Zero));
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You must login at least one bot to use the help command");
                }
            }
            else if (firstToken == "script")
            {
                // No reason to pass this to all bots, and we also want to allow it when there are no bots
                ScriptCommand command = new ScriptCommand(null);
                Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
            }
            else if (firstToken == "waitforlogin")
            {
                // Special exception to allow this to run before any bots have logged in
                if (ClientManager.Instance.PendingLogins > 0)
                {
                    WaitForLoginCommand command = new WaitForLoginCommand(null);
                    Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
                }
                else
                {
                    Logger.Log("No pending logins", Helpers.LogLevel.Info);
                }
            }
            else
            {
                // Make an immutable copy of the Clients dictionary to safely iterate over
                Dictionary<UUID, TestClient> clientsCopy = new Dictionary<UUID, TestClient>(Clients);

                int completed = 0;

                foreach (TestClient client in clientsCopy.Values)
                {
                    ThreadPool.QueueUserWorkItem((WaitCallback)
                        delegate(object state)
                        {
                            TestClient testClient = (TestClient)state;
                            if ((String.Empty == onlyAvatar) || (testClient.ToString() == onlyAvatar)) {
                                if (testClient.Commands.ContainsKey(firstToken))
                                    Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
                                        Helpers.LogLevel.Info, testClient);
                                else
                                    Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
                            }

                            ++completed;
                        },
                        client);
                }

                while (completed < clientsCopy.Count)
                    Thread.Sleep(50);
            }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="fromAgentID"></param>
        /// <param name="imSessionID"></param>
        public void DoCommandAll(string cmd, UUID fromAgentID)
        {
            string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' });
            if (tokens.Length == 0)
            {
                return;
            }

            string firstToken = tokens[0].ToLower();

            if (String.IsNullOrEmpty(firstToken))
            {
                return;
            }

            // Allow for comments when cmdline begins with ';' or '#'
            if (firstToken[0] == ';' || firstToken[0] == '#')
            {
                return;
            }

            if ('@' == firstToken[0])
            {
                onlyAvatar = String.Empty;
                if (tokens.Length == 3)
                {
                    bool found = false;
                    onlyAvatar = tokens[1] + " " + tokens[2];
                    foreach (TestClient client in Clients.Values)
                    {
                        if ((client.ToString() == onlyAvatar) && (client.Network.Connected))
                        {
                            found = true;
                            break;
                        }
                    }
                    if (found)
                    {
                        Logger.Log("Commanding only " + onlyAvatar + " now", Helpers.LogLevel.Info);
                    }
                    else
                    {
                        Logger.Log("Commanding nobody now. Avatar " + onlyAvatar + " is offline", Helpers.LogLevel.Info);
                    }
                }
                else
                {
                    Logger.Log("Commanding all avatars now", Helpers.LogLevel.Info);
                }
                return;
            }

            string[] args = new string[tokens.Length - 1];
            if (args.Length > 0)
            {
                Array.Copy(tokens, 1, args, 0, args.Length);
            }

            if (firstToken == "login")
            {
                Login(args);
            }
            else if (firstToken == "quit")
            {
                Quit();
                Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info);
            }
            else if (firstToken == "help")
            {
                if (Clients.Count > 0)
                {
                    foreach (TestClient client in Clients.Values)
                    {
                        Console.WriteLine(client.Commands["help"].Execute(args, UUID.Zero));
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You must login at least one bot to use the help command");
                }
            }
            else if (firstToken == "script")
            {
                // No reason to pass this to all bots, and we also want to allow it when there are no bots
                ScriptCommand command = new ScriptCommand(null);
                Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
            }
            else if (firstToken == "waitforlogin")
            {
                // Special exception to allow this to run before any bots have logged in
                if (ClientManager.Instance.PendingLogins > 0)
                {
                    WaitForLoginCommand command = new WaitForLoginCommand(null);
                    Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
                }
                else
                {
                    Logger.Log("No pending logins", Helpers.LogLevel.Info);
                }
            }
            else
            {
                // Make an immutable copy of the Clients dictionary to safely iterate over
                Dictionary <UUID, TestClient> clientsCopy = new Dictionary <UUID, TestClient>(Clients);

                int completed = 0;

                foreach (TestClient client in clientsCopy.Values)
                {
                    ThreadPool.QueueUserWorkItem((WaitCallback)
                                                 delegate(object state)
                    {
                        TestClient testClient = (TestClient)state;
                        if ((String.Empty == onlyAvatar) || (testClient.ToString() == onlyAvatar))
                        {
                            if (testClient.Commands.ContainsKey(firstToken))
                            {
                                Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
                                           Helpers.LogLevel.Info, testClient);
                            }
                            else
                            {
                                Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
                            }
                        }

                        ++completed;
                    },
                                                 client);
                }

                while (completed < clientsCopy.Count)
                {
                    Thread.Sleep(50);
                }
            }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="fromAgentID"></param>
        /// <param name="imSessionID"></param>
        public void DoCommandAll(string cmd, UUID fromAgentID)
        {
            string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' });
            if (tokens.Length == 0)
            {
                return;
            }

            string firstToken = tokens[0].ToLower();

            if (String.IsNullOrEmpty(firstToken))
            {
                return;
            }

            string[] args = new string[tokens.Length - 1];
            if (args.Length > 0)
            {
                Array.Copy(tokens, 1, args, 0, args.Length);
            }

            if (firstToken == "login")
            {
                Login(args);
            }
            else if (firstToken == "quit")
            {
                Quit();
                Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info);
            }
            else if (firstToken == "help")
            {
                if (Clients.Count > 0)
                {
                    foreach (TestClient client in Clients.Values)
                    {
                        Console.WriteLine(client.Commands["help"].Execute(args, UUID.Zero));
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You must login at least one bot to use the help command");
                }
            }
            else if (firstToken == "script")
            {
                // No reason to pass this to all bots, and we also want to allow it when there are no bots
                ScriptCommand command = new ScriptCommand(null);
                Logger.Log(command.Execute(args, UUID.Zero), Helpers.LogLevel.Info);
            }
            else
            {
                // Make an immutable copy of the Clients dictionary to safely iterate over
                Dictionary <UUID, TestClient> clientsCopy = new Dictionary <UUID, TestClient>(Clients);

                int completed = 0;

                foreach (TestClient client in clientsCopy.Values)
                {
                    ThreadPool.QueueUserWorkItem((WaitCallback)
                                                 delegate(object state)
                    {
                        TestClient testClient = (TestClient)state;
                        if (testClient.Commands.ContainsKey(firstToken))
                        {
                            Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID),
                                       Helpers.LogLevel.Info, testClient);
                        }
                        else
                        {
                            Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
                        }

                        ++completed;
                    },
                                                 client);
                }

                while (completed < clientsCopy.Count)
                {
                    Thread.Sleep(50);
                }
            }
        }