* Replacing hacky ClientManagerRef in TestClient with a proper singleton implementation of ClientManager
* Use BeginLogin in TestClient to try out asynchronous logins (this is experimental and may very likely break things, hooray for trunk) git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@2715 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
@@ -36,35 +36,82 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
}
|
||||
|
||||
// WOW WHAT A HACK!
|
||||
public static class ClientManagerRef
|
||||
public sealed class ClientManager
|
||||
{
|
||||
public static ClientManager ClientManager;
|
||||
}
|
||||
const string VERSION = "1.0.0";
|
||||
|
||||
class Singleton { internal static readonly ClientManager Instance = new ClientManager(); }
|
||||
public static ClientManager Instance { get { return Singleton.Instance; } }
|
||||
|
||||
public class ClientManager
|
||||
{
|
||||
public Dictionary<UUID, TestClient> Clients = new Dictionary<UUID, TestClient>();
|
||||
public Dictionary<Simulator, Dictionary<uint, Primitive>> SimPrims = new Dictionary<Simulator, Dictionary<uint, Primitive>>();
|
||||
|
||||
public bool Running = true;
|
||||
public bool GetTextures = false;
|
||||
|
||||
string version = "1.0.0";
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="accounts"></param>
|
||||
public ClientManager(List<LoginDetails> accounts, bool getTextures)
|
||||
ClientManager()
|
||||
{
|
||||
ClientManagerRef.ClientManager = this;
|
||||
}
|
||||
|
||||
public void Start(List<LoginDetails> accounts, bool getTextures)
|
||||
{
|
||||
GetTextures = getTextures;
|
||||
|
||||
foreach (LoginDetails account in accounts)
|
||||
Login(account);
|
||||
}
|
||||
|
||||
public TestClient Login(string[] args)
|
||||
{
|
||||
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Usage: login firstname lastname password [simname] [login server url]");
|
||||
return null;
|
||||
}
|
||||
LoginDetails account = new LoginDetails();
|
||||
account.FirstName = args[0];
|
||||
account.LastName = args[1];
|
||||
account.Password = args[2];
|
||||
|
||||
if (args.Length > 3)
|
||||
{
|
||||
// If it looks like a full starting position was specified, parse it
|
||||
if (args[3].StartsWith("http"))
|
||||
{
|
||||
account.URI = args[3];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args[3].IndexOf('/') >= 0)
|
||||
{
|
||||
char sep = '/';
|
||||
string[] startbits = args[3].Split(sep);
|
||||
try
|
||||
{
|
||||
account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]),
|
||||
Int32.Parse(startbits[2]), Int32.Parse(startbits[3]));
|
||||
}
|
||||
catch (FormatException) { }
|
||||
}
|
||||
|
||||
// Otherwise, use the center of the named region
|
||||
if (account.StartLocation == null)
|
||||
account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40);
|
||||
}
|
||||
}
|
||||
|
||||
if (args.Length > 4)
|
||||
if (args[4].StartsWith("http"))
|
||||
account.URI = args[4];
|
||||
|
||||
if (string.IsNullOrEmpty(account.URI))
|
||||
account.URI = Program.LoginURI;
|
||||
Logger.Log("Using login URI " + account.URI, Helpers.LogLevel.Info);
|
||||
|
||||
return Login(account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
@@ -83,6 +130,47 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
|
||||
TestClient client = new TestClient(this);
|
||||
client.Network.OnLogin +=
|
||||
delegate(LoginStatus login, string message)
|
||||
{
|
||||
Logger.Log(String.Format("Login {0}: {1}", login, message), Helpers.LogLevel.Info, client);
|
||||
|
||||
if (login == LoginStatus.Success)
|
||||
{
|
||||
Clients[client.Self.AgentID] = client;
|
||||
|
||||
if (client.MasterKey == UUID.Zero)
|
||||
{
|
||||
UUID query = UUID.Random();
|
||||
DirectoryManager.DirPeopleReplyCallback peopleDirCallback =
|
||||
delegate(UUID queryID, List<DirectoryManager.AgentSearchData> matchedPeople)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Logger.Log("Logged in " + client.ToString(), Helpers.LogLevel.Info);
|
||||
}
|
||||
else if (login == LoginStatus.Failed)
|
||||
{
|
||||
Logger.Log("Failed to login " + account.FirstName + " " + account.LastName + ": " +
|
||||
client.Network.LoginMessage, Helpers.LogLevel.Warning);
|
||||
}
|
||||
};
|
||||
|
||||
// Optimize the throttle
|
||||
client.Throttle.Wind = 0;
|
||||
@@ -96,97 +184,18 @@ namespace OpenMetaverse.TestClient
|
||||
client.AllowObjectMaster = client.MasterKey != UUID.Zero; // Require UUID for object master.
|
||||
|
||||
LoginParams loginParams = client.Network.DefaultLoginParams(
|
||||
account.FirstName, account.LastName, account.Password, "TestClient", version);
|
||||
account.FirstName, account.LastName, account.Password, "TestClient", VERSION);
|
||||
|
||||
if (!String.IsNullOrEmpty(account.StartLocation))
|
||||
loginParams.Start = account.StartLocation;
|
||||
|
||||
if (!String.IsNullOrEmpty(account.URI))
|
||||
loginParams.URI = account.URI;
|
||||
|
||||
if (client.Network.Login(loginParams))
|
||||
{
|
||||
Clients[client.Self.AgentID] = client;
|
||||
|
||||
if (client.MasterKey == UUID.Zero)
|
||||
{
|
||||
UUID query = UUID.Random();
|
||||
DirectoryManager.DirPeopleReplyCallback peopleDirCallback =
|
||||
delegate(UUID queryID, List<DirectoryManager.AgentSearchData> matchedPeople)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
Logger.Log("Logged in " + client.ToString(), Helpers.LogLevel.Info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Log("Failed to login " + account.FirstName + " " + account.LastName + ": " +
|
||||
client.Network.LoginMessage, Helpers.LogLevel.Warning);
|
||||
}
|
||||
|
||||
client.Network.BeginLogin(loginParams);
|
||||
return client;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public TestClient Login(string[] args)
|
||||
{
|
||||
|
||||
if (args.Length < 3)
|
||||
{
|
||||
Console.WriteLine("Usage: login firstname lastname password [simname] [login server url]");
|
||||
return null;
|
||||
}
|
||||
LoginDetails account = new LoginDetails();
|
||||
account.FirstName = args[0];
|
||||
account.LastName = args[1];
|
||||
account.Password = args[2];
|
||||
|
||||
if (args.Length > 3)
|
||||
{
|
||||
// If it looks like a full starting position was specified, parse it
|
||||
if( args[3].IndexOf('/') >= 0 )
|
||||
{
|
||||
char sep = '/';
|
||||
string[] startbits = args[3].Split(sep);
|
||||
account.StartLocation = NetworkManager.StartLocation(startbits[0], Int32.Parse(startbits[1]),
|
||||
Int32.Parse(startbits[2]), Int32.Parse(startbits[3]));
|
||||
}
|
||||
// Otherwise, use the center of the named region
|
||||
else
|
||||
account.StartLocation = NetworkManager.StartLocation(args[3], 128, 128, 40);
|
||||
}
|
||||
|
||||
if (args.Length > 4)
|
||||
if(args[4].StartsWith("http://"))
|
||||
account.URI = args[4];
|
||||
|
||||
if (string.IsNullOrEmpty(account.URI))
|
||||
account.URI = Program.LoginURI;
|
||||
Logger.Log("Using login URI " + account.URI, Helpers.LogLevel.Info);
|
||||
|
||||
return Login(account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user