diff --git a/Programs/examples/TestClient/ClientManager.cs b/Programs/examples/TestClient/ClientManager.cs index e31de55a..0bbc21a0 100644 --- a/Programs/examples/TestClient/ClientManager.cs +++ b/Programs/examples/TestClient/ClientManager.cs @@ -146,10 +146,10 @@ namespace OpenMetaverse.TestClient account.LastName = args[1]; account.Password = args[2]; - if (args.Length == 4) - { + if (args.Length > 3) account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40); - } + if (args.Length > 4) + account.URI = args[4]; return Login(account); } @@ -212,15 +212,23 @@ namespace OpenMetaverse.TestClient else if (firstToken == "quit") { Quit(); - Console.WriteLine("All clients logged out and program finished running."); + Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info); } else { - // make a copy of the clients list so that it can be iterated without fear of being changed during iteration + // Make an immutable copy of the Clients dictionary to safely iterate over Dictionary clientsCopy = new Dictionary(Clients); + int completed = 0; + foreach (TestClient client in clientsCopy.Values) - client.DoCommand(cmd, fromAgentID); + { + ThreadStart starter = delegate() { client.DoCommand(cmd, fromAgentID); }; + starter.BeginInvoke((AsyncCallback)delegate(IAsyncResult ar) { ++completed; }, null); + } + + while (completed < clientsCopy.Count) + Thread.Sleep(50); } } diff --git a/Programs/examples/TestClient/Commands/System/LoginCommand.cs b/Programs/examples/TestClient/Commands/System/LoginCommand.cs index 32b15ced..a2344d53 100644 --- a/Programs/examples/TestClient/Commands/System/LoginCommand.cs +++ b/Programs/examples/TestClient/Commands/System/LoginCommand.cs @@ -11,25 +11,14 @@ namespace OpenMetaverse.TestClient public LoginCommand(TestClient testClient) { Name = "login"; - Description = "Logs in another avatar"; + Description = "Logs in another avatar. Usage: login firstname lastname [simname] [loginuri]"; Category = CommandCategory.TestClient; } public override string Execute(string[] args, UUID fromAgentID) { - if (args.Length != 3 && args.Length != 4) - return "usage: login firstname lastname password [simname]"; - - GridClient newClient = Client.ClientManager.Login(args); - - if (newClient.Network.Connected) - { - return "Logged in " + newClient.ToString(); - } - else - { - return "Failed to login: " + newClient.Network.LoginMessage; - } + // This is a dummy command. Calls to it should be intercepted and handled specially + return "This command should not be executed directly"; } } } diff --git a/Programs/examples/TestClient/Commands/System/QuitCommand.cs b/Programs/examples/TestClient/Commands/System/QuitCommand.cs index fa2b7c15..c6b30d8b 100644 --- a/Programs/examples/TestClient/Commands/System/QuitCommand.cs +++ b/Programs/examples/TestClient/Commands/System/QuitCommand.cs @@ -17,9 +17,8 @@ namespace OpenMetaverse.TestClient public override string Execute(string[] args, UUID fromAgentID) { - Client.ClientManager.LogoutAll(); - Client.ClientManager.Running = false; - return "All avatars logged out"; + // This is a dummy command. Calls to it should be intercepted and handled specially + return "This command should not be executed directly"; } } } diff --git a/Programs/examples/TestClient/Program.cs b/Programs/examples/TestClient/Program.cs index f7b85c01..c9e02c98 100644 --- a/Programs/examples/TestClient/Program.cs +++ b/Programs/examples/TestClient/Program.cs @@ -8,7 +8,7 @@ namespace OpenMetaverse.TestClient public class CommandLineArgumentsException : Exception { } - + public class Program { private static void Usage() @@ -28,104 +28,79 @@ namespace OpenMetaverse.TestClient string masterName = String.Empty; UUID masterKey = UUID.Zero; string file = String.Empty; - string loginuri = String.Empty; + string loginuri = String.Empty; - try + if (arguments["groupcommands"] != null) + groupCommands = true; + + if (arguments["masterkey"] != null) + masterKey = UUID.Parse(arguments["masterkey"]); + + if (arguments["master"] != null) + masterName = arguments["master"]; + + if (arguments["loginuri"] != null) + loginuri = arguments["loginuri"]; + + if (arguments["file"] != null) { - if (arguments["groupcommands"] != null) + file = arguments["file"]; + + if (!File.Exists(file)) { - groupCommands = true; + Console.WriteLine("File {0} Does not exist", file); + return; } - if (arguments["masterkey"] != null) + // Loading names from a file + try { - masterKey = UUID.Parse(arguments["masterkey"]); - } - - if (arguments["master"] != null) - { - masterName = arguments["master"]; - } - - if (arguments["loginuri"] != null) - { - loginuri = arguments["loginuri"]; - } - - if (arguments["file"] != null) - { - file = arguments["file"]; - - if (!File.Exists(file)) + using (StreamReader reader = new StreamReader(file)) { - Console.WriteLine("File {0} Does not exist", file); - return; - } + string line; + int lineNumber = 0; - // Loading names from a file - try - { - using (StreamReader reader = new StreamReader(file)) + while ((line = reader.ReadLine()) != null) { - string line; - int lineNumber = 0; + lineNumber++; + string[] tokens = line.Trim().Split(new char[] { ' ', ',' }); - while ((line = reader.ReadLine()) != null) + if (tokens.Length >= 3) { - lineNumber++; - string[] tokens = line.Trim().Split(new char[] { ' ', ',' }); + account = new LoginDetails(); + account.FirstName = tokens[0]; + account.LastName = tokens[1]; + account.Password = tokens[2]; - if (tokens.Length >= 3) - { - account = new LoginDetails(); - account.FirstName = tokens[0]; - account.LastName = tokens[1]; - account.Password = tokens[2]; - - accounts.Add(account); - - // Leaving this out until we have per-account masters (if that - // is desirable). For now the command-line option can - // specify the single master that TestClient supports - - //if (tokens.Length == 5) - //{ - // master = tokens[3] + " " + tokens[4]; - //} - } - else - { - Console.WriteLine("Invalid data on line " + lineNumber + - ", must be in the format of: FirstName LastName Password"); - } + accounts.Add(account); + } + else + { + Logger.Log("Invalid data on line " + lineNumber + + ", must be in the format of: FirstName LastName Password", + Helpers.LogLevel.Warning); } } } - catch (Exception e) - { - Console.WriteLine("Error reading from " + args[1]); - Console.WriteLine(e.ToString()); - return; - } } - else if (arguments["first"] != null && arguments["last"] != null && arguments["pass"] != null) + catch (Exception e) { - // Taking a single login off the command-line - account = new LoginDetails(); - account.FirstName = arguments["first"]; - account.LastName = arguments["last"]; - account.Password = arguments["pass"]; - - accounts.Add(account); - - } - else - { - throw new CommandLineArgumentsException(); + Console.WriteLine("Error reading from " + args[1]); + Console.WriteLine(e.ToString()); + return; } } + else if (arguments["first"] != null && arguments["last"] != null && arguments["pass"] != null) + { + // Taking a single login off the command-line + account = new LoginDetails(); + account.FirstName = arguments["first"]; + account.LastName = arguments["last"]; + account.Password = arguments["pass"]; - catch (CommandLineArgumentsException) + accounts.Add(account); + } + else if (arguments["help"] != null) { Usage(); return; @@ -141,13 +116,9 @@ namespace OpenMetaverse.TestClient // Login the accounts and run the input loop if (arguments["startpos"] != null) - { manager = new ClientManager(accounts, arguments["startpos"]); - } else - { manager = new ClientManager(accounts); - } manager.Run(); } diff --git a/Programs/examples/TestClient/TestClient.cs b/Programs/examples/TestClient/TestClient.cs index 4aaf37c7..ef4ed153 100644 --- a/Programs/examples/TestClient/TestClient.cs +++ b/Programs/examples/TestClient/TestClient.cs @@ -131,7 +131,7 @@ namespace OpenMetaverse.TestClient string[] tokens; try { tokens = Parsing.ParseArguments(cmd); } - catch (FormatException ex) { Console.WriteLine(ex.Message); return; } + catch (FormatException ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); return; } if (tokens.Length == 0) return; @@ -145,16 +145,24 @@ namespace OpenMetaverse.TestClient // Reserialize all of the arguments except for "all" for (int i = 1; i < tokens.Length; i++) - { cmd += tokens[i] + " "; - } ClientManager.DoCommandAll(cmd, fromAgentID); - - return; } - - if (Commands.ContainsKey(firstToken)) + else if (firstToken == "login") + { + // Special login case: Only call it once, and allow it with + // no logged in avatars + string[] args = new string[tokens.Length - 1]; + Array.Copy(tokens, 1, args, 0, args.Length); + ClientManager.Login(args); + } + else if (firstToken == "quit") + { + ClientManager.Quit(); + Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info); + } + else if (Commands.ContainsKey(firstToken)) { string[] args = new string[tokens.Length - 1]; Array.Copy(tokens, 1, args, 0, args.Length);