Begining major rework of Asset/Inventory code. Doing a lot of refectoing. What's in here so far?

+ Inventory, Asset and Image managers are now directly apart of the SecondLife class
+ Root Inventory folder has been added to MainAvatar and is set upon login
+ Inventory is no longer downloaded all at once, you have to request the download of individual folders
+ Folder downloading is available Asynchronously, and returns a object that has a ManualResetEvent that you can use to optionally block with
+ The code for AssetManager has been reworked some in prep for allowing Wearables to be Saved/Loaded to/from disk, and for creating new wearables.


git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@742 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Michael Cortez
2006-12-19 23:13:04 +00:00
parent df1ac0424f
commit b686cebf3d
17 changed files with 835 additions and 439 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using IA_SimpleInventory;
@@ -13,8 +14,12 @@ namespace IA_ImageTool
/// <summary>
/// Summary description for Class1.
/// </summary>
class ImageTool : SimpleInventory
class ImageTool
{
private SecondLife _Client;
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
private List<LLUUID> _ImageIDs = new List<LLUUID>();
private string _FileName;
private bool _Put;
@@ -24,7 +29,7 @@ namespace IA_ImageTool
/// Used to upload/download images.
/// </summary>
[STAThread]
static new void Main(string[] args)
static void Main(string[] args)
{
if ( (File.Exists("libjasper.dll") == false) )
{
@@ -94,17 +99,16 @@ namespace IA_ImageTool
ImageTool it = new ImageTool(uuidList, filename, put, rate);
// Only download the inventory tree if we're planning on putting/uploading files.
it.DownloadInventoryOnConnect = put;
if (it.Connect(args[0], args[1], args[2]))
{
it.doStuff();
it.Disconnect();
if (it.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
it.doStuff();
System.Threading.Thread.Sleep(500);
it.Disconnect();
}
Console.WriteLine("Done logging out.");
}
}
@@ -114,12 +118,62 @@ namespace IA_ImageTool
_FileName = filename;
_Put = put;
_Rate = rate;
try
{
_Client = new SecondLife();
_Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
}
catch (Exception e)
{
// Error initializing the client
Console.WriteLine();
Console.WriteLine(e.ToString());
}
}
protected new void doStuff()
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
// Setup Login to Second Life
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!_Client.Network.Login(FirstName, LastName, Password, "ImageTool", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + _Client.Network.LoginError);
return false;
}
// Login was successful
Console.WriteLine("Login was successful.");
Console.WriteLine("AgentID: " + _Client.Network.AgentID);
Console.WriteLine("SessionID: " + _Client.Network.SessionID);
return true;
}
protected void Disconnect()
{
// Logout of Second Life
Console.WriteLine("Request logout");
_Client.Network.Logout();
}
protected void doStuff()
{
if (_Put)
{
Console.WriteLine("Reading: " + _FileName);
byte[] j2cdata;
@@ -135,7 +189,7 @@ namespace IA_ImageTool
Console.WriteLine("Connecting to your Texture folder...");
InventoryFolder iFolder = AgentInventory.getFolder("Textures");
InventoryFolder iFolder = _Client.Inventory.getFolder("Textures");
Console.WriteLine("Uploading Texture...");
InventoryImage image = iFolder.NewImage(_FileName, "ImageTool Upload", j2cdata);
@@ -162,7 +216,7 @@ namespace IA_ImageTool
try
{
j2cdata = client.Images.RequestImage(ImageID);
j2cdata = _Client.Images.RequestImage(ImageID);
int end = Environment.TickCount;
Console.WriteLine("Elapsed download time, in TickCounts: " + (end - start));

View File

@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Serialization;
@@ -23,7 +25,7 @@ namespace IA_InventoryManager
/// * MOVE
/// * GIVE
/// </summary>
class iManager : SimpleInventory
class iManager
{
private char[] cmdSeperators = { ' ' };
private string curDirectory = "/";
@@ -31,9 +33,12 @@ namespace IA_InventoryManager
private string TYPE_DIR = "<DIR> ";
private string TYPE_ITEM = "<ITEM> ";
private SecondLife _Client;
private AppearanceManager aManager;
static new void Main(string[] args)
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
static void Main(string[] args)
{
if (args.Length < 3)
{
@@ -42,18 +47,35 @@ namespace IA_InventoryManager
}
iManager it = new iManager();
it.Connect(args[0], args[1], args[2]);
it.doStuff();
it.Disconnect();
if (it.Connect(args[0], args[1], args[2]))
{
if (it.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
it.doStuff();
it.Disconnect();
}
}
}
System.Threading.Thread.Sleep(1000);
public iManager()
{
try
{
_Client = new SecondLife();
_Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
_Client.Self.OnTeleport += new TeleportCallback(Self_OnTeleport);
}
catch (Exception e)
{
// Error initializing the client
Console.WriteLine();
Console.WriteLine(e.ToString());
}
}
private new void doStuff()
private void doStuff()
{
client.Self.OnTeleport += new TeleportCallback(Self_OnTeleport);
System.Threading.Thread.Sleep(1000);
Console.WriteLine("==================================================================");
@@ -164,6 +186,17 @@ namespace IA_InventoryManager
getlook();
break;
case "saveav":
saveavatar(curCmdLine);
break;
case "savew":
savewearables(curCmdLine);
break;
case "loadw":
loadwearables(curCmdLine);
break;
default:
Console.WriteLine("Unknown command '" + curCmdLine[0] + "'.");
@@ -192,10 +225,144 @@ namespace IA_InventoryManager
Console.WriteLine("REGIONINFO - Display Grid Region Info.");
Console.WriteLine("TELEPORT - Teleport to a new sim.");
Console.WriteLine("NOTECARD - Create a new notecard.");
Console.WriteLine("XML - Display an item as xml");
Console.WriteLine("XML - Display an item as xml.");
Console.WriteLine("GETLOOK - Send an AgentSetAppearance based on your current weables.");
Console.WriteLine("SAVEAV - Serialize your current wearables and the info from them.");
Console.WriteLine("SAVEW - Serialize your current wearables.");
Console.WriteLine("LOADW - Load a previously serialized wearables.");
Console.WriteLine("QUIT - Exit the Inventory Manager.");
}
private void savewearables(string[] cmdLine)
{
if (aManager == null)
{
aManager = new AppearanceManager(_Client);
}
// Get Wearable Data
AgentWearablesUpdatePacket.WearableDataBlock[] wdbs = aManager.GetWearables();
List<AgentWearablesUpdatePacket.WearableDataBlock> WearablesList = new List<AgentWearablesUpdatePacket.WearableDataBlock>();
foreach (AgentWearablesUpdatePacket.WearableDataBlock wdb in wdbs)
{
WearablesList.Add(wdb);
}
// Serialize to XML
StringBuilder sb = new StringBuilder();
XmlWriterSettings xmlws = new XmlWriterSettings();
xmlws.Indent = true;
XmlWriter xmlw = XmlWriter.Create(sb, xmlws);
XmlSerializer serializer = new XmlSerializer(typeof(List<AgentWearablesUpdatePacket.WearableDataBlock>));
serializer.Serialize(xmlw, WearablesList);
// Output
if (cmdLine.Length >= 2)
{
Console.WriteLine("Writing wearable data to : " + cmdLine[1]);
File.WriteAllText(cmdLine[1], sb.ToString());
Console.WriteLine("Done...");
}
else
{
Console.WriteLine(sb.ToString());
}
}
private void loadwearables(string[] cmdLine)
{
if (cmdLine.Length < 2)
{
Console.WriteLine("You must specify the file to load the wearables from.");
Console.WriteLine("Usage: loadw [file.xml]");
return;
}
Console.WriteLine("Reading Wearable data from: " + cmdLine[1]);
try
{
XmlReader xmlr = XmlReader.Create(File.OpenText(cmdLine[1]));
XmlSerializer serializer = new XmlSerializer(typeof(List<AgentWearablesUpdatePacket.WearableDataBlock>));
List<AgentWearablesUpdatePacket.WearableDataBlock> WearablesList = (List<AgentWearablesUpdatePacket.WearableDataBlock>)serializer.Deserialize(xmlr);
foreach (AgentWearablesUpdatePacket.WearableDataBlock wdb in WearablesList)
{
Console.WriteLine(wdb.AssetID);
}
}
catch (Exception e)
{
Console.WriteLine("An error has occured...");
Console.WriteLine(e.Message);
Console.WriteLine(e.StackTrace);
}
}
private void saveavatar(string[] cmdLine)
{
if (aManager == null)
{
aManager = new AppearanceManager(_Client);
}
AgentWearablesUpdatePacket.WearableDataBlock[] wdbs = aManager.GetWearables();
aManager.GetAvatarAppearanceInfoFromWearableAssets();
// Get the list of wearables
List<AgentWearablesUpdatePacket.WearableDataBlock> WearablesList = new List<AgentWearablesUpdatePacket.WearableDataBlock>();
foreach (AgentWearablesUpdatePacket.WearableDataBlock wdb in wdbs)
{
WearablesList.Add(wdb);
}
XmlWriterSettings xmlws = new XmlWriterSettings();
xmlws.OmitXmlDeclaration = true;
xmlws.Indent = true;
xmlws.CloseOutput = false;
StringBuilder Save = new StringBuilder();
Save.Append("<avatar_appearance>");
// Wearables
StringBuilder sb = new StringBuilder();
XmlWriter xmlw = XmlWriter.Create(sb, xmlws);
XmlSerializer serializer = new XmlSerializer(typeof(List<AgentWearablesUpdatePacket.WearableDataBlock>));
serializer.Serialize(xmlw, WearablesList);
Save.AppendLine(sb.ToString());
// Parameters
sb = new StringBuilder();
xmlw = XmlWriter.Create(sb, xmlws);
serializer = new XmlSerializer(typeof(SerializableDictionary<uint, float>));
serializer.Serialize(xmlw, aManager.AgentAppearanceParams);
Save.AppendLine(sb.ToString());
// Parameters
sb = new StringBuilder();
xmlw = XmlWriter.Create(sb, xmlws);
serializer = new XmlSerializer(typeof(TextureEntry));
serializer.Serialize(xmlw, aManager.AgentTextureEntry);
Save.AppendLine(sb.ToString());
// Finish off save data
Save.Append("</avatar_appearance>");
Console.WriteLine(Save.ToString());
//aManager.SendAgentSetAppearance
}
private void StandUpStraight()
{
AgentUpdatePacket p = new AgentUpdatePacket();
@@ -206,17 +373,17 @@ namespace IA_InventoryManager
p.AgentData.CameraUpAxis = new LLVector3(0, 0, 0);
p.AgentData.HeadRotation = new LLQuaternion(0, 0, 0, 1); ;
p.AgentData.BodyRotation = new LLQuaternion(0, 0, 0, 1); ;
p.AgentData.AgentID = client.Network.AgentID;
p.AgentData.SessionID = client.Network.SessionID;
p.AgentData.AgentID = _Client.Network.AgentID;
p.AgentData.SessionID = _Client.Network.SessionID;
p.AgentData.ControlFlags = (uint)Avatar.AgentUpdateFlags.AGENT_CONTROL_STAND_UP;
client.Network.SendPacket(p);
_Client.Network.SendPacket(p);
}
private void getlook()
{
if (aManager == null)
{
aManager = new AppearanceManager(client);
aManager = new AppearanceManager(_Client);
}
@@ -242,17 +409,20 @@ namespace IA_InventoryManager
{
}
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
InventoryFolder iFolder = _Client.Inventory.getFolder(curDirectory);
InventoryBase itemOfInterest = null;
foreach (InventoryBase ib in iFolder.alContents)
iFolder.BeginDownloadContents(false).RequestComplete.WaitOne(15000,false);
foreach (InventoryBase ib in iFolder.GetContents())
{
if (ib is InventoryFolder)
{
InventoryFolder folder = (InventoryFolder)ib;
if (folder.Name.Equals(cmdLine[1]) || folder.FolderID.Equals(uuid))
{
// Refresh the folder tree for this folder before outputing it.
folder.BeginDownloadContents(true).RequestComplete.WaitOne(30000, false);
itemOfInterest = folder;
break;
}
@@ -309,7 +479,7 @@ namespace IA_InventoryManager
sb.Append(cki.Key.ToString());
} while (cki.Key != ConsoleKey.Escape);
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
InventoryFolder iFolder = _Client.Inventory.getFolder(curDirectory);
iFolder.NewNotecard(cmdLine[1], NoteDesc, sb.ToString());
Console.WriteLine("Notecard '" + NoteName + " 'Created");
@@ -324,22 +494,22 @@ namespace IA_InventoryManager
return;
}
if (cmdLine[1].ToLower() == client.Network.CurrentSim.Region.Name.ToLower())
if (cmdLine[1].ToLower() == _Client.Network.CurrentSim.Region.Name.ToLower())
{
Console.WriteLine("TODO: Add the ability to teleport somewhere in the local region. " +
"Exiting for now, please specify a region other than the current one");
}
else
{
if (client.Grid.Regions.Count == 0)
if (_Client.Grid.Regions.Count == 0)
{
Console.WriteLine("Caching estate sims...");
client.Grid.AddEstateSims();
_Client.Grid.AddEstateSims();
System.Threading.Thread.Sleep(3000);
}
client.Self.Teleport(cmdLine[1], new LLVector3( float.Parse(cmdLine[2]), float.Parse(cmdLine[3]), float.Parse(cmdLine[4]) ) );
_Client.Self.Teleport(cmdLine[1], new LLVector3(float.Parse(cmdLine[2]), float.Parse(cmdLine[3]), float.Parse(cmdLine[4])));
}
}
@@ -360,7 +530,7 @@ namespace IA_InventoryManager
}
regionName = regionName.Trim();
GridRegion gr = client.Grid.GetGridRegion(regionName);
GridRegion gr = _Client.Grid.GetGridRegion(regionName);
Console.WriteLine(gr);
}
@@ -382,15 +552,17 @@ namespace IA_InventoryManager
// Arbitrary Asset
Asset asset = new Asset(cmdLine[2], sbyte.Parse(cmdLine[1]), null);
AgentInventory.getAssetManager().GetInventoryAsset(asset);
_Client.Assets.GetInventoryAsset(asset);
Console.WriteLine(asset.AssetDataToString());
}
else
{
// Asset for an item in inventory
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
foreach (InventoryBase ib in iFolder.alContents)
InventoryFolder iFolder = _Client.Inventory.getFolder(curDirectory);
iFolder.BeginDownloadContents(false).RequestComplete.WaitOne(15000, false);
foreach (InventoryBase ib in iFolder.GetContents())
{
if (ib is InventoryItem)
{
@@ -423,7 +595,7 @@ namespace IA_InventoryManager
}
targetDir += combineCmdArg(cmdLine);
InventoryFolder iFolder = AgentInventory.getFolder(targetDir);
InventoryFolder iFolder = _Client.Inventory.getFolder(targetDir);
if (iFolder == null)
{
Console.WriteLine("Could not find directory: " + targetDir);
@@ -446,7 +618,7 @@ namespace IA_InventoryManager
string targetDir = combineCmdArg(cmdLine);
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
InventoryFolder iFolder = _Client.Inventory.getFolder(curDirectory);
InventoryFolder newFolder = iFolder.CreateFolder(targetDir);
@@ -492,7 +664,7 @@ namespace IA_InventoryManager
Console.WriteLine("Changing directory to: " + targetDir );
InventoryFolder iFolder = AgentInventory.getFolder(targetDir);
InventoryFolder iFolder = _Client.Inventory.getFolder(targetDir);
if (iFolder == null)
{
@@ -521,8 +693,9 @@ namespace IA_InventoryManager
Console.WriteLine("..");
}
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
foreach (InventoryBase ib in iFolder.alContents)
InventoryFolder iFolder = _Client.Inventory.getFolder(curDirectory);
iFolder.BeginDownloadContents(false).RequestComplete.WaitOne(15000, false);
foreach (InventoryBase ib in iFolder.GetContents())
{
if (ib is InventoryFolder)
{
@@ -550,5 +723,41 @@ namespace IA_InventoryManager
}
return rtn.Trim();
}
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
// Setup Login to Second Life
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!_Client.Network.Login(FirstName, LastName, Password, "createnotecard", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + _Client.Network.LoginError);
return false;
}
// Login was successful
Console.WriteLine("Login was successful.");
Console.WriteLine("AgentID: " + _Client.Network.AgentID);
Console.WriteLine("SessionID: " + _Client.Network.SessionID);
return true;
}
protected void Disconnect()
{
// Logout of Second Life
Console.WriteLine("Request logout");
_Client.Network.Logout();
}
}
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using IA_SimpleInventory;
using IA_ImageTool;
@@ -11,11 +12,14 @@ using libsecondlife.AssetSystem;
namespace IA_MultiImageUpload
{
class MultiImageUpload : SimpleInventory
class MultiImageUpload
{
private SecondLife _Client;
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
protected string ImageDirectory;
static new void Main(string[] args)
static void Main(string[] args)
{
if (args.Length < 4)
{
@@ -32,14 +36,31 @@ namespace IA_MultiImageUpload
}
MultiImageUpload app = new MultiImageUpload( fullpath );
app.Connect(args[0], args[1], args[2]);
app.doStuff();
app.Disconnect();
if (app.Connect(args[0], args[1], args[2]))
{
if (app.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
app.doStuff();
app.Disconnect();
}
}
}
public MultiImageUpload(string dir)
{
ImageDirectory = dir;
try
{
_Client = new SecondLife();
_Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
}
catch (Exception e)
{
// Error initializing the client
Console.WriteLine();
Console.WriteLine(e.ToString());
}
}
public static void Usage()
@@ -47,9 +68,9 @@ namespace IA_MultiImageUpload
System.Console.WriteLine("MultiImageUpload [FirstName] [LastName] [Password] [Directory]");
}
protected new void doStuff()
protected void doStuff()
{
InventoryFolder iFolder = AgentInventory.getFolder("Textures");
InventoryFolder iFolder = _Client.Inventory.getFolder("Textures");
iFolder = iFolder.CreateFolder(Helpers.GetUnixTime().ToString());
Console.WriteLine("Uploading images:");
@@ -79,5 +100,39 @@ namespace IA_MultiImageUpload
}
}
}
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
// Setup Login to Second Life
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!_Client.Network.Login(FirstName, LastName, Password, "MultiImageUpload", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + _Client.Network.LoginError);
return false;
}
// Login was successful
Console.WriteLine("Login was successful.");
Console.WriteLine("AgentID: " + _Client.Network.AgentID);
Console.WriteLine("SessionID: " + _Client.Network.SessionID);
return true;
}
protected void Disconnect()
{
// Logout of Second Life
Console.WriteLine("Request logout");
_Client.Network.Logout();
}
}
}

