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,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();
}
}
}