Cleanup TestClient.ClientManager
This commit is contained in:
@@ -1,3 +1,30 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2016, openmetaverse.co
|
||||
* Copyright (c) 2019-2022, Sjofn, LLC
|
||||
* All rights reserved.
|
||||
*
|
||||
* - Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* - Neither the name of the openmetaverse.co nor the names
|
||||
* of its contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@@ -59,6 +86,11 @@ namespace OpenMetaverse.TestClient
|
||||
Login(account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Login command with required args
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
public TestClient Login(string[] args)
|
||||
{
|
||||
if (args.Length < 3)
|
||||
@@ -107,11 +139,16 @@ namespace OpenMetaverse.TestClient
|
||||
|
||||
if (string.IsNullOrEmpty(account.URI))
|
||||
account.URI = Program.LoginURI;
|
||||
Logger.Log("Using login URI " + account.URI, Helpers.LogLevel.Info);
|
||||
Logger.Log($"Using login URI {account.URI}", Helpers.LogLevel.Info);
|
||||
|
||||
return Login(account);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Login account with provided <seealso cref="LoginDetails"/>
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <returns></returns>
|
||||
public TestClient Login(LoginDetails account)
|
||||
{
|
||||
// Check if this client is already logged in
|
||||
@@ -146,12 +183,12 @@ namespace OpenMetaverse.TestClient
|
||||
{
|
||||
if (dpe.MatchedPeople.Count != 1)
|
||||
{
|
||||
Logger.Log("Unable to resolve master key from " + client.MasterName, Helpers.LogLevel.Warning);
|
||||
Logger.Log($"Unable to resolve master key from {client.MasterName}", Helpers.LogLevel.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
client.MasterKey = dpe.MatchedPeople[0].AgentID;
|
||||
Logger.Log("Master key resolved to " + client.MasterKey, Helpers.LogLevel.Info);
|
||||
Logger.Log($"Master key resolved to {client.MasterKey}", Helpers.LogLevel.Info);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -160,13 +197,13 @@ namespace OpenMetaverse.TestClient
|
||||
query = client.Directory.StartPeopleSearch(client.MasterName, 0);
|
||||
}
|
||||
|
||||
Logger.Log("Logged in " + client.ToString(), Helpers.LogLevel.Info);
|
||||
Logger.Log($"Logged in {client}", Helpers.LogLevel.Info);
|
||||
--PendingLogins;
|
||||
}
|
||||
else if (e.Status == LoginStatus.Failed)
|
||||
{
|
||||
Logger.Log("Failed to login " + account.FirstName + " " + account.LastName + ": " +
|
||||
client.Network.LoginMessage, Helpers.LogLevel.Warning);
|
||||
Logger.Log($"Failed to login {account.FirstName} {account.LastName}: {client.Network.LoginMessage}",
|
||||
Helpers.LogLevel.Warning);
|
||||
--PendingLogins;
|
||||
}
|
||||
};
|
||||
@@ -185,10 +222,10 @@ namespace OpenMetaverse.TestClient
|
||||
LoginParams loginParams = client.Network.DefaultLoginParams(
|
||||
account.FirstName, account.LastName, account.Password, "TestClient", VERSION);
|
||||
|
||||
if (!String.IsNullOrEmpty(account.StartLocation))
|
||||
if (!string.IsNullOrEmpty(account.StartLocation))
|
||||
loginParams.Start = account.StartLocation;
|
||||
|
||||
if (!String.IsNullOrEmpty(account.URI))
|
||||
if (!string.IsNullOrEmpty(account.URI))
|
||||
loginParams.URI = account.URI;
|
||||
|
||||
client.Network.BeginLogin(loginParams);
|
||||
@@ -196,8 +233,9 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Begin running client
|
||||
/// </summary>
|
||||
/// <param name="noGUI">Run with Gui or nah</param>
|
||||
public void Run(bool noGUI)
|
||||
{
|
||||
if (noGUI)
|
||||
@@ -225,6 +263,9 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Print GUI prompt to screen
|
||||
/// </summary>
|
||||
private void PrintPrompt()
|
||||
{
|
||||
int online = 0;
|
||||
@@ -234,7 +275,7 @@ namespace OpenMetaverse.TestClient
|
||||
if (client.Network.Connected) online++;
|
||||
}
|
||||
|
||||
Console.Write(online + " avatars online> ");
|
||||
Console.Write($"{online} avatars online> ");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -252,7 +293,7 @@ namespace OpenMetaverse.TestClient
|
||||
return;
|
||||
|
||||
string firstToken = tokens[0].ToLower();
|
||||
if (String.IsNullOrEmpty(firstToken))
|
||||
if (string.IsNullOrEmpty(firstToken))
|
||||
return;
|
||||
|
||||
// Allow for comments when cmdline begins with ';' or '#'
|
||||
@@ -271,9 +312,9 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
Logger.Log("Commanding only "+onlyAvatar+" now", Helpers.LogLevel.Info);
|
||||
Logger.Log($"Commanding only {onlyAvatar} now", Helpers.LogLevel.Info);
|
||||
} else {
|
||||
Logger.Log("Commanding nobody now. Avatar "+onlyAvatar+" is offline", Helpers.LogLevel.Info);
|
||||
Logger.Log($"Commanding nobody now. Avatar {onlyAvatar} is offline", Helpers.LogLevel.Info);
|
||||
}
|
||||
} else {
|
||||
Logger.Log("Commanding all avatars now", Helpers.LogLevel.Info);
|
||||
@@ -337,11 +378,11 @@ namespace OpenMetaverse.TestClient
|
||||
|
||||
foreach (TestClient client in clientsCopy.Values)
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem((WaitCallback)
|
||||
ThreadPool.QueueUserWorkItem(
|
||||
delegate(object state)
|
||||
{
|
||||
TestClient testClient = (TestClient)state;
|
||||
if ((String.Empty == onlyAvatar) || (testClient.ToString() == onlyAvatar)) {
|
||||
if ((string.Empty == onlyAvatar) || (testClient.ToString() == onlyAvatar)) {
|
||||
if (testClient.Commands.ContainsKey(firstToken)) {
|
||||
string result;
|
||||
try {
|
||||
@@ -353,7 +394,7 @@ namespace OpenMetaverse.TestClient
|
||||
testClient);
|
||||
}
|
||||
} else
|
||||
Logger.Log("Unknown command " + firstToken, Helpers.LogLevel.Warning);
|
||||
Logger.Log($"Unknown command {firstToken}", Helpers.LogLevel.Warning);
|
||||
}
|
||||
|
||||
++completed;
|
||||
@@ -367,9 +408,9 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Logout specified <seealso cref="TestClient"/> instance
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="client">Client to perform logout</param>
|
||||
public void Logout(TestClient client)
|
||||
{
|
||||
Clients.Remove(client.Self.AgentID);
|
||||
@@ -377,7 +418,7 @@ namespace OpenMetaverse.TestClient
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Exit the program
|
||||
/// </summary>
|
||||
public void Quit()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user