View File

@@ -28,6 +28,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using IA_SimpleInventory;
using libsecondlife;
@@ -35,12 +36,16 @@ using libsecondlife.InventorySystem;
namespace IA_NotecardTool
{
class NotecardTool : SimpleInventory
class NotecardTool
{
private string FileName;
private string NotecardName;
static new void Main(string[] args)
private SecondLife _Client;
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
static void Main(string[] args)
{
if (args.Length < 6)
{
@@ -59,21 +64,22 @@ namespace IA_NotecardTool
tool.FileName = args[5];
tool.Connect(args[0], args[1], args[2]);
tool.doStuff();
tool.Disconnect();
System.Threading.Thread.Sleep(500);
if (tool.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
tool.doStuff();
tool.Disconnect();
}
}
private new void doStuff()
private void doStuff()
{
Console.WriteLine("Reading " + FileName);
StreamReader sr = File.OpenText(FileName);
string Body = sr.ReadToEnd();
Console.WriteLine("Getting Notecard Folder");
InventoryFolder iFolder = base.AgentInventory.getFolder("Notecards");
InventoryFolder iFolder = _Client.Inventory.getFolder("Notecards");
Console.WriteLine("Creating Notecard");
@@ -81,5 +87,55 @@ namespace IA_NotecardTool
Console.WriteLine("Done.");
}
public NotecardTool()
{
try
{
_Client = new SecondLife();
_Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
}
catch (Exception e)
{
// Error initializing the client
Console.WriteLine();
Console.WriteLine(e.ToString());
}
}
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
// Setup Login to Second Life
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!_Client.Network.Login(FirstName, LastName, Password, "createnotecard", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + _Client.Network.LoginError);
return false;
}
// Login was successful
Console.WriteLine("Login was successful.");
Console.WriteLine("AgentID: " + _Client.Network.AgentID);
Console.WriteLine("SessionID: " + _Client.Network.SessionID);
return true;
}
protected void Disconnect()
{
// Logout of Second Life
Console.WriteLine("Request logout");
_Client.Network.Logout();
}
}
}

