diff --git a/Programs/examples/TestClient/ClientManager.cs b/Programs/examples/TestClient/ClientManager.cs index ab7bacee..d0a8ecd2 100644 --- a/Programs/examples/TestClient/ClientManager.cs +++ b/Programs/examples/TestClient/ClientManager.cs @@ -107,27 +107,37 @@ namespace OpenMetaverse.TestClient if (client.Network.Login(loginParams)) { Clients[client.Self.AgentID] = client; + if (client.MasterKey == UUID.Zero) { UUID query = UUID.Random(); - client.Directory.OnDirPeopleReply += + DirectoryManager.DirPeopleReplyCallback peopleDirCallback = delegate(UUID queryID, List matchedPeople) { - if (queryID != query) - return; - if (matchedPeople.Count != 1) - Console.WriteLine("Unable to resolve master key."); - else - client.MasterKey = matchedPeople[0].AgentID; + if (queryID == query) + { + if (matchedPeople.Count != 1) + { + Logger.Log("Unable to resolve master key from " + client.MasterName, Helpers.LogLevel.Warning); + } + else + { + client.MasterKey = matchedPeople[0].AgentID; + Logger.Log("Master key resolved to " + client.MasterKey, Helpers.LogLevel.Info); + } + } }; + + client.Directory.OnDirPeopleReply += peopleDirCallback; client.Directory.StartPeopleSearch(DirectoryManager.DirFindFlags.People, client.MasterName, 0, query); } - Console.WriteLine("Logged in " + client.ToString()); + + Logger.Log("Logged in " + client.ToString(), Helpers.LogLevel.Info); } else { - Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " + - client.Network.LoginMessage); + Logger.Log("Failed to login " + account.FirstName + " " + account.LastName + ": " + + client.Network.LoginMessage, Helpers.LogLevel.Warning); } return client; @@ -195,13 +205,16 @@ namespace OpenMetaverse.TestClient public void DoCommandAll(string cmd, UUID fromAgentID) { string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' }); - string firstToken = tokens[0].ToLower(); - - string[] args = new string[tokens.Length - 1]; - Array.Copy(tokens, 1, args, 0, args.Length); - 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") { @@ -245,10 +258,12 @@ namespace OpenMetaverse.TestClient ThreadPool.QueueUserWorkItem((WaitCallback) delegate(object state) { - Logger.Log(client.Commands[firstToken].Execute(args, fromAgentID), - Helpers.LogLevel.Info); + TestClient testClient = (TestClient)state; + Logger.Log(testClient.Commands[firstToken].Execute(args, fromAgentID), + Helpers.LogLevel.Info, testClient); ++completed; - }); + }, + client); } while (completed < clientsCopy.Count) @@ -266,24 +281,11 @@ namespace OpenMetaverse.TestClient client.Network.Logout(); } - /// - /// - /// - public void LogoutAll() - { - // make a copy of the clients list so that it can be iterated without fear of being changed during iteration - Dictionary clientsCopy = new Dictionary(Clients); - - foreach (TestClient client in clientsCopy.Values) - Logout(client); - } - /// /// /// public void Quit() { - LogoutAll(); Running = false; // TODO: It would be really nice if we could figure out a way to abort the ReadLine here in so that Run() will exit. } diff --git a/Programs/examples/TestClient/Program.cs b/Programs/examples/TestClient/Program.cs index a9bf6ea6..c0be00d6 100644 --- a/Programs/examples/TestClient/Program.cs +++ b/Programs/examples/TestClient/Program.cs @@ -149,14 +149,7 @@ namespace OpenMetaverse.TestClient manager = new ClientManager(accounts, getTextures); if (!String.IsNullOrEmpty(scriptFile)) - { - // Kick off the initially specified script - string[] scriptargs = new string[1]; - scriptargs[0] = scriptFile; - - ScriptCommand command = new ScriptCommand(null); - Logger.Log(command.Execute(scriptargs, UUID.Zero), Helpers.LogLevel.Info); - } + manager.DoCommandAll("script " + scriptFile, UUID.Zero); // Then Run the ClientManager normally manager.Run(); diff --git a/Programs/examples/TestClient/TestClient.cs b/Programs/examples/TestClient/TestClient.cs index e19e63cd..26a82c00 100644 --- a/Programs/examples/TestClient/TestClient.cs +++ b/Programs/examples/TestClient/TestClient.cs @@ -126,66 +126,6 @@ namespace OpenMetaverse.TestClient } } - public void DoCommand(string cmd, UUID fromAgentID) - { - string[] tokens; - - try { tokens = Parsing.ParseArguments(cmd); } - catch (FormatException ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, ex); return; } - - if (tokens.Length == 0) - return; - - string firstToken = tokens[0].ToLower(); - - string[] args = new string[tokens.Length - 1]; - Array.Copy(tokens, 1, args, 0, args.Length); - - // "all balance" will send the balance command to all currently logged in bots - if (firstToken == "all" && tokens.Length > 1) - { - cmd = String.Empty; - - // Reserialize all of the arguments except for "all" - for (int i = 1; i < tokens.Length; i++) - cmd += tokens[i] + " "; - - ClientManager.DoCommandAll(cmd, fromAgentID); - } - else if (firstToken == "login") - { - // Special login case: Only call it once, and allow it with - // no logged in avatars - ClientManager.Login(args); - } - else if (firstToken == "quit") - { - ClientManager.Quit(); - Logger.Log("All clients logged out and program finished running.", Helpers.LogLevel.Info); - } - else if (firstToken == "script") - { - // Execute only once - Logger.Log(Commands[firstToken].Execute(args, fromAgentID), Helpers.LogLevel.Info); - } - else if (Commands.ContainsKey(firstToken)) - { - string response = Commands[firstToken].Execute(args, fromAgentID); - - if (!String.IsNullOrEmpty(response)) - { - Logger.Log(response, Helpers.LogLevel.Info); - - if (fromAgentID != UUID.Zero && Network.Connected) - { - // IMs don't like \r\n line endings, clean them up first - response = response.Replace("\r", String.Empty); - SendResponseIM(this, fromAgentID, response); - } - } - } - } - private void updateTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { foreach (Command c in Commands.Values) @@ -227,7 +167,6 @@ namespace OpenMetaverse.TestClient private void Self_OnInstantMessage(InstantMessage im, Simulator simulator) { - bool groupIM = im.GroupIM && GroupMembers != null && GroupMembers.ContainsKey(im.FromAgentID) ? true : false; if (im.FromAgentID == MasterKey || (GroupCommands && groupIM)) @@ -244,10 +183,9 @@ namespace OpenMetaverse.TestClient im.Dialog == InstantMessageDialog.MessageFromAgent || im.Dialog == InstantMessageDialog.MessageFromObject) { - DoCommand(im.Message, im.FromAgentID); + ClientManagerRef.ClientManager.DoCommandAll(im.Message, im.FromAgentID); } } - else { // Received an IM from someone that is not the bot's master, ignore @@ -255,7 +193,6 @@ namespace OpenMetaverse.TestClient im.RegionID, im.Position); return; } - } private bool Inventory_OnInventoryObjectReceived(InstantMessage offer, AssetType type,