diff --git a/libsecondlife-cs/examples/TestClient/ClientManager.cs b/libsecondlife-cs/examples/TestClient/ClientManager.cs index dfbe8d85..d509b4e4 100644 --- a/libsecondlife-cs/examples/TestClient/ClientManager.cs +++ b/libsecondlife-cs/examples/TestClient/ClientManager.cs @@ -1,194 +1,239 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Xml; -using libsecondlife; -using libsecondlife.Packets; -using libsecondlife.AssetSystem; - -namespace libsecondlife.TestClient -{ - public class LoginDetails - { - public string FirstName; - public string LastName; - public string Password; - public string Master; - } - - public class ClientManager - { - public Dictionary Clients = new Dictionary(); - public Dictionary> SimPrims = new Dictionary>(); - - public bool Running = true; - - /// - /// - /// - /// - public ClientManager(List accounts) - { - foreach (LoginDetails account in accounts) - Login(account); - } - - /// - /// - /// - /// - /// - public TestClient Login(LoginDetails account) - { - // Check if this client is already logged in - foreach (TestClient c in Clients.Values) - { - if (c.Self.FirstName == account.FirstName && c.Self.LastName == account.LastName) - { - Logout(c); - break; - } - } - - TestClient client = new TestClient(this); - - client.SimPrims = SimPrims; - client.Master = account.Master; - - if ( ! client.Network.Login(account.FirstName, account.LastName, account.Password, "TestClient", "contact@libsecondlife.org") ) { - Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " + client.Network.LoginError); - } - - if (client.Network.Connected) - { - Clients[client.Network.AgentID] = client; - - Console.WriteLine("Logged in " + client.ToString()); - - // Throttle the connection to not receive LayerData or asset packets - client.Throttle.Total = 0.0f; - client.Throttle.Task = 1536000.0f; - client.Throttle.Set(); - } - - return client; - } - - /// - /// - /// - /// - /// - public TestClient Login(string[] args) - { - LoginDetails account = new LoginDetails(); - account.FirstName = args[0]; - account.LastName = args[1]; - account.Password = args[2]; - - return Login(account); - } - - /// - /// - /// - public void Run() - { - Console.WriteLine("Type quit to exit. Type help for a command list."); - - while (Running) - { - PrintPrompt(); - string input = Console.ReadLine(); - DoCommandAll(input, null, null); - } - - foreach (SecondLife client in Clients.Values) - { - if (client.Network.Connected) - client.Network.Logout(); - } - } - - private void PrintPrompt() - { - int online = 0; - - foreach (SecondLife client in Clients.Values) - { - if (client.Network.Connected) online++; - } - - Console.Write(online + " avatars online> "); - } - - /// - /// - /// - /// - /// - /// - public void DoCommandAll(string cmd, LLUUID fromAgentID, LLUUID imSessionID) - { - string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' }); - string firstToken = tokens[0].ToLower(); - - if (tokens.Length == 0) - return; - - 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); - Login(args); - } - else if (firstToken == "quit") - { - Quit(); - Console.WriteLine("All clients logged out and program finished running."); - } - else - { - // 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) - client.DoCommand(cmd, fromAgentID, imSessionID); - } - } - - /// - /// - /// - /// - public void Logout(TestClient client) - { - Clients.Remove(client.Network.AgentID); - 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. - } - } -} +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Xml; +using libsecondlife; +using libsecondlife.Packets; +using libsecondlife.AssetSystem; + +namespace libsecondlife.TestClient +{ + public class LoginDetails + { + public string FirstName; + public string LastName; + public string Password; + public string Master; + } + + public class StartPosition + { + public string sim; + public int x; + public int y; + public int z; + + public StartPosition() + { + this.sim = null; + this.x = 0; + this.y = 0; + this.z = 0; + } + } + + public class ClientManager + { + public Dictionary Clients = new Dictionary(); + public Dictionary> SimPrims = new Dictionary>(); + + public bool Running = true; + + string contactPerson = ""; + StartPosition startpos = new StartPosition(); + + /// + /// + /// + /// + public ClientManager(List accounts, string c) + { + this.contactPerson = c; + foreach (LoginDetails account in accounts) + Login(account); + } + + public ClientManager(List accounts, string c, string s) + { + this.contactPerson = c; + char sep = '/'; + string[] startbits = s.Split(sep); + this.startpos.sim = startbits[0]; + this.startpos.x = int.Parse(startbits[1]); + this.startpos.y = int.Parse(startbits[2]); + this.startpos.z = int.Parse(startbits[3]); + foreach (LoginDetails account in accounts) + Login(account); + } + /// + /// + /// + /// + /// + public TestClient Login(LoginDetails account) + { + // Check if this client is already logged in + foreach (TestClient c in Clients.Values) + { + if (c.Self.FirstName == account.FirstName && c.Self.LastName == account.LastName) + { + Logout(c); + break; + } + } + + TestClient client = new TestClient(this); + + client.SimPrims = SimPrims; + client.Master = account.Master; + + bool check = false; + if ( this.startpos.sim != null ) { + if ( this.startpos.x == 0 || this.startpos.y == 0 || this.startpos.z == 0 ) { + this.startpos.x = 128; + this.startpos.y = 128; + this.startpos.z = 1; + } + string startLoc = NetworkManager.StartLocation(this.startpos.sim, this.startpos.x, this.startpos.y, this.startpos.z); + Console.WriteLine(startLoc); + client.Network.Login(account.FirstName, account.LastName, account.Password, "TestClient", startLoc, contactPerson, false); + } else { + client.Network.Login(account.FirstName, account.LastName, account.Password, "TestClient", contactPerson); + } + if ( ! check ) { + Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " + client.Network.LoginError); + } + + if (client.Network.Connected) + { + Clients[client.Network.AgentID] = client; + + Console.WriteLine("Logged in " + client.ToString()); + + // Throttle the connection to not receive LayerData or asset packets + client.Throttle.Total = 0.0f; + client.Throttle.Task = 1536000.0f; + client.Throttle.Set(); + } + + return client; + } + + /// + /// + /// + /// + /// + public TestClient Login(string[] args) + { + LoginDetails account = new LoginDetails(); + account.FirstName = args[0]; + account.LastName = args[1]; + account.Password = args[2]; + + return Login(account); + } + + /// + /// + /// + public void Run() + { + Console.WriteLine("Type quit to exit. Type help for a command list."); + + while (Running) + { + PrintPrompt(); + string input = Console.ReadLine(); + DoCommandAll(input, null, null); + } + + foreach (SecondLife client in Clients.Values) + { + if (client.Network.Connected) + client.Network.Logout(); + } + } + + private void PrintPrompt() + { + int online = 0; + + foreach (SecondLife client in Clients.Values) + { + if (client.Network.Connected) online++; + } + + Console.Write(online + " avatars online> "); + } + + /// + /// + /// + /// + /// + /// + public void DoCommandAll(string cmd, LLUUID fromAgentID, LLUUID imSessionID) + { + string[] tokens = cmd.Trim().Split(new char[] { ' ', '\t' }); + string firstToken = tokens[0].ToLower(); + + if (tokens.Length == 0) + return; + + 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); + Login(args); + } + else if (firstToken == "quit") + { + Quit(); + Console.WriteLine("All clients logged out and program finished running."); + } + else + { + // 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) + client.DoCommand(cmd, fromAgentID, imSessionID); + } + } + + /// + /// + /// + /// + public void Logout(TestClient client) + { + Clients.Remove(client.Network.AgentID); + 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/libsecondlife-cs/examples/TestClient/Program.cs b/libsecondlife-cs/examples/TestClient/Program.cs index 66407768..d3b8a890 100644 --- a/libsecondlife-cs/examples/TestClient/Program.cs +++ b/libsecondlife-cs/examples/TestClient/Program.cs @@ -1,109 +1,124 @@ -using System; -using System.Collections.Generic; -using System.IO; -using CommandLine.Utility; - -namespace libsecondlife.TestClient -{ - public class Program - { - private static void Usage() - { - Console.WriteLine("Usage: " + Environment.NewLine + - "TestClient.exe --first firstname --last lastname --pass password [--master \"master name\"]" + - Environment.NewLine + "TestClient.exe --file filename [--master \"master name\"]"); - } - - static void Main(string[] args) - { - Arguments arguments = new Arguments(args); - - ClientManager manager; - List accounts = new List(); - LoginDetails account; - string master = ""; - string file = ""; - - if (arguments["master"] != null) - { - master = arguments["master"]; - } - - if (arguments["file"] != null) - { - file = arguments["file"]; - - // Loading names from a file - try - { - using (StreamReader reader = new StreamReader(file)) - { - string line; - int lineNumber = 0; - - while ((line = reader.ReadLine()) != null) - { - lineNumber++; - string[] tokens = line.Trim().Split(new char[] { ' ', ',' }); - - 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"); - } - } - } - } - 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) - { - // 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 - { - Usage(); - return; - } - } - - foreach (LoginDetails a in accounts) - a.Master = master; - - // Login the accounts and run the input loop - manager = new ClientManager(accounts); - manager.Run(); - } - } -} +using System; +using System.Collections.Generic; +using System.IO; +using CommandLine.Utility; + +namespace libsecondlife.TestClient +{ + public class Program + { + private static void Usage() + { + Console.WriteLine("Usage: " + Environment.NewLine + + "TestClient.exe --first firstname --last lastname --pass password --contact \"youremail\" [--startpos \"sim/x/y/z\"] [--master \"master name\"]" + + Environment.NewLine + "TestClient.exe --file filename --contact \"youremail\" [--master \"master name\"]"); + } + + static void Main(string[] args) + { + Arguments arguments = new Arguments(args); + + ClientManager manager; + List accounts = new List(); + LoginDetails account; + string master = ""; + string file = ""; + string startpos = ""; + string contact = ""; + + if (arguments["master"] != null) + { + master = arguments["master"]; + } + + if ( arguments["start"] != null) + { + startpos = arguments["start"]; + } + if (arguments["contact"] != null) + { + contact = arguments["contact"]; + if (arguments["file"] != null) + { + file = arguments["file"]; + + // Loading names from a file + try + { + using (StreamReader reader = new StreamReader(file)) + { + string line; + int lineNumber = 0; + + while ((line = reader.ReadLine()) != null) + { + lineNumber++; + string[] tokens = line.Trim().Split(new char[] { ' ', ',' }); + + 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"); + } + } + } + } + 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) + { + // 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 + { + Usage(); + return; + } + + foreach (LoginDetails a in accounts) + a.Master = master; + + // Login the accounts and run the input loop + if ( startpos != null ) { + manager = new ClientManager(accounts, contact, startpos); + } else { + manager = new ClientManager(accounts, contact); + } + manager.Run(); + + } + } +}