View File

@@ -27,6 +27,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using libsecondlife;
using libsecondlife.InventorySystem;
@@ -38,10 +39,8 @@ namespace IA_SimpleInventory
/// </summary>
public class SimpleInventory
{
protected SecondLife client;
protected InventoryManager AgentInventory;
protected bool DownloadInventoryOnConnect = true;
private SecondLife client;
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
public static void Main(string[] args)
{
@@ -53,9 +52,14 @@ namespace IA_SimpleInventory
}
SimpleInventory simple = new SimpleInventory();
simple.Connect(args[0], args[1], args[2]);
simple.doStuff();
simple.Disconnect();
if (simple.Connect(args[0], args[1], args[2]))
{
if (simple.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
simple.doStuff();
simple.Disconnect();
}
}
}
protected SimpleInventory()
@@ -63,6 +67,7 @@ namespace IA_SimpleInventory
try
{
client = new SecondLife();
client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
}
catch (Exception e)
{
@@ -72,6 +77,11 @@ namespace IA_SimpleInventory
}
}
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
@@ -80,7 +90,7 @@ namespace IA_SimpleInventory
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!client.Network.Login(FirstName, LastName, Password, "createnotecard", "static.sprocket@gmail.com"))
if (!client.Network.Login(FirstName, LastName, Password, "IA_SimpleInventory", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + client.Network.LoginError);
@@ -92,22 +102,6 @@ namespace IA_SimpleInventory
Console.WriteLine("AgentID: " + client.Network.AgentID);
Console.WriteLine("SessionID: " + client.Network.SessionID);
// Get Root Inventory Folder UUID
Console.WriteLine("Pulling root folder UUID from login data.");
ArrayList alInventoryRoot = (ArrayList)client.Network.LoginValues["inventory-root"];
Hashtable htInventoryRoot = (Hashtable)alInventoryRoot[0];
LLUUID agentRootFolderID = new LLUUID((string)htInventoryRoot["folder_id"]);
// Initialize Inventory Manager object
Console.WriteLine("Initializing Inventory Manager.");
AgentInventory = new InventoryManager(client, agentRootFolderID);
if (DownloadInventoryOnConnect)
{
// and request an inventory download
Console.WriteLine("Downloading Inventory.");
AgentInventory.DownloadInventory();
}
return true;
}
@@ -120,17 +114,19 @@ namespace IA_SimpleInventory
protected void doStuff()
{
// and request an inventory download
Console.WriteLine("Downloading Inventory.");
client.Inventory.DownloadInventory();
Console.WriteLine("Dumping a copy of " + client.Self.FirstName + "'s inventory to the console.");
Console.WriteLine();
if (AgentInventory != null)
{
InventoryFolder root = AgentInventory.getRootFolder();
InventoryFolder root = client.Inventory.getRootFolder();
if (root != null)
{
Console.WriteLine(root.toXML(false));
}
if (root != null)
{
Console.WriteLine(root.toXML(false));
}
}
}

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using IA_SimpleInventory;
using libsecondlife;
@@ -10,76 +11,79 @@ using libsecondlife.AssetSystem;
namespace IA_TestAsyncImage
{
class TestAsync : SimpleInventory
class TestAsync
{
ImageManager imgManager;
private SecondLife _Client;
private ManualResetEvent ConnectedSignal = new ManualResetEvent(false);
Queue<LLUUID> TextureQueue = new Queue<LLUUID>();
string OutputDirectory = "IA_TestAsyncImages";
private Queue<LLUUID> TextureQueue = new Queue<LLUUID>();
private string OutputDirectory = "IA_TestAsyncImages";
[STAThread]
static new void Main(string[] args)
static void Main(string[] args)
{
TestAsync app = new TestAsync();
app.DownloadInventoryOnConnect = false;
app.client.Objects.OnNewPrim += new ObjectManager.NewPrimCallback(app.Objects_OnNewPrim);
app.client.Objects.OnNewAvatar += new ObjectManager.NewAvatarCallback(app.Objects_OnNewAvatar);
app._Client.Objects.OnNewPrim += new ObjectManager.NewPrimCallback(app.Objects_OnNewPrim);
app._Client.Objects.OnNewAvatar += new ObjectManager.NewAvatarCallback(app.Objects_OnNewAvatar);
app.Connect(args[0], args[1], args[2]);
app.doStuff();
app.Disconnect();
System.Threading.Thread.Sleep(500);
if (app.ConnectedSignal.WaitOne(TimeSpan.FromMinutes(1), false))
{
app.doStuff();
app.Disconnect();
}
Console.WriteLine("Done...");
}
public TestAsync()
{
try
{
_Client = new SecondLife();
_Client.Images = new ImageManager(_Client, ImageManager.CacheTypes.Disk, OutputDirectory);
_Client.Network.OnConnected += new NetworkManager.ConnectedCallback(Network_OnConnected);
}
catch (Exception e)
{
// Error initializing the client
Console.WriteLine();
Console.WriteLine(e.ToString());
}
}
private void Objects_OnNewAvatar(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation)
{
if (imgManager == null)
if (avatar.FirstLifeImage != null)
{
Console.WriteLine("ImageManager not ready yet, queueing Avatar textures.");
TextureQueue.Enqueue(avatar.FirstLifeImage);
TextureQueue.Enqueue(avatar.ProfileImage);
foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values)
if (_Client.Images.isCachedImage(avatar.FirstLifeImage) == false)
{
TextureQueue.Enqueue(tef.TextureID);
_Client.Images.RequestImageAsync(avatar.FirstLifeImage);
}
}
else
if (avatar.ProfileImage != null)
{
if (avatar.FirstLifeImage != null)
if (_Client.Images.isCachedImage(avatar.FirstLifeImage) == false)
{
if (imgManager.isCachedImage(avatar.FirstLifeImage) == false)
{
imgManager.RequestImageAsync(avatar.FirstLifeImage);
}
_Client.Images.RequestImageAsync(avatar.ProfileImage);
}
}
if (avatar.ProfileImage != null)
if (avatar.Textures != null)
{
foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values)
{
if (imgManager.isCachedImage(avatar.FirstLifeImage) == false)
if (_Client.Images.isCachedImage(tef.TextureID) == false)
{
imgManager.RequestImageAsync(avatar.ProfileImage);
_Client.Images.RequestImageAsync(tef.TextureID);
}
}
if (avatar.Textures != null)
{
foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values)
else
{
if (imgManager.isCachedImage(tef.TextureID) == false)
{
imgManager.RequestImageAsync(tef.TextureID);
}
else
{
Console.WriteLine("Already cached: " + tef.TextureID);
}
Console.WriteLine("Already cached: " + tef.TextureID);
}
}
}
@@ -87,42 +91,29 @@ namespace IA_TestAsyncImage
private void Objects_OnNewPrim(Simulator simulator, PrimObject prim, ulong regionHandle, ushort timeDilation)
{
if (imgManager == null)
if ((prim.Textures.DefaultTexture != null) && (prim.Textures.DefaultTexture.TextureID != null))
{
Console.WriteLine("ImageManager not ready yet, queueing Prim textures.");
TextureQueue.Enqueue(prim.Textures.DefaultTexture.TextureID);
foreach (TextureEntryFace tef in prim.Textures.FaceTextures.Values)
if (_Client.Images.isCachedImage(prim.Textures.DefaultTexture.TextureID) == false)
{
TextureQueue.Enqueue(tef.TextureID);
_Client.Images.RequestImageAsync(prim.Textures.DefaultTexture.TextureID);
}
else
{
Console.WriteLine("Already cached: " + prim.Textures.DefaultTexture.TextureID);
}
}
else
if (prim.Textures.FaceTextures != null)
{
if ((prim.Textures.DefaultTexture != null) && (prim.Textures.DefaultTexture.TextureID != null))
foreach (TextureEntryFace tef in prim.Textures.FaceTextures.Values)
{
if (imgManager.isCachedImage(prim.Textures.DefaultTexture.TextureID) == false)
if (_Client.Images.isCachedImage(tef.TextureID) == false)
{
imgManager.RequestImageAsync(prim.Textures.DefaultTexture.TextureID);
_Client.Images.RequestImageAsync(tef.TextureID);
}
else
{
Console.WriteLine("Already cached: " + prim.Textures.DefaultTexture.TextureID);
}
}
if (prim.Textures.FaceTextures != null)
{
foreach (TextureEntryFace tef in prim.Textures.FaceTextures.Values)
{
if (imgManager.isCachedImage(tef.TextureID) == false)
{
imgManager.RequestImageAsync(tef.TextureID);
}
else
{
Console.WriteLine("Already cached: " + tef.TextureID);
}
Console.WriteLine("Already cached: " + tef.TextureID);
}
}
}
@@ -153,14 +144,14 @@ namespace IA_TestAsyncImage
}
}
protected new void doStuff()
protected void doStuff()
{
imgManager = new ImageManager(client, ImageManager.CacheTypes.Disk, OutputDirectory);
imgManager.OnImageRetrieved += new ImageRetrievedCallback(NewImageRetrievedCallBack);
_Client.Images.OnImageRetrieved += new ImageRetrievedCallback(NewImageRetrievedCallBack);
while (TextureQueue.Count > 0)
{
imgManager.RequestImageAsync(TextureQueue.Dequeue());
_Client.Images.RequestImageAsync(TextureQueue.Dequeue());
}
Console.WriteLine("Press any key to stop.");
@@ -183,5 +174,40 @@ namespace IA_TestAsyncImage
File.WriteAllBytes(filename, JasperWrapper.jasper_decode_j2c_to_tiff(j2cdata));
}
}
void Network_OnConnected(object sender)
{
ConnectedSignal.Set();
}
protected bool Connect(string FirstName, string LastName, string Password)
{
Console.WriteLine("Attempting to connect and login to SecondLife.");
// Setup Login to Second Life
Dictionary<string, object> loginReply = new Dictionary<string, object>();
// Login
if (!_Client.Network.Login(FirstName, LastName, Password, "createnotecard", "static.sprocket@gmail.com"))
{
// Login failed
Console.WriteLine("Error logging in: " + _Client.Network.LoginError);
return false;
}
// Login was successful
Console.WriteLine("Login was successful.");
Console.WriteLine("AgentID: " + _Client.Network.AgentID);
Console.WriteLine("SessionID: " + _Client.Network.SessionID);
return true;
}
protected void Disconnect()
{
// Logout of Second Life
Console.WriteLine("Request logout");
_Client.Network.Logout();
}
}
}

View File

@@ -136,7 +136,7 @@ namespace Teleport
}
}
Client.Self.OnTeleport += new TeleportCallback(Avatar_OnTeleportMessage);
Client.Self.OnTeleport += new TeleportCallback(Self_OnTeleport);
DoneTeleporting = false;
Client.Self.Teleport(RegionHandle, coords);
@@ -147,7 +147,7 @@ namespace Teleport
}
}
private void Avatar_OnTeleportMessage(Simulator currentSim, string message, TeleportStatus status)
void Self_OnTeleport(Simulator currentSim, string message, TeleportStatus status)
{
Console.WriteLine(message);