Files
libremetaverse/libsecondlife-cs/examples/IA_InventoryManager/iManager.cs
Michael Cortez a00b7debcc Added ability to teleport
git-svn-id: http://libopenmetaverse.googlecode.com/svn/trunk@540 52acb1d6-8a22-11de-b505-999d5b087335
2006-11-08 22:42:52 +00:00

344 lines
10 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using IA_SimpleInventory;
using libsecondlife;
using libsecondlife.InventorySystem;
using libsecondlife.AssetSystem;
namespace IA_InventoryManager
{
/// <summary>
/// Todo:
/// * TYPE or VIEW (for notecards, landmarks, etc)
/// * RENAME
/// * DOWNLOAD
/// * COPY
/// * MOVE
/// * GIVE
/// </summary>
class iManager : SimpleInventory
{
private char[] cmdSeperators = { ' ' };
private string curDirectory = "/";
private string TYPE_DIR = "<DIR> ";
private string TYPE_ITEM = "<ITEM> ";
static new void Main(string[] args)
{
if (args.Length < 3)
{
Console.WriteLine("Usage: Inventory [first] [last] [password]");
return;
}
iManager it = new iManager();
it.Connect(args[0], args[1], args[2]);
it.doStuff();
it.Disconnect();
System.Threading.Thread.Sleep(500);
}
private new void doStuff()
{
System.Threading.Thread.Sleep(1000);
Console.WriteLine("==================================================================");
Console.WriteLine("The Inventory Manager program provides a simple shell for working with your Second Life[tm] Avatar.");
Console.WriteLine();
Console.WriteLine("Type HELP for a list of available commands.");
Console.WriteLine("-------------------------------------------");
bool shutdown = false;
do
{
Console.WriteLine();
Console.Write( curDirectory + "> ");
string curCmd = Console.ReadLine();
string[] curCmdLine = curCmd.Split(cmdSeperators);
switch (curCmdLine[0].ToLower())
{
case "quit":
case "exit":
case "bye":
case "q":
shutdown = true;
break;
case "help":
help();
break;
case "ls":
case "dir":
ls( curCmdLine );
break;
case "cd":
cd(curCmdLine);
break;
case "mkdir":
mkdir(curCmdLine);
break;
case "rmdir":
rmdir(curCmdLine);
break;
case "getasset":
getasset(curCmdLine);
break;
case "regioninfo":
regioninfo(curCmdLine);
break;
case "teleport":
teleport(curCmdLine);
break;
default:
Console.WriteLine("Unknown command '" + curCmdLine[0] + "'.");
Console.WriteLine("Type HELP for a list of available commands.");
break;
}
} while (shutdown == false);
}
private void help()
{
Console.WriteLine("Currently available commands are: ");
Console.WriteLine("LS - List contents of the current directory.");
Console.WriteLine("CD - Change directory.");
Console.WriteLine("MKDIR - Make a new directory.");
Console.WriteLine("RMDIR - Remove directory.");
Console.WriteLine("GETASSET - Fetch an asset from SL.");
Console.WriteLine("REGIONINFO - Display Grid Region Info.");
Console.WriteLine("TELEPORT - Teleport to a new sim.");
Console.WriteLine("QUIT - Exit the Inventory Manager.");
}
private void teleport(string[] cmdLine)
{
if (cmdLine.Length < 5)
{
Console.WriteLine("Usage: teleport [sim] [x] [y] [z]");
Console.WriteLine("Example: teleport hooper 182 40 26");
return;
}
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)
{
Console.WriteLine("Caching estate sims...");
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]) ) );
}
}
private void regioninfo(string[] cmdLine)
{
if (cmdLine.Length < 2)
{
Console.WriteLine("Usage: regioninfo [name]");
Console.WriteLine("Example: regioninfo ahern");
return;
}
string regionName = "";
for( int i = 1; i < cmdLine.Length; i++ )
{
regionName += cmdLine[i] + " ";
}
regionName = regionName.Trim();
GridRegion gr = client.Grid.GetGridRegion(regionName);
Console.WriteLine(gr);
}
private void getasset(string[] cmdLine)
{
if (cmdLine.Length < 3)
{
Console.WriteLine("Usage: getasset [type] [UUID]");
Console.WriteLine("Example: getasset 13 c2ca25c1fb242e41650a54901bc2d21c");
return;
}
Asset asset = new Asset(cmdLine[2], sbyte.Parse(cmdLine[1]), null);
AgentInventory.getAssetManager().GetInventoryAsset(asset);
Console.WriteLine(asset.AssetDataToString());
}
private void rmdir(string[] cmdLine)
{
if (cmdLine.Length < 2)
{
Console.WriteLine("Usage: rmdir [directory]");
Console.WriteLine("Example: rmdir SubDir");
return;
}
string targetDir = "";
if (!curDirectory.Equals("/"))
{
targetDir = curDirectory + "/";
}
targetDir += combineCmdArg(cmdLine);
InventoryFolder iFolder = AgentInventory.getFolder(targetDir);
if (iFolder == null)
{
Console.WriteLine("Could not find directory: " + targetDir);
return;
}
else
{
iFolder.Delete();
}
}
private void mkdir(string[] cmdLine)
{
if (cmdLine.Length < 2)
{
Console.WriteLine("Usage: mkdir [directory]");
Console.WriteLine("Example: mkdir SubDir");
return;
}
string targetDir = combineCmdArg(cmdLine);
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
InventoryFolder newFolder = iFolder.CreateFolder(targetDir);
if (newFolder != null)
{
Console.WriteLine("Directory created: " + targetDir);
}
else
{
Console.WriteLine("Error creating directory: " + targetDir);
}
}
private void cd(string[] cmdLine)
{
if( cmdLine.Length < 2 )
{
Console.WriteLine("Usage: cd [directory]");
Console.WriteLine("Example: cd /Notecards");
return;
}
string targetDir = "";
if (cmdLine[1].Equals(".."))
{
targetDir = curDirectory.Substring(0, curDirectory.LastIndexOf("/"));
}
else if (cmdLine[1].StartsWith("/"))
{
targetDir += combineCmdArg(cmdLine);
}
else
{
if (!curDirectory.Equals("/"))
{
targetDir = curDirectory + "/";
}
targetDir += combineCmdArg(cmdLine);
}
Console.WriteLine("Changing directory to: " + targetDir );
InventoryFolder iFolder = AgentInventory.getFolder(targetDir);
if (iFolder == null)
{
Console.WriteLine("Could not find directory: " + targetDir);
return;
}
else
{
if (targetDir.StartsWith("/"))
{
curDirectory = targetDir;
}
else
{
curDirectory = "/" + targetDir;
}
}
}
private void ls(string[] cmdLine)
{
Console.WriteLine("Contents of: " + curDirectory);
Console.WriteLine("--------------------------------------------------");
if (!curDirectory.Equals("/"))
{
Console.WriteLine("..");
}
InventoryFolder iFolder = AgentInventory.getFolder(curDirectory);
foreach (InventoryBase ib in iFolder.alContents)
{
if (ib is InventoryFolder)
{
InventoryFolder folder = (InventoryFolder)ib;
Console.WriteLine(TYPE_DIR + folder.Name);
}
else
{
InventoryItem item = (InventoryItem)ib;
Console.WriteLine(TYPE_ITEM + item.Name);
}
}
}
private string combineCmdArg( string[] cmdLine )
{
return combineString( cmdLine, 1 );
}
private string combineString( string[] parts, int start )
{
string rtn = "";
for (int i = start; i < parts.Length; i++)
{
rtn += " " + parts[i];
}
return rtn.Trim();
}
}
}