2007-04-28 20:54:02 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
using System.Threading;
|
2008-07-21 21:12:59 +00:00
|
|
|
using OpenMetaverse;
|
|
|
|
|
using OpenMetaverse.Packets;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
namespace OpenMetaverse.TestClient
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
public class LoginDetails
|
|
|
|
|
{
|
|
|
|
|
public string FirstName;
|
|
|
|
|
public string LastName;
|
|
|
|
|
public string Password;
|
|
|
|
|
public string StartLocation;
|
2008-02-07 17:32:06 +00:00
|
|
|
public bool GroupCommands;
|
2007-04-28 20:54:02 +00:00
|
|
|
public string MasterName;
|
|
|
|
|
public LLUUID MasterKey;
|
2007-07-11 09:17:46 +00:00
|
|
|
public string URI;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2008-07-21 21:12:59 +00:00
|
|
|
public Dictionary<LLUUID, GridClient> Clients = new Dictionary<LLUUID, GridClient>();
|
2007-04-28 20:54:02 +00:00
|
|
|
public Dictionary<Simulator, Dictionary<uint, Primitive>> SimPrims = new Dictionary<Simulator, Dictionary<uint, Primitive>>();
|
|
|
|
|
|
|
|
|
|
public bool Running = true;
|
|
|
|
|
|
2007-12-21 02:25:36 +00:00
|
|
|
string version = "1.0.0";
|
2007-04-28 20:54:02 +00:00
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="accounts"></param>
|
2007-12-21 02:25:36 +00:00
|
|
|
public ClientManager(List<LoginDetails> accounts)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
foreach (LoginDetails account in accounts)
|
|
|
|
|
Login(account);
|
|
|
|
|
}
|
|
|
|
|
|
2007-12-21 02:25:36 +00:00
|
|
|
public ClientManager(List<LoginDetails> accounts, string s)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
char sep = '/';
|
|
|
|
|
string[] startbits = s.Split(sep);
|
|
|
|
|
|
|
|
|
|
foreach (LoginDetails account in accounts)
|
|
|
|
|
{
|
|
|
|
|
account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]),
|
|
|
|
|
Int32.Parse(startbits[2]), Int32.Parse(startbits[3]));
|
|
|
|
|
Login(account);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="account"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
// Optimize the throttle
|
|
|
|
|
client.Throttle.Wind = 0;
|
|
|
|
|
client.Throttle.Cloud = 0;
|
|
|
|
|
client.Throttle.Land = 1000000;
|
|
|
|
|
client.Throttle.Task = 1000000;
|
|
|
|
|
|
2008-02-07 17:32:06 +00:00
|
|
|
client.GroupCommands = account.GroupCommands;
|
2007-04-28 20:54:02 +00:00
|
|
|
client.MasterName = account.MasterName;
|
|
|
|
|
client.MasterKey = account.MasterKey;
|
|
|
|
|
|
2007-12-21 02:25:36 +00:00
|
|
|
LoginParams loginParams = client.Network.DefaultLoginParams(
|
|
|
|
|
account.FirstName, account.LastName, account.Password, "TestClient", version);
|
2007-07-11 09:17:46 +00:00
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(account.StartLocation))
|
|
|
|
|
loginParams.Start = account.StartLocation;
|
|
|
|
|
|
|
|
|
|
if (!String.IsNullOrEmpty(account.URI))
|
|
|
|
|
loginParams.URI = account.URI;
|
|
|
|
|
|
2008-01-10 23:40:13 +00:00
|
|
|
if (client.Network.Login(loginParams))
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
if (account.MasterKey == LLUUID.Zero && !String.IsNullOrEmpty(account.MasterName))
|
|
|
|
|
{
|
2008-03-31 04:29:12 +00:00
|
|
|
// To prevent security issues, we must resolve the specified master name to a key.
|
|
|
|
|
ManualResetEvent keyResolution = new ManualResetEvent(false);
|
|
|
|
|
List<DirectoryManager.AgentSearchData> masterMatches = new List<DirectoryManager.AgentSearchData>();
|
|
|
|
|
|
|
|
|
|
// Set up the callback that handles the search results:
|
|
|
|
|
DirectoryManager.DirPeopleReplyCallback callback =
|
|
|
|
|
delegate (LLUUID queryID, List<DirectoryManager.AgentSearchData> matches) {
|
|
|
|
|
// This may be called several times with additional search results.
|
|
|
|
|
if (matches.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
lock (masterMatches)
|
|
|
|
|
{
|
|
|
|
|
masterMatches.AddRange(matches);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// No results to show.
|
|
|
|
|
keyResolution.Set();
|
|
|
|
|
}
|
|
|
|
|
};
|
2007-04-28 20:54:02 +00:00
|
|
|
// Find master's key from name
|
2008-03-31 04:29:12 +00:00
|
|
|
Console.WriteLine("Resolving {0}'s UUID", account.MasterName);
|
2007-04-28 20:54:02 +00:00
|
|
|
client.Directory.OnDirPeopleReply += callback;
|
2007-05-14 10:18:54 +00:00
|
|
|
client.Directory.StartPeopleSearch(DirectoryManager.DirFindFlags.People, account.MasterName, 0);
|
2008-03-31 04:29:12 +00:00
|
|
|
keyResolution.WaitOne(TimeSpan.FromSeconds(30), false);
|
|
|
|
|
client.Directory.OnDirPeopleReply -= callback;
|
|
|
|
|
|
|
|
|
|
LLUUID masterKey = LLUUID.Zero;
|
|
|
|
|
string masterName = account.MasterName;
|
|
|
|
|
lock (masterMatches) {
|
|
|
|
|
if (masterMatches.Count == 1) {
|
|
|
|
|
masterKey = masterMatches[0].AgentID;
|
|
|
|
|
masterName = masterMatches[0].FirstName + " " + masterMatches[0].LastName;
|
|
|
|
|
} else if (masterMatches.Count > 0) {
|
|
|
|
|
// Print out numbered list of masters:
|
|
|
|
|
Console.WriteLine("Possible masters:");
|
|
|
|
|
for (int i = 0; i < masterMatches.Count; ++i)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("{0}: {1}", i, masterMatches[i].FirstName + " " + masterMatches[i].LastName);
|
|
|
|
|
}
|
|
|
|
|
Console.Write("Ambiguous master, choose one: ");
|
|
|
|
|
// Read number from the console:
|
|
|
|
|
string read = null;
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
read = Console.ReadLine();
|
|
|
|
|
int choice = 0;
|
|
|
|
|
if (int.TryParse(read, out choice))
|
|
|
|
|
{
|
|
|
|
|
if (choice == -1)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else if (choice < masterMatches.Count)
|
|
|
|
|
{
|
|
|
|
|
masterKey = masterMatches[choice].AgentID;
|
|
|
|
|
masterName = masterMatches[choice].FirstName + " " + masterMatches[choice].LastName;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Please type a number from the above list, -1 to cancel.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("You didn't type a number.");
|
|
|
|
|
Console.WriteLine("Please type a number from the above list, -1 to cancel.");
|
|
|
|
|
}
|
|
|
|
|
} while (read != null); // Do it until the user selects a master.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (masterKey != LLUUID.Zero)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
2008-03-31 04:29:12 +00:00
|
|
|
Console.WriteLine("\"{0}\" resolved to {1} ({2})", account.MasterName, masterName, masterKey);
|
|
|
|
|
account.MasterName = masterName;
|
|
|
|
|
account.MasterKey = masterKey;
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Unable to obtain UUID for \"{0}\". No master will be used. Try specifying a key with --masterkey.", account.MasterName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client.MasterKey = account.MasterKey;
|
2007-11-06 09:26:10 +00:00
|
|
|
Clients[client.Self.AgentID] = client;
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
Console.WriteLine("Logged in " + client.ToString());
|
|
|
|
|
}
|
2008-01-10 23:40:13 +00:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Failed to login " + account.FirstName + " " + account.LastName + ": " +
|
|
|
|
|
client.Network.LoginMessage);
|
|
|
|
|
}
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public TestClient Login(string[] args)
|
|
|
|
|
{
|
|
|
|
|
LoginDetails account = new LoginDetails();
|
|
|
|
|
account.FirstName = args[0];
|
|
|
|
|
account.LastName = args[1];
|
|
|
|
|
account.Password = args[2];
|
|
|
|
|
|
|
|
|
|
if (args.Length == 4)
|
|
|
|
|
{
|
|
|
|
|
account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Login(account);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Run()
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Type quit to exit. Type help for a command list.");
|
|
|
|
|
|
|
|
|
|
while (Running)
|
|
|
|
|
{
|
|
|
|
|
PrintPrompt();
|
|
|
|
|
string input = Console.ReadLine();
|
2007-12-21 05:31:13 +00:00
|
|
|
DoCommandAll(input, LLUUID.Zero);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
foreach (GridClient client in Clients.Values)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
if (client.Network.Connected)
|
|
|
|
|
client.Network.Logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PrintPrompt()
|
|
|
|
|
{
|
|
|
|
|
int online = 0;
|
|
|
|
|
|
2008-07-21 21:12:59 +00:00
|
|
|
foreach (GridClient client in Clients.Values)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
if (client.Network.Connected) online++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.Write(online + " avatars online> ");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cmd"></param>
|
|
|
|
|
/// <param name="fromAgentID"></param>
|
|
|
|
|
/// <param name="imSessionID"></param>
|
2007-12-21 05:31:13 +00:00
|
|
|
public void DoCommandAll(string cmd, LLUUID fromAgentID)
|
2007-04-28 20:54:02 +00:00
|
|
|
{
|
|
|
|
|
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
|
2008-07-21 21:12:59 +00:00
|
|
|
Dictionary<LLUUID, GridClient> clientsCopy = new Dictionary<LLUUID, GridClient>(Clients);
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
foreach (TestClient client in clientsCopy.Values)
|
2007-12-21 05:31:13 +00:00
|
|
|
client.DoCommand(cmd, fromAgentID);
|
2007-04-28 20:54:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
public void Logout(TestClient client)
|
|
|
|
|
{
|
2007-11-06 09:26:10 +00:00
|
|
|
Clients.Remove(client.Self.AgentID);
|
2007-04-28 20:54:02 +00:00
|
|
|
client.Network.Logout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void LogoutAll()
|
|
|
|
|
{
|
|
|
|
|
// make a copy of the clients list so that it can be iterated without fear of being changed during iteration
|
2008-07-21 21:12:59 +00:00
|
|
|
Dictionary<LLUUID, GridClient> clientsCopy = new Dictionary<LLUUID, GridClient>(Clients);
|
2007-04-28 20:54:02 +00:00
|
|
|
|
|
|
|
|
foreach (TestClient client in clientsCopy.Values)
|
|
|
|
|
Logout(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
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.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|