Open sourced NatiBot

This commit is contained in:
2014-09-04 04:26:22 +01:00
parent 0c66d4a2ea
commit e4b4c631af
301 changed files with 84837 additions and 7 deletions

View File

@@ -0,0 +1,514 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : BackupCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse.Assets;
public class BackupCommand : Command
{
private BackgroundWorker BackupWorker;
private List<QueuedDownloadInfo> CurrentDownloads = new List<QueuedDownloadInfo>(10);
private const int MAX_TRANSFERS = 10;
private Queue<QueuedDownloadInfo> PendingDownloads = new Queue<QueuedDownloadInfo>();
private BackgroundWorker QueueWorker;
private int TextItemErrors;
private int TextItemsFound;
private int TextItemsTransferred;
#region Properties
/// <summary>
/// true if either of the background threads is running
/// </summary>
private bool BackgroundBackupRunning
{
get { return InventoryWalkerRunning || QueueRunnerRunning; }
}
/// <summary>
/// true if the thread walking inventory is running
/// </summary>
private bool InventoryWalkerRunning
{
get { return BackupWorker != null; }
}
/// <summary>
/// true if the thread feeding the queue to the server is running
/// </summary>
private bool QueueRunnerRunning
{
get { return QueueWorker != null; }
}
/// <summary>
/// returns a string summarizing activity
/// </summary>
/// <returns></returns>
private string BackgroundBackupStatus
{
get
{
StringBuilder sbResult = new StringBuilder();
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Running"), Name, BoolToNot(BackgroundBackupRunning));
if (TextItemErrors != 0 || TextItemsFound != 0 || TextItemsTransferred != 0)
{
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Walker"),
Name, BoolToNot(InventoryWalkerRunning), TextItemsFound);
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Transfer"),
Name, BoolToNot(QueueRunnerRunning), TextItemsTransferred, TextItemErrors);
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Queue"),
Name, PendingDownloads.Count, CurrentDownloads.Count);
}
return sbResult.ToString();
}
}
#endregion Properties
public BackupCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "backup";
base.Description = bot.Localization.clResourceManager.getText("Commands.Backup.Description") + " " + String.Format(bot.Localization.clResourceManager.getText("Commands.Backup.Usage"), Name);
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
Program.NBStats.AddStatData(String.Format("{0}: {1} backing up all inventory.", DateTime.Now.ToString(), Client));
StringBuilder sbResult = new StringBuilder();
if (args.Length == 1 && args[0] == "status")
{
return BackgroundBackupStatus;
}
else if (args.Length == 1 && args[0] == "abort")
{
if (!BackgroundBackupRunning)
return BackgroundBackupStatus;
BackupWorker.CancelAsync();
QueueWorker.CancelAsync();
Thread.Sleep(500);
// check status
return BackgroundBackupStatus;
}
else if (args.Length != 2)
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.Backup.Usage"), Name);
}
else if (BackgroundBackupRunning)
{
return BackgroundBackupStatus;
}
QueueWorker = new BackgroundWorker();
QueueWorker.WorkerSupportsCancellation = true;
QueueWorker.DoWork += new DoWorkEventHandler(bwQueueRunner_DoWork);
QueueWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwQueueRunner_RunWorkerCompleted);
QueueWorker.RunWorkerAsync();
BackupWorker = new BackgroundWorker();
BackupWorker.WorkerSupportsCancellation = true;
BackupWorker.DoWork += new DoWorkEventHandler(bwBackup_DoWork);
BackupWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwBackup_RunWorkerCompleted);
BackupWorker.RunWorkerAsync(args);
return bot.Localization.clResourceManager.getText("Commands.Backup.Started");
}
void bwQueueRunner_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
QueueWorker = null;
bot.Console.WriteLine(BackgroundBackupStatus);
}
void bwQueueRunner_DoWork(object sender, DoWorkEventArgs e)
{
TextItemErrors = TextItemsTransferred = 0;
while (QueueWorker.CancellationPending == false)
{
// have any timed out?
if (CurrentDownloads.Count > 0)
{
lock (CurrentDownloads)
{
foreach (QueuedDownloadInfo qdi in CurrentDownloads)
{
if ((qdi.WhenRequested + TimeSpan.FromSeconds(60)) < DateTime.Now)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Timeout"), Name, qdi.AssetID.ToString());
// submit request again
if (qdi.Type == AssetType.Notecard || qdi.Type == AssetType.LSLText || qdi.Type == AssetType.Texture)
{
if (qdi.Type == AssetType.Texture)
{
Client.Assets.RequestImage(qdi.AssetID, Assets_OnImageReceived);
}
else
{
Client.Assets.RequestInventoryAsset(
qdi.AssetID, qdi.ItemID, qdi.TaskID, qdi.OwnerID, qdi.Type, true, Assets_OnAssetReceived);
}
}
else
{
Client.Assets.RequestAsset(qdi.AssetID, qdi.Type, true, Assets_OnAssetReceived);
}
qdi.WhenRequested = DateTime.Now;
qdi.IsRequested = true;
}
}
}
}
if (PendingDownloads.Count != 0)
{
// room in the server queue?
if (CurrentDownloads.Count < MAX_TRANSFERS)
{
// yes
QueuedDownloadInfo qdi = PendingDownloads.Dequeue();
qdi.WhenRequested = DateTime.Now;
qdi.IsRequested = true;
if (qdi.Type == AssetType.Notecard || qdi.Type == AssetType.LSLText || qdi.Type == AssetType.Texture)
{
if (qdi.Type == AssetType.Texture)
{
Client.Assets.RequestImage(qdi.AssetID, Assets_OnImageReceived);
}
else
{
Client.Assets.RequestInventoryAsset(
qdi.AssetID, qdi.ItemID, qdi.TaskID, qdi.OwnerID, qdi.Type, true, Assets_OnAssetReceived);
}
}
else
{
Client.Assets.RequestAsset(qdi.AssetID, qdi.Type, true, Assets_OnAssetReceived);
}
lock (CurrentDownloads)
CurrentDownloads.Add(qdi);
}
}
if (CurrentDownloads.Count == 0 && PendingDownloads.Count == 0 && BackupWorker == null)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.AllDone"), Name);
return;
}
Thread.Sleep(100);
}
}
void bwBackup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.WalkingDone"), Name);
BackupWorker = null;
}
private void bwBackup_DoWork(object sender, DoWorkEventArgs e)
{
string[] args;
TextItemsFound = 0;
args = (string[])e.Argument;
lock (CurrentDownloads)
CurrentDownloads.Clear();
// FIXME:
//Client.Inventory.RequestFolderContents(Client.Inventory.Store.RootFolder.UUID, Client.Self.AgentID,
// true, true, false, InventorySortOrder.ByName);
DirectoryInfo di = new DirectoryInfo(args[1]);
// recurse on the root folder into the entire inventory
BackupFolder(Client.Inventory.Store.RootNode, di.FullName);
}
/// <summary>
/// BackupFolder - recurse through the inventory nodes sending scripts and notecards to the transfer queue
/// </summary>
/// <param name="folder">The current leaf in the inventory tree</param>
/// <param name="sPathSoFar">path so far, in the form @"c:\here" -- this needs to be "clean" for the current filesystem</param>
private void BackupFolder(InventoryNode folder, string sPathSoFar)
{
StringBuilder sbRequests = new StringBuilder();
// FIXME:
//Client.Inventory.RequestFolderContents(folder.Data.UUID, Client.Self.AgentID, true, true, false,
// InventorySortOrder.ByName);
// first scan this folder for text
foreach (InventoryNode iNode in folder.Nodes.Values)
{
if (BackupWorker.CancellationPending)
return;
if (iNode.Data is OpenMetaverse.InventoryItem)
{
InventoryItem ii = iNode.Data as InventoryItem;
string sExtension;
string sPath;
switch (ii.AssetType)
{
case AssetType.Animation:
sExtension = ".animatn";
break;
case AssetType.Bodypart:
sExtension = ".bodypart";
break;
case AssetType.CallingCard:
continue; // They really don't exist. Are not backable.
case AssetType.Clothing:
sExtension = ".clothing";
break;
case AssetType.Folder:
continue;
case AssetType.Gesture:
sExtension = ".gesture";
break;
case AssetType.ImageJPEG:
sExtension = ".jpg";
break;
case AssetType.ImageTGA:
sExtension = ".tga";
break;
case AssetType.Landmark:
sExtension = ".landmark";
break;
case AssetType.LostAndFoundFolder:
continue;
case AssetType.LSLBytecode:
sExtension = ".lso";
break;
case AssetType.LSLText:
if ((ii.Permissions.OwnerMask & PermissionMask.Copy) == PermissionMask.None || (ii.Permissions.OwnerMask & PermissionMask.Modify) == PermissionMask.None)
{
continue; // Nocopy scripts are not readable (SecondLife Jira VWR-5238). Nomod scripts will never be.
}
else
{
sExtension = ".lsl";
break;
}
case AssetType.Notecard:
if ((ii.Permissions.OwnerMask & PermissionMask.Copy) == PermissionMask.None)
{
continue; // Nocopy notecards are not readable (SecondLife Jira VWR-5238)
}
else
{
sExtension = ".notecard";
break;
}
case AssetType.Object:
/*sExtension=".object";
break;*/
continue; // They cannot be copied from the inventory, they must be rezzed
case AssetType.RootFolder:
continue;
case AssetType.Simstate:
sExtension = ".simstate";
break;
case AssetType.SnapshotFolder:
continue;
case AssetType.Sound:
sExtension = ".ogg";
break;
case AssetType.SoundWAV:
sExtension = ".wav";
break;
case AssetType.Texture:
sExtension = ".jp2";
break;
case AssetType.TextureTGA:
sExtension = ".tga";
break;
case AssetType.TrashFolder:
continue;
case AssetType.Unknown:
default:
sExtension = ".unk";
break;
}
// make the output file
sPath = sPathSoFar + @"\" + MakeValid(ii.Name.Trim()) + sExtension;
// create the new qdi
QueuedDownloadInfo qdi = new QueuedDownloadInfo(sPath, ii.AssetUUID, iNode.Data.UUID, UUID.Zero,
Client.Self.AgentID, ii.AssetType);
// add it to the queue
lock (PendingDownloads)
{
TextItemsFound++;
PendingDownloads.Enqueue(qdi);
}
}
}
// now run any subfolders
foreach (InventoryNode i in folder.Nodes.Values)
{
if (BackupWorker.CancellationPending)
return;
else if (i.Data is OpenMetaverse.InventoryFolder)
BackupFolder(i, sPathSoFar + @"\" + MakeValid(i.Data.Name.Trim()));
}
}
private string MakeValid(string path)
{
string FinalName;
//FinalName = path.Replace(" ", "_"); // This is not needed for exporting the inventory
FinalName = path.Replace(":", ";");
FinalName = FinalName.Replace("*", "+");
FinalName = FinalName.Replace("|", "I");
FinalName = FinalName.Replace("\\", "[");
FinalName = FinalName.Replace("/", "]");
FinalName = FinalName.Replace("?", "¿");
FinalName = FinalName.Replace(">", "}");
FinalName = FinalName.Replace("<", "{");
FinalName = FinalName.Replace("\"", "'");
FinalName = FinalName.Replace("\n", " ");
return FinalName;
}
private void Assets_OnAssetReceived(AssetDownload asset, Asset blah)
{
lock (CurrentDownloads)
{
// see if we have this in our transfer list
QueuedDownloadInfo r = CurrentDownloads.Find(delegate(QueuedDownloadInfo q)
{
return q.AssetID == asset.AssetID;
});
if (r != null && r.AssetID == asset.AssetID)
{
if (asset.Success)
{
// create the directory to put this in
Directory.CreateDirectory(Path.GetDirectoryName(r.FileName));
// write out the file
File.WriteAllBytes(r.FileName, asset.AssetData);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Wrote"), Name, r.FileName);
TextItemsTransferred++;
}
else
{
TextItemErrors++;
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Failed"), Name, r.FileName,
r.AssetID.ToString(), asset.Status.ToString());
}
// remove the entry
CurrentDownloads.Remove(r);
}
}
}
/// <summary>
/// returns blank or "not" if false
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
private static string BoolToNot(bool b)
{
return b ? String.Empty : bot.Localization.clResourceManager.getText("Commands.Backup.Not");
}
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
{
lock (CurrentDownloads)
{
// see if we have this in our transfer list
QueuedDownloadInfo r = CurrentDownloads.Find(delegate(QueuedDownloadInfo q)
{
return q.AssetID == asset.AssetID;
});
if (r != null && r.AssetID == asset.AssetID)
{
if (asset != null/* && asset.Decode()*/)
{
// create the directory to put this in
Directory.CreateDirectory(Path.GetDirectoryName(r.FileName));
// write out the file
File.WriteAllBytes(r.FileName, asset.AssetData);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Wrote"), Name, r.FileName);
// This, even being a desiderable feature, timeouts the bot and it gets ejected from SL.
/*File.WriteAllBytes(r.FileName.Substring(0, r.FileName.Length - 4) + ".tga", asset.Image.ExportTGA());
bot.Console.WriteLine("Wrote " + r.FileName.Substring(0, r.FileName.Length - 4) + ".tga");
Logger.DebugLog(Name + " Wrote: " + r.FileName.Substring(0, r.FileName.Length - 4) + ".tga", Client);*/
TextItemsTransferred++;
}
else
{
TextItemErrors++;
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Failed"), Name, r.FileName,
r.AssetID.ToString(), bot.Localization.clResourceManager.getText("Commands.Backup.Unknown"));
}
// remove the entry
CurrentDownloads.Remove(r);
}
}
}
}
}

View File

@@ -0,0 +1,370 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : BackupTextCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse.Assets;
public class BackupTextCommand : Command
{
private BackgroundWorker BackupWorker;
private List<QueuedDownloadInfo> CurrentDownloads = new List<QueuedDownloadInfo>(10);
private const int MAX_TRANSFERS = 10;
private Queue<QueuedDownloadInfo> PendingDownloads = new Queue<QueuedDownloadInfo>();
private BackgroundWorker QueueWorker;
private int TextItemErrors;
private int TextItemsFound;
private int TextItemsTransferred;
#region Properties
/// <summary>
/// true if either of the background threads is running
/// </summary>
private bool BackgroundBackupRunning
{
get { return InventoryWalkerRunning || QueueRunnerRunning; }
}
/// <summary>
/// true if the thread walking inventory is running
/// </summary>
private bool InventoryWalkerRunning
{
get { return BackupWorker != null; }
}
/// <summary>
/// true if the thread feeding the queue to the server is running
/// </summary>
private bool QueueRunnerRunning
{
get { return QueueWorker != null; }
}
/// <summary>
/// returns a string summarizing activity
/// </summary>
/// <returns></returns>
private string BackgroundBackupStatus
{
get
{
StringBuilder sbResult = new StringBuilder();
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Running"), Name, BoolToNot(BackgroundBackupRunning));
if (TextItemErrors != 0 || TextItemsFound != 0 || TextItemsTransferred != 0)
{
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Walker"),
Name, BoolToNot(InventoryWalkerRunning), TextItemsFound);
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Transfer"),
Name, BoolToNot(QueueRunnerRunning), TextItemsTransferred, TextItemErrors);
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Backup.Queue"),
Name, PendingDownloads.Count, CurrentDownloads.Count);
}
return sbResult.ToString();
}
}
#endregion Properties
public BackupTextCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "backuptext";
base.Description = bot.Localization.clResourceManager.getText("Commands.BackupText.Description") + " " + String.Format(bot.Localization.clResourceManager.getText("Commands.Backup.Usage"), Name);
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
Program.NBStats.AddStatData(String.Format("{0}: {1} backing up all text.", DateTime.Now.ToString(), Client));
StringBuilder sbResult = new StringBuilder();
if (args.Length == 1 && args[0] == "status")
{
return BackgroundBackupStatus;
}
else if (args.Length == 1 && args[0] == "abort")
{
if (!BackgroundBackupRunning)
return BackgroundBackupStatus;
BackupWorker.CancelAsync();
QueueWorker.CancelAsync();
Thread.Sleep(500);
// check status
return BackgroundBackupStatus;
}
else if (args.Length != 2)
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.Backup.Usage"), Name);
}
else if (BackgroundBackupRunning)
{
return BackgroundBackupStatus;
}
QueueWorker = new BackgroundWorker();
QueueWorker.WorkerSupportsCancellation = true;
QueueWorker.DoWork += new DoWorkEventHandler(bwQueueRunner_DoWork);
QueueWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwQueueRunner_RunWorkerCompleted);
QueueWorker.RunWorkerAsync();
BackupWorker = new BackgroundWorker();
BackupWorker.WorkerSupportsCancellation = true;
BackupWorker.DoWork += new DoWorkEventHandler(bwBackup_DoWork);
BackupWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bwBackup_RunWorkerCompleted);
BackupWorker.RunWorkerAsync(args);
return bot.Localization.clResourceManager.getText("Commands.Backup.Started");
}
void bwQueueRunner_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
QueueWorker = null;
bot.Console.WriteLine(BackgroundBackupStatus);
}
void bwQueueRunner_DoWork(object sender, DoWorkEventArgs e)
{
TextItemErrors = TextItemsTransferred = 0;
while (QueueWorker.CancellationPending == false)
{
// have any timed out?
if (CurrentDownloads.Count > 0)
{
foreach (QueuedDownloadInfo qdi in CurrentDownloads)
{
if ((qdi.WhenRequested + TimeSpan.FromSeconds(60)) < DateTime.Now)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Timeout"), Name, qdi.AssetID.ToString());
// submit request again
Client.Assets.RequestInventoryAsset(
qdi.AssetID, qdi.ItemID, qdi.TaskID, qdi.OwnerID, qdi.Type, true, Assets_OnAssetReceived);
qdi.WhenRequested = DateTime.Now;
qdi.IsRequested = true;
}
}
}
if (PendingDownloads.Count != 0)
{
// room in the server queue?
if (CurrentDownloads.Count < MAX_TRANSFERS)
{
// yes
QueuedDownloadInfo qdi = PendingDownloads.Dequeue();
qdi.WhenRequested = DateTime.Now;
qdi.IsRequested = true;
Client.Assets.RequestInventoryAsset(
qdi.AssetID, qdi.ItemID, qdi.TaskID, qdi.OwnerID, qdi.Type, true, Assets_OnAssetReceived);
lock (CurrentDownloads)
CurrentDownloads.Add(qdi);
}
}
if (CurrentDownloads.Count == 0 && PendingDownloads.Count == 0 && BackupWorker == null)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.AllDone"), Name);
return;
}
Thread.Sleep(100);
}
}
void bwBackup_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.WalkingDone"), Name);
BackupWorker = null;
}
private void bwBackup_DoWork(object sender, DoWorkEventArgs e)
{
string[] args;
TextItemsFound = 0;
args = (string[])e.Argument;
lock (CurrentDownloads)
CurrentDownloads.Clear();
// FIXME:
//Client.Inventory.RequestFolderContents(Client.Inventory.Store.RootFolder.UUID, Client.Self.AgentID,
// true, true, false, InventorySortOrder.ByName);
DirectoryInfo di = new DirectoryInfo(args[1]);
// recurse on the root folder into the entire inventory
BackupFolder(Client.Inventory.Store.RootNode, di.FullName);
}
/// <summary>
/// BackupFolder - recurse through the inventory nodes sending scripts and notecards to the transfer queue
/// </summary>
/// <param name="folder">The current leaf in the inventory tree</param>
/// <param name="sPathSoFar">path so far, in the form @"c:\here" -- this needs to be "clean" for the current filesystem</param>
private void BackupFolder(InventoryNode folder, string sPathSoFar)
{
StringBuilder sbRequests = new StringBuilder();
// FIXME:
//Client.Inventory.RequestFolderContents(folder.Data.UUID, Client.Self.AgentID, true, true, false,
// InventorySortOrder.ByName);
// first scan this folder for text
foreach (InventoryNode iNode in folder.Nodes.Values)
{
if (BackupWorker.CancellationPending)
return;
if (iNode.Data is OpenMetaverse.InventoryItem)
{
InventoryItem ii = iNode.Data as InventoryItem;
if (ii.AssetType == AssetType.LSLText || ii.AssetType == AssetType.Notecard)
{
// check permissions on scripts
if (ii.AssetType == AssetType.LSLText)
{
if ((ii.Permissions.OwnerMask & PermissionMask.Modify) == PermissionMask.None)
{
// skip this one
continue;
}
}
string sExtension = (ii.AssetType == AssetType.LSLText) ? ".lsl" : ".txt";
// make the output file
string sPath = sPathSoFar + @"\" + MakeValid(ii.Name.Trim()) + sExtension;
// create the new qdi
QueuedDownloadInfo qdi = new QueuedDownloadInfo(sPath, ii.AssetUUID, iNode.Data.UUID, UUID.Zero,
Client.Self.AgentID, ii.AssetType);
// add it to the queue
lock (PendingDownloads)
{
TextItemsFound++;
PendingDownloads.Enqueue(qdi);
}
}
}
}
// now run any subfolders
foreach (InventoryNode i in folder.Nodes.Values)
{
if (BackupWorker.CancellationPending)
return;
else if (i.Data is OpenMetaverse.InventoryFolder)
BackupFolder(i, sPathSoFar + @"\" + MakeValid(i.Data.Name.Trim()));
}
}
private string MakeValid(string path)
{
string FinalName;
FinalName = path.Replace(" ", "_");
FinalName = FinalName.Replace(":", ";");
FinalName = FinalName.Replace("*", "+");
FinalName = FinalName.Replace("|", "I");
FinalName = FinalName.Replace("\\", "[");
FinalName = FinalName.Replace("/", "]");
FinalName = FinalName.Replace("?", "¿");
FinalName = FinalName.Replace(">", "}");
FinalName = FinalName.Replace("<", "{");
FinalName = FinalName.Replace("\"", "'");
FinalName = FinalName.Replace("\n", " ");
return FinalName;
}
private void Assets_OnAssetReceived(AssetDownload asset, Asset blah)
{
lock (CurrentDownloads)
{
// see if we have this in our transfer list
QueuedDownloadInfo r = CurrentDownloads.Find(delegate(QueuedDownloadInfo q)
{
return q.AssetID == asset.AssetID;
});
if (r != null && r.AssetID == asset.AssetID)
{
if (asset.Success)
{
// create the directory to put this in
Directory.CreateDirectory(Path.GetDirectoryName(r.FileName));
// write out the file
File.WriteAllBytes(r.FileName, asset.AssetData);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Wrote"), Name, r.FileName);
TextItemsTransferred++;
}
else
{
TextItemErrors++;
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Backup.Failed"), Name, r.FileName,
r.AssetID.ToString(), asset.Status.ToString());
}
// remove the entry
CurrentDownloads.Remove(r);
}
}
}
/// <summary>
/// returns blank or "not" if false
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
private static string BoolToNot(bool b)
{
return b ? String.Empty : bot.Localization.clResourceManager.getText("Commands.Backup.Not");
}
}
}

View File

@@ -0,0 +1,122 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ChangeDirectoryCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
public class ChangeDirectoryCommand : Command
{
private InventoryManager Manager;
private OpenMetaverse.Inventory Inventory;
public ChangeDirectoryCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "cd";
base.Description = bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
Manager = Client.Inventory;
Inventory = Client.Inventory.Store;
if (args.Length > 1)
return bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.Usage");
string pathStr = "";
string[] path = null;
if (args.Length == 0)
{
path = new string[] { "" };
// cd without any arguments doesn't do anything.
}
else if (args.Length == 1)
{
pathStr = args[0];
path = pathStr.Split(new char[] { '/' });
// Use '/' as a path seperator.
}
InventoryFolder currentFolder = Client.CurrentDirectory;
if (pathStr.StartsWith("/"))
currentFolder = Inventory.RootFolder;
if (currentFolder == null) // We need this to be set to something.
//return "Error: Sesi<73>n no iniciada.";
currentFolder = Inventory.RootFolder;
// Traverse the path, looking for the
for (int i = 0; i < path.Length; ++i)
{
string nextName = path[i];
if (string.IsNullOrEmpty(nextName) || nextName == ".")
continue; // Ignore '.' and blanks, stay in the current directory.
if (nextName == ".." && currentFolder != Inventory.RootFolder)
{
// If we encounter .., move to the parent folder.
currentFolder = Inventory[currentFolder.ParentUUID] as InventoryFolder;
}
else
{
List<InventoryBase> currentContents = Inventory.GetContents(currentFolder);
// Try and find an InventoryBase with the corresponding name.
bool found = false;
foreach (InventoryBase item in currentContents)
{
// Allow lookup by UUID as well as name:
if (item.Name == nextName || item.UUID.ToString() == nextName)
{
found = true;
if (item is InventoryFolder)
{
currentFolder = item as InventoryFolder;
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.NotFolder"), item.Name);
}
}
}
if (!found)
return String.Format(bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.NotFound"), nextName, currentFolder.Name);
}
}
Client.CurrentDirectory = currentFolder;
return String.Format(bot.Localization.clResourceManager.getText("Commands.ChangeDirectory.CurrentFolder"), currentFolder.Name);
}
}
}

View File

@@ -0,0 +1,504 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : CreateClothingCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class CreateClothingCommand : Command
{
public CreateClothingCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "createclothing";
base.Description = bot.Localization.clResourceManager.getText("Commands.CreateClothing.Description") + " " + bot.Localization.clResourceManager.getText("Commands.CreateClothing.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
string LongUsage = bot.Localization.clResourceManager.getText("Commands.CreateClothing.UsageLine1") + System.Environment.NewLine +
bot.Localization.clResourceManager.getText("Commands.CreateClothing.UsageLine2");
string finalmessage = "";
string NL = "\n";
WearableType wtype;
UUID uuid1, uuid2;
uuid2 = UUID.Zero;
if (args.Length == 0)
return Description;
if (args.Length == 1)
if (args[0].ToLower() == "help")
return LongUsage;
else
return Description;
if (args.Length != 3 && args.Length != 4)
return Description;
switch (args[1].ToLower())
{
case "gloves":
wtype = WearableType.Gloves;
break;
case "jacket":
wtype = WearableType.Jacket;
if (args.Length != 4)
return bot.Localization.clResourceManager.getText("Commands.CreateClothing.Jacket");
break;
case "pants":
wtype = WearableType.Pants;
break;
case "shirt":
wtype = WearableType.Shirt;
break;
case "shoes":
wtype = WearableType.Shoes;
break;
case "skirt":
wtype = WearableType.Skirt;
break;
case "socks":
wtype = WearableType.Socks;
break;
case "underpants":
wtype = WearableType.Underpants;
break;
case "undershirt":
wtype = WearableType.Undershirt;
break;
default:
return bot.Localization.clResourceManager.getText("Commands.CreateClothing.Incorrect");
}
if (!UUID.TryParse(args[2], out uuid1))
return bot.Localization.clResourceManager.getText("Commands.CreateClothing.ExpectedID1");
if (args.Length == 4)
if (!UUID.TryParse(args[3], out uuid2))
return bot.Localization.clResourceManager.getText("Commands.CreateClothing.ExpectedID2");
if (args[1].ToLower() == "jacket")
Program.NBStats.AddStatData(String.Format("{0}: {1} creating clothing of type {2} named {3} with uuid {4} {5}.", DateTime.Now.ToString(), Client, args[1], args[0], args[2], args[3]));
else
Program.NBStats.AddStatData(String.Format("{0}: {1} creating clothing of type {2} named {3} with uuid {4}.", DateTime.Now.ToString(), Client, args[1], args[0], args[2]));
#region Part common to all wearable types
StringBuilder sbcloth = new StringBuilder("LLWearable version 22\n");
sbcloth.Append(args[0]);
sbcloth.Append(NL);
sbcloth.Append(NL);
sbcloth.Append("\tpermissions 0\n\t{\n");
sbcloth.Append("\t\tbase_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\towner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\teveryone_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\tnext_owner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tcreator_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\towner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tlast_owner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_id\t");
sbcloth.Append(UUID.Zero.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
sbcloth.Append("\tsale_info\t0\n");
sbcloth.Append("\t{\n");
sbcloth.Append("\t\tsale_type\t");
sbcloth.Append("not");
sbcloth.Append(NL);
sbcloth.Append("\t\tsale_price\t");
sbcloth.Append("0");
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
#endregion #region Part common to all wearable types
sbcloth.Append("type ");
sbcloth.Append((int)wtype);
sbcloth.Append(NL);
switch (wtype)
{
case WearableType.Gloves:
sbcloth.Append("parameters ");
sbcloth.Append(5);
sbcloth.Append(NL);
sbcloth.Append("93 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("827 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("829 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("830 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("844 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("15 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Jacket:
sbcloth.Append("parameters ");
sbcloth.Append(9);
sbcloth.Append(NL);
sbcloth.Append("606 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("607 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("608 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("609 ");
sbcloth.Append(".2");
sbcloth.Append(NL);
sbcloth.Append("780 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("834 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("835 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("836 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("877 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(2);
sbcloth.Append(NL);
sbcloth.Append("13 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
sbcloth.Append("14 ");
sbcloth.Append(uuid2.ToString());
sbcloth.Append(NL);
break;
case WearableType.Pants:
sbcloth.Append("parameters ");
sbcloth.Append(9);
sbcloth.Append(NL);
sbcloth.Append("625 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("638 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("806 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("807 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("808 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("814 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("815 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("816 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("869 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("2 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Shirt:
sbcloth.Append("parameters ");
sbcloth.Append(10);
sbcloth.Append(NL);
sbcloth.Append("781 ");
sbcloth.Append(".78");
sbcloth.Append(NL);
sbcloth.Append("800 ");
sbcloth.Append(".89");
sbcloth.Append(NL);
sbcloth.Append("801 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("802 ");
sbcloth.Append(".78");
sbcloth.Append(NL);
sbcloth.Append("803 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("804 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("805 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("828 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("840 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("868 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("1 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Shoes:
sbcloth.Append("parameters ");
sbcloth.Append(10);
sbcloth.Append(NL);
sbcloth.Append("198 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("503 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("508 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("513 ");
sbcloth.Append(".5");
sbcloth.Append(NL);
sbcloth.Append("514 ");
sbcloth.Append(".5");
sbcloth.Append(NL);
sbcloth.Append("616 ");
sbcloth.Append(".1");
sbcloth.Append(NL);
sbcloth.Append("654 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("812 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("813 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("817 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("7 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Skirt:
sbcloth.Append("parameters ");
sbcloth.Append(10);
sbcloth.Append(NL);
sbcloth.Append("848 ");
sbcloth.Append(".2");
sbcloth.Append(NL);
sbcloth.Append("858 ");
sbcloth.Append(".4");
sbcloth.Append(NL);
sbcloth.Append("859 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("860 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("861 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("862 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("863 ");
sbcloth.Append(".33");
sbcloth.Append(NL);
sbcloth.Append("921 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("922 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("923 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("18 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Socks:
sbcloth.Append("parameters ");
sbcloth.Append(4);
sbcloth.Append(NL);
sbcloth.Append("617 ");
sbcloth.Append(".35");
sbcloth.Append(NL);
sbcloth.Append("818 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("819 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("820 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("12 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Underpants:
sbcloth.Append("parameters ");
sbcloth.Append(5);
sbcloth.Append(NL);
sbcloth.Append("619 ");
sbcloth.Append(".3");
sbcloth.Append(NL);
sbcloth.Append("624 ");
sbcloth.Append(".8");
sbcloth.Append(NL);
sbcloth.Append("824 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("825 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("826 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("17 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
case WearableType.Undershirt:
sbcloth.Append("parameters ");
sbcloth.Append(7);
sbcloth.Append(NL);
sbcloth.Append("603 ");
sbcloth.Append(".4");
sbcloth.Append(NL);
sbcloth.Append("604 ");
sbcloth.Append(".85");
sbcloth.Append(NL);
sbcloth.Append("605 ");
sbcloth.Append(".84");
sbcloth.Append(NL);
sbcloth.Append("779 ");
sbcloth.Append(".84");
sbcloth.Append(NL);
sbcloth.Append("821 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("822 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("823 ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("16 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
break;
}
AssetClothing clothing = new AssetClothing(sbcloth.ToString());
clothing.Decode();
Client.Inventory.RequestCreateItemFromAsset(clothing.AssetData, args[0], String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreatedBy"), args[0], DateTime.Now), AssetType.Clothing,
InventoryType.Wearable, Client.Inventory.FindFolderForType(AssetType.Clothing),
delegate(bool success, string status, UUID itemID, UUID assetID)
{
if (success)
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateClothing.Created"), assetID);
Client.Inventory.GiveItem(itemID, args[0], AssetType.Clothing, Client.MasterKey, false);
}
else
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateClothing.Failed"), status);
}
}
);
return finalmessage;
}
}
}

View File

@@ -0,0 +1,156 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : CreateEyesCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class CreateEyesCommand : Command
{
public CreateEyesCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "createeyes";
base.Description = bot.Localization.clResourceManager.getText("Commands.CreateEyes.Description") + " " + bot.Localization.clResourceManager.getText("Commands.CreateEyes.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
string finalmessage = "";
string NL = "\n";
UUID uuid1;
uuid1 = UUID.Zero;
if (args.Length != 2)
return Description;
if (!UUID.TryParse(args[1], out uuid1))
return bot.Localization.clResourceManager.getText("Commands.CreateEyes.ExpectedID");
Program.NBStats.AddStatData(String.Format("{0}: {1} creating eyes named {2} with uuid {3}.", DateTime.Now.ToString(), Client, args[0], args[1]));
#region Part common to all wearable types
StringBuilder sbcloth = new StringBuilder("LLWearable version 22\n");
sbcloth.Append(args[0]);
sbcloth.Append(NL);
sbcloth.Append(NL);
sbcloth.Append("\tpermissions 0\n\t{\n");
sbcloth.Append("\t\tbase_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\towner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\teveryone_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\tnext_owner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tcreator_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\towner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tlast_owner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_id\t");
sbcloth.Append(UUID.Zero.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
sbcloth.Append("\tsale_info\t0\n");
sbcloth.Append("\t{\n");
sbcloth.Append("\t\tsale_type\t");
sbcloth.Append("not");
sbcloth.Append(NL);
sbcloth.Append("\t\tsale_price\t");
sbcloth.Append("0");
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
#endregion #region Part common to all wearable types
sbcloth.Append("type ");
sbcloth.Append((int)WearableType.Eyes);
sbcloth.Append(NL);
sbcloth.Append("parameters ");
sbcloth.Append(2);
sbcloth.Append(NL);
sbcloth.Append("98 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("99 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(1);
sbcloth.Append(NL);
sbcloth.Append("3 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
AssetBodypart bodypart = new AssetBodypart(sbcloth.ToString());
bodypart.Decode();
Client.Inventory.RequestCreateItemFromAsset(bodypart.AssetData, args[0], String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreatedBy"), args[0], DateTime.Now), AssetType.Bodypart,
InventoryType.Wearable, Client.Inventory.FindFolderForType(AssetType.Bodypart),
delegate(bool success, string status, UUID itemID, UUID assetID)
{
if (success)
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateEyes.Created"), assetID);
Client.Inventory.GiveItem(itemID, args[0], AssetType.Bodypart, Client.MasterKey, false);
}
else
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateEyes.Failed"), status);
}
}
);
return finalmessage;
}
}
}

View File

@@ -0,0 +1,81 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : CreateLandMarkCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
// Does not work, HTTP error 400.
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class CreateLandMarkCommand : Command
{
public CreateLandMarkCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "createlm";
base.Description = bot.Localization.clResourceManager.getText("Commands.CreateLandMark.Description");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
string finalmessage = "";
AssetLandmark landmark = new AssetLandmark(this.Client.Network.CurrentSim.RegionID, this.Client.Self.SimPosition);
landmark.Encode();
landmark.Decode();
Client.Inventory.RequestCreateItemFromAsset(landmark.AssetData, this.Client.Network.CurrentSim.Name, String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreatedBy"), this.Client.Network.CurrentSim.Name, DateTime.Now), AssetType.Landmark,
InventoryType.Landmark, Client.Inventory.FindFolderForType(AssetType.Landmark),
delegate(bool success, string status, UUID itemID, UUID assetID)
{
if (success)
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateLandMark.Created"), assetID);
Client.Inventory.GiveItem(itemID, this.Client.Network.CurrentSim.Name, AssetType.Clothing, Client.MasterKey, false);
}
else
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateLandMark.Failed"), status);
}
}
);
return finalmessage;
}
}
}

View File

@@ -0,0 +1,233 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : CreateNotecardCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class CreateNotecardCommand : Command
{
const int NOTECARD_CREATE_TIMEOUT = 2500 * 10;
const int NOTECARD_FETCH_TIMEOUT = 1500 * 10;
const int INVENTORY_FETCH_TIMEOUT = 1500 * 10;
public CreateNotecardCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "createnotecard";
base.Description = bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Description") + " " + bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
UUID embedItemID = UUID.Zero, notecardItemID = UUID.Zero, notecardAssetID = UUID.Zero;
string filename, fileData;
bool success = false, finalUploadSuccess = false;
string message = String.Empty;
AutoResetEvent notecardEvent = new AutoResetEvent(false);
if (args.Length == 1)
{
filename = args[0];
}
else if (args.Length == 2)
{
filename = args[0];
UUID.TryParse(args[1], out embedItemID);
}
else
{
return bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Usage");
}
if (!File.Exists(filename))
return String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.NotFound"), filename);
try
{
fileData = File.ReadAllText(filename);
}
catch (Exception ex)
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.OpenFailed"), filename, ex.Message);
}
#region Notecard asset data
AssetNotecard notecard = new AssetNotecard();
notecard.BodyText = fileData;
// Item embedding
if (embedItemID != UUID.Zero)
{
// Try to fetch the inventory item
InventoryItem item = FetchItem(embedItemID);
if (item != null)
{
notecard.EmbeddedItems = new List<InventoryItem> { item };
notecard.BodyText += (char)0xdbc0 + (char)0xdc00;
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.FetchFailed"), embedItemID);
}
}
notecard.Encode();
#endregion Notecard asset data
Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.Notecard),
filename, String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreatedBy"), filename, DateTime.Now), AssetType.Notecard,
UUID.Random(), InventoryType.Notecard, PermissionMask.All,
delegate(bool createSuccess, InventoryItem item)
{
if (createSuccess)
{
#region Upload an empty notecard asset first
AutoResetEvent emptyNoteEvent = new AutoResetEvent(false);
AssetNotecard empty = new AssetNotecard();
empty.BodyText = "\n";
empty.Encode();
Client.Inventory.RequestUploadNotecardAsset(empty.AssetData, item.UUID,
delegate(bool uploadSuccess, string status, UUID itemID, UUID assetID)
{
notecardItemID = itemID;
notecardAssetID = assetID;
success = uploadSuccess;
message = status ?? bot.Localization.clResourceManager.getText("Commands.CreateNotecard.UnknownError");
emptyNoteEvent.Set();
});
emptyNoteEvent.WaitOne(NOTECARD_CREATE_TIMEOUT, false);
#endregion Upload an empty notecard asset first
if (success)
{
// Upload the actual notecard asset
Client.Inventory.RequestUploadNotecardAsset(notecard.AssetData, item.UUID,
delegate(bool uploadSuccess, string status, UUID itemID, UUID assetID)
{
notecardItemID = itemID;
notecardAssetID = assetID;
finalUploadSuccess = uploadSuccess;
message = status ?? bot.Localization.clResourceManager.getText("Commands.CreateNotecard.UnknownError");
notecardEvent.Set();
});
}
else
{
notecardEvent.Set();
}
}
else
{
message = bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreateFail");
notecardEvent.Set();
}
}
);
notecardEvent.WaitOne(NOTECARD_CREATE_TIMEOUT, false);
if (finalUploadSuccess)
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Success"), notecardItemID, notecardAssetID);
Client.Inventory.GiveItem(notecardItemID, filename, AssetType.Notecard, Client.MasterKey, false);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Sending"));
return DownloadNotecard(notecardItemID, notecardAssetID);
}
else
return String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreateFailDetails"), message);
}
private InventoryItem FetchItem(UUID itemID)
{
InventoryItem fetchItem = null;
AutoResetEvent fetchItemEvent = new AutoResetEvent(false);
EventHandler<ItemReceivedEventArgs> itemReceivedCallback =
delegate(object sender, ItemReceivedEventArgs e)
{
if (e.Item.UUID == itemID)
{
fetchItem = e.Item;
fetchItemEvent.Set();
}
};
Client.Inventory.ItemReceived += itemReceivedCallback;
Client.Inventory.RequestFetchInventory(itemID, Client.Self.AgentID);
fetchItemEvent.WaitOne(INVENTORY_FETCH_TIMEOUT, false);
Client.Inventory.ItemReceived -= itemReceivedCallback;
return fetchItem;
}
private string DownloadNotecard(UUID itemID, UUID assetID)
{
AutoResetEvent assetDownloadEvent = new AutoResetEvent(false);
byte[] notecardData = null;
string error = bot.Localization.clResourceManager.getText("Commands.CreateNotecard.Timeout");
Client.Assets.RequestInventoryAsset(assetID, itemID, UUID.Zero, Client.Self.AgentID, AssetType.Notecard, true,
delegate(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
notecardData = transfer.AssetData;
else
error = transfer.Status.ToString();
assetDownloadEvent.Set();
}
);
assetDownloadEvent.WaitOne(NOTECARD_FETCH_TIMEOUT, false);
if (notecardData != null)
return Encoding.UTF8.GetString(notecardData);
else
return String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.DownloadError"), error);
}
}
}

View File

@@ -0,0 +1,240 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : CreateSkinCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class CreateSkinCommand : Command
{
public CreateSkinCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "createskin";
base.Description = bot.Localization.clResourceManager.getText("Commands.CreateSkin.Description") + " " + bot.Localization.clResourceManager.getText("Commands.CreateSkin.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
string finalmessage = "";
string NL = "\n";
UUID uuid1, uuid2, uuid3;
uuid3 = uuid2 = uuid1 = UUID.Zero;
if (args.Length != 4)
return bot.Localization.clResourceManager.getText("Commands.CreateSkin.Usage");
if (!UUID.TryParse(args[1], out uuid1))
return bot.Localization.clResourceManager.getText("Commands.CreateSkin.ExpectedFaceID");
if (!UUID.TryParse(args[2], out uuid2))
return bot.Localization.clResourceManager.getText("Commands.CreateSkin.ExpectedUpID");
if (!UUID.TryParse(args[3], out uuid3))
return bot.Localization.clResourceManager.getText("Commands.CreateSkin.ExpectedLowID");
Program.NBStats.AddStatData(String.Format("{0}: {1} creating skin named {2} with uuids {3} {4} {5}.", DateTime.Now.ToString(), Client, args[0], args[1], args[2], args[3]));
#region Part common to all wearable types
StringBuilder sbcloth = new StringBuilder("LLWearable version 22\n");
sbcloth.Append(args[0]);
sbcloth.Append(NL);
sbcloth.Append(NL);
sbcloth.Append("\tpermissions 0\n\t{\n");
sbcloth.Append("\t\tbase_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\towner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\teveryone_mask\t");
sbcloth.Append("00000000");
sbcloth.Append(NL);
sbcloth.Append("\t\tnext_owner_mask\t");
sbcloth.Append("7fffffff");
sbcloth.Append(NL);
sbcloth.Append("\t\tcreator_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\towner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tlast_owner_id\t");
sbcloth.Append(Client.Self.AgentID.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t\tgroup_id\t");
sbcloth.Append(UUID.Zero.ToString());
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
sbcloth.Append("\tsale_info\t0\n");
sbcloth.Append("\t{\n");
sbcloth.Append("\t\tsale_type\t");
sbcloth.Append("not");
sbcloth.Append(NL);
sbcloth.Append("\t\tsale_price\t");
sbcloth.Append("0");
sbcloth.Append(NL);
sbcloth.Append("\t}\n");
#endregion #region Part common to all wearable types
sbcloth.Append("type ");
sbcloth.Append((int)WearableType.Skin);
sbcloth.Append(NL);
sbcloth.Append("parameters ");
sbcloth.Append(26);
sbcloth.Append(NL);
sbcloth.Append("108 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("110 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("111 ");
sbcloth.Append(".5");
sbcloth.Append(NL);
sbcloth.Append("116 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("117 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("150 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("162 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("163 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("165 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("700 ");
sbcloth.Append(".25");
sbcloth.Append(NL);
sbcloth.Append("701 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("702 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("703 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("704 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("705 ");
sbcloth.Append(".5");
sbcloth.Append(NL);
sbcloth.Append("706 ");
sbcloth.Append(".6");
sbcloth.Append(NL);
sbcloth.Append("707 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("708 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("709 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("710 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("711 ");
sbcloth.Append(".5");
sbcloth.Append(NL);
sbcloth.Append("712 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("713 ");
sbcloth.Append(".7");
sbcloth.Append(NL);
sbcloth.Append("714 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("715 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("775 ");
sbcloth.Append(0);
sbcloth.Append(NL);
sbcloth.Append("textures ");
sbcloth.Append(3);
sbcloth.Append(NL);
sbcloth.Append("0 ");
sbcloth.Append(uuid1.ToString());
sbcloth.Append(NL);
sbcloth.Append("5 ");
sbcloth.Append(uuid2.ToString());
sbcloth.Append(NL);
sbcloth.Append("6 ");
sbcloth.Append(uuid3.ToString());
sbcloth.Append(NL);
AssetBodypart bodypart = new AssetBodypart(sbcloth.ToString());
bodypart.Decode();
Client.Inventory.RequestCreateItemFromAsset(bodypart.AssetData, args[0], String.Format(bot.Localization.clResourceManager.getText("Commands.CreateNotecard.CreatedBy"), args[0], DateTime.Now), AssetType.Bodypart,
InventoryType.Wearable, Client.Inventory.FindFolderForType(AssetType.Bodypart),
delegate(bool success, string status, UUID itemID, UUID assetID)
{
if (success)
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateSkin.Created"), assetID);
Client.Inventory.GiveItem(itemID, args[0], AssetType.Bodypart, Client.MasterKey, false);
}
else
{
finalmessage = String.Format(bot.Localization.clResourceManager.getText("Commands.CreateSkin.Failed"), status);
}
}
);
return finalmessage;
}
}
}

View File

@@ -0,0 +1,80 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : DeleteCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
public class DeleteCommand : Command
{
public DeleteCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "rmdir";
base.Description = bot.Localization.clResourceManager.getText("Commands.DeleteFolder.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DeleteFolder.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length >= 2)
{
// parse the command line
string target = String.Empty;
for (int ct = 0; ct < args.Length; ct++)
target = target + args[ct] + " ";
target = target.TrimEnd();
// initialize results list
List<InventoryBase> found = new List<InventoryBase>();
// find the folder
found = Client.Inventory.LocalFind(Client.Inventory.Store.RootFolder.UUID, target.Split('/'), 0, true);
if (found.Count.Equals(1))
{
// move the folder to the trash folder
Client.Inventory.MoveFolder(found[0].UUID, Client.Inventory.FindFolderForType(AssetType.TrashFolder));
return String.Format(bot.Localization.clResourceManager.getText("Commands.DeleteFolder.Deleted"), found[0].Name);
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.DeleteFolder.NotFound"), "");
}
}
return bot.Localization.clResourceManager.getText("Commands.DeleteFolder.Usage");
}
}
}

View File

@@ -0,0 +1,55 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : EmptyLostAndFoundCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenMetaverse.Packets;
using bot;
class EmptyLostAndFoundCommand : Command
{
public EmptyLostAndFoundCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "emptylostandfound";
base.Description = bot.Localization.clResourceManager.getText("Commands.EmptyLostAndFound.Description");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
Client.Inventory.EmptyLostAndFound();
return bot.Localization.clResourceManager.getText("Commands.EmptyLostAndFound.Done");
}
}
}

View File

@@ -0,0 +1,55 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : EmptyTrashCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using System;
using System.Collections.Generic;
using OpenMetaverse;
using OpenMetaverse.Packets;
using bot;
class EmptyTrashCommand : Command
{
public EmptyTrashCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "emptytrash";
base.Description = bot.Localization.clResourceManager.getText("Commands.EmptyTrash.Description");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
Client.Inventory.EmptyLostAndFound();
return bot.Localization.clResourceManager.getText("Commands.EmptyTrash.Done");
}
}
}

View File

@@ -0,0 +1,96 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : GiveItemCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Text;
public class GiveItemCommand : Command
{
private InventoryManager Manager;
private OpenMetaverse.Inventory Inventory;
public GiveItemCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "give";
base.Description = bot.Localization.clResourceManager.getText("Commands.GiveItem.Description") + " " + bot.Localization.clResourceManager.getText("Commands.GiveItem.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length < 2)
{
return bot.Localization.clResourceManager.getText("Commands.GiveItem.Usage");
}
UUID dest;
if (!UUID.TryParse(args[0], out dest))
{
return bot.Localization.clResourceManager.getText("Commands.GiveItem.InvalidUUID");
}
Manager = Client.Inventory;
Inventory = Manager.Store;
string ret = "";
string nl = "\n";
for (int i = 1; i < args.Length; ++i)
{
string inventoryName = args[i];
// WARNING: Uses local copy of inventory contents, need to download them first.
List<InventoryBase> contents = Inventory.GetContents(Client.CurrentDirectory);
bool found = false;
foreach (InventoryBase b in contents)
{
if (inventoryName == b.Name || inventoryName == b.UUID.ToString())
{
found = true;
if (b is InventoryItem)
{
InventoryItem item = b as InventoryItem;
Manager.GiveItem(item.UUID, item.Name, item.AssetType, dest, true);
ret += String.Format(bot.Localization.clResourceManager.getText("Commands.GiveItem.Gave"), item.Name);
}
else
{
ret += String.Format(bot.Localization.clResourceManager.getText("Commands.GiveItem.Folder"), b.Name);
}
}
}
if (!found)
ret += String.Format(bot.Localization.clResourceManager.getText("Commands.GiveItem.NotFound"), inventoryName);
}
return ret;
}
}
}

View File

@@ -0,0 +1,85 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : InventoryCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Text;
using System.Collections.Generic;
public class InventoryCommand : Command
{
private Inventory Inventory;
private InventoryManager Manager;
public InventoryCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "i";
base.Description = bot.Localization.clResourceManager.getText("Commands.Inventory.Description");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
Manager = Client.Inventory;
Inventory = Manager.Store;
StringBuilder result = new StringBuilder();
InventoryFolder rootFolder = Inventory.RootFolder;
PrintFolder(rootFolder, result, 0);
return result.ToString();
}
void PrintFolder(InventoryFolder f, StringBuilder result, int indent)
{
List<InventoryBase> contents = Manager.FolderContents(f.UUID, Client.Self.AgentID,
true, true, InventorySortOrder.ByName, 3000);
if (contents != null)
{
foreach (InventoryBase i in contents)
{
result.AppendFormat("{0}{1} ({2})\n", new String(' ', indent * 2), i.Name, i.UUID);
if (i is InventoryFolder)
{
InventoryFolder folder = (InventoryFolder)i;
PrintFolder(folder, result, indent + 1);
}
}
}
}
}
}

View File

@@ -0,0 +1,225 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ListContentsCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
public class ListContentsCommand : Command
{
private InventoryManager Manager;
private OpenMetaverse.Inventory Inventory;
public ListContentsCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "ls";
base.Description = bot.Localization.clResourceManager.getText("Commands.ListContents.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ListContents.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length > 1)
return bot.Localization.clResourceManager.getText("Commands.ListContents.Usage");
bool longDisplay = false;
if (args.Length > 0 && args[0] == "-l")
longDisplay = true;
List<InventoryBase> contents;
Manager = Client.Inventory;
Inventory = Manager.Store;
// WARNING: Uses local copy of inventory contents, need to download them first.
if (Client.CurrentDirectory != null)
contents = Manager.FolderContents(Client.CurrentDirectory.UUID, Inventory.RootFolder.OwnerID, true, true, InventorySortOrder.SystemFoldersToTop | InventorySortOrder.FoldersByName | InventorySortOrder.ByName, 1000);
else
contents = Manager.FolderContents(Inventory.RootFolder.UUID, Inventory.RootFolder.OwnerID, true, true, InventorySortOrder.SystemFoldersToTop | InventorySortOrder.FoldersByName | InventorySortOrder.ByName, 1000);
string displayString = "";
string nl = "\n"; // New line character
// Pretty simple, just print out the contents.
if (contents != null)
{
foreach (InventoryBase b in contents)
{
if (longDisplay)
{
// Generate a nicely formatted description of the item.
// It kinda looks like the output of the unix ls.
// starts with 'd' if the inventory is a folder, '-' if not.
// 9 character permissions string
// UUID of object
// Name of object
if (b is InventoryFolder)
{
InventoryFolder folder = b as InventoryFolder;
displayString += "d--------- ";
displayString += " " + "<DIR>";
displayString += " " + DateTime.MinValue.ToShortDateString() + " " + DateTime.MinValue.ToShortTimeString();
displayString += folder.UUID.ToString().ToUpperInvariant();
displayString += " " + folder.Name;
}
else if (b is InventoryItem)
{
InventoryItem item = b as InventoryItem;
string iteminvType;
switch (item.AssetType)
{
case AssetType.Animation:
iteminvType = "<ANM>";
break;
case AssetType.Bodypart:
iteminvType = "<BDY>";
break;
case AssetType.CallingCard:
iteminvType = "<CCD>";
break;
case AssetType.Clothing:
iteminvType = "<CLT>";
break;
case AssetType.Folder:
iteminvType = "<DIR>";
break;
case AssetType.Gesture:
iteminvType = "<GES>";
break;
case AssetType.ImageJPEG:
iteminvType = "<JPG>";
break;
case AssetType.ImageTGA:
iteminvType = "<TGA>";
break;
case AssetType.Landmark:
iteminvType = "<LND>";
break;
case AssetType.LostAndFoundFolder:
iteminvType = "<L&F>";
break;
case AssetType.LSLBytecode:
iteminvType = "<LSO>";
break;
case AssetType.LSLText:
iteminvType = "<LSL>";
break;
case AssetType.Notecard:
iteminvType = "<NOT>";
break;
case AssetType.Object:
iteminvType = "<OBJ>";
break;
case AssetType.RootFolder:
iteminvType = "< / >";
break;
case AssetType.Simstate:
iteminvType = "<SIM>";
break;
case AssetType.SnapshotFolder:
iteminvType = "<SNA>";
break;
case AssetType.Sound:
iteminvType = "<OGG>";
break;
case AssetType.SoundWAV:
iteminvType = "<WAV>";
break;
case AssetType.Texture:
iteminvType = "<JP2>";
break;
case AssetType.TextureTGA:
iteminvType = "<TGA>";
break;
case AssetType.TrashFolder:
iteminvType = "<TRS>";
break;
case AssetType.Unknown:
default:
iteminvType = "<?<3F>?>";
break;
}
displayString += "-";
displayString += PermMaskString(item.Permissions.OwnerMask);
displayString += PermMaskString(item.Permissions.GroupMask);
displayString += PermMaskString(item.Permissions.EveryoneMask);
displayString += " " + iteminvType;
displayString += " " + item.CreationDate.ToShortDateString() + " " + item.CreationDate.ToShortTimeString();
displayString += " " + item.UUID.ToString().ToUpperInvariant();
displayString += " " + item.Name;
}
}
else
{
displayString += b.Name;
}
displayString += nl;
}
return displayString;
}
else
{
return bot.Localization.clResourceManager.getText("Commands.ListContents.NotReady");
}
}
/// <summary>
/// Returns a 3-character summary of the PermissionMask
/// CMT if the mask allows copy, mod and transfer
/// -MT if it disallows copy
/// --T if it only allows transfer
/// --- if it disallows everything
/// </summary>
/// <param name="mask"></param>
/// <returns></returns>
private static string PermMaskString(PermissionMask mask)
{
string str = "";
if (((uint)mask | (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
str += "C";
else
str += "-";
if (((uint)mask | (uint)PermissionMask.Modify) == (uint)PermissionMask.Modify)
str += "M";
else
str += "-";
if (((uint)mask | (uint)PermissionMask.Transfer) == (uint)PermissionMask.Transfer)
str += "T";
else
str += "-";
return str;
}
}
}

View File

@@ -0,0 +1,93 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : RezItemCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Text;
public class RezItemCommand : Command
{
private InventoryManager Manager;
private OpenMetaverse.Inventory Inventory;
public RezItemCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "rezitem";
base.Description = bot.Localization.clResourceManager.getText("Commands.RezItem.Description") + " " + bot.Localization.clResourceManager.getText("Commands.RezItem.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length != 1)
{
return bot.Localization.clResourceManager.getText("Commands.RezItem.Usage");
}
UUID dest;
if (!UUID.TryParse(args[0], out dest))
{
return bot.Localization.clResourceManager.getText("Commands.RezItem.ExpectedID");
}
Manager = Client.Inventory;
Inventory = Manager.Store;
string inventoryName = args[0];
// WARNING: Uses local copy of inventory contents, need to download them first.
List<InventoryBase> contents = Inventory.GetContents(Client.CurrentDirectory);
foreach (InventoryBase b in contents)
{
if (inventoryName == b.Name || inventoryName.ToLower() == b.UUID.ToString())
{
if (b is InventoryItem)
{
InventoryItem item = b as InventoryItem;
Vector3 Position = new Vector3();
Position = Client.Self.SimPosition;
Position.Z += 3.0f;
Manager.RequestRezFromInventory(Client.Network.CurrentSim, Quaternion.Identity, Position, item);
return String.Format(bot.Localization.clResourceManager.getText("Commands.RezItem.Requesting"), item.Name);
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.RezItem.CannotFolder"), b.Name);
}
}
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.RezItem.NotFound"), inventoryName);
}
}
}

View File

@@ -0,0 +1,82 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : TakeItemCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
public class TakeItemCommand : Command
{
public TakeItemCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "takeitem";
base.Description = bot.Localization.clResourceManager.getText("Commands.TakeItem.Description") + " " + bot.Localization.clResourceManager.getText("Commands.TakeItem.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
UUID target;
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.TakeItem.Usage");
if (UUID.TryParse(args[0], out target))
{
Primitive targetPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(
delegate(Primitive prim)
{
return prim.ID == target;
}
);
if (targetPrim != null)
{
string primName;
Client.Inventory.RequestDeRezToInventory(targetPrim.LocalID);
if (targetPrim.Properties.Name == null)
primName = "Object";
else
primName = targetPrim.Properties.Name;
return String.Format(bot.Localization.clResourceManager.getText("Commands.TakeItem.Took"), primName, targetPrim.ID);
}
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.TakeItem.NotFound"), args[0]);
}
}
}

View File

@@ -0,0 +1,169 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : TaskRunningCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using System.Threading;
public class TaskRunningCommand : Command
{
public TaskRunningCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "taskrunning";
base.Description = bot.Localization.clResourceManager.getText("Commands.TaskRunning.Description") + " " + bot.Localization.clResourceManager.getText("Commands.TaskRunning.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.TaskRunning.Usage");
uint objectLocalID;
UUID objectID;
if (!UUID.TryParse(args[0], out objectID))
return bot.Localization.clResourceManager.getText("Commands.TaskRunning.Usage");
Primitive found = Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim)
{
return prim.ID == objectID;
});
if (found != null)
objectLocalID = found.LocalID;
else
return String.Format(bot.Localization.clResourceManager.getText("Commands.TaskRunning.NotFound"), objectID);
List<InventoryBase> items = Client.Inventory.GetTaskInventory(objectID, objectLocalID, 1000 * 30);
//bool wantSet = false;
bool setTaskTo = false;
if (items != null)
{
string result = String.Empty;
string matching = String.Empty;
bool setAny = false;
if (args.Length > 1)
{
matching = args[1];
string tf;
if (args.Length > 2)
{
tf = args[2];
}
else
{
tf = matching.ToLower();
}
if (tf == "true")
{
setAny = true;
setTaskTo = true;
}
else if (tf == "false")
{
setAny = true;
setTaskTo = false;
}
}
bool wasRunning = false;
EventHandler<ScriptRunningReplyEventArgs> callback;
using (AutoResetEvent OnScriptRunningReset = new AutoResetEvent(false))
{
callback = ((object sender, ScriptRunningReplyEventArgs e) =>
{
if (e.ObjectID == objectID)
{
result += String.Format(bot.Localization.clResourceManager.getText("Commands.TaskRunning.Running"), e.IsMono, e.IsRunning);
wasRunning = e.IsRunning;
OnScriptRunningReset.Set();
}
});
Client.Inventory.ScriptRunningReply += callback;
for (int i = 0; i < items.Count; i++)
{
if (items[i] is InventoryFolder)
{
// this shouldn't happen this year
result += String.Format(bot.Localization.clResourceManager.getText("Commands.TaskRunning.Folder"), items[i].Name) + Environment.NewLine;
}
else
{
InventoryItem item = (InventoryItem)items[i];
AssetType assetType = item.AssetType;
result += String.Format(bot.Localization.clResourceManager.getText("Commands.TaskRunning.Item"), item.Name, item.Description,
assetType);
if (assetType == AssetType.LSLBytecode || assetType == AssetType.LSLText)
{
OnScriptRunningReset.Reset();
Client.Inventory.RequestGetScriptRunning(objectID, item.UUID);
if (!OnScriptRunningReset.WaitOne(10000, true))
{
result += bot.Localization.clResourceManager.getText("Commands.TaskRunning.NoInfo");
}
if (setAny && item.Name.Contains(matching))
{
if (wasRunning != setTaskTo)
{
OnScriptRunningReset.Reset();
result += bot.Localization.clResourceManager.getText("Commands.TaskRunning.Setting") + setTaskTo + " => ";
Client.Inventory.RequestSetScriptRunning(objectID, item.UUID, setTaskTo);
if (!OnScriptRunningReset.WaitOne(10000, true))
{
result += bot.Localization.clResourceManager.getText("Commands.TaskRunning.NotSet");
}
}
}
}
result += Environment.NewLine;
}
}
}
Client.Inventory.ScriptRunningReply -= callback;
return result;
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.TaskRunning.failed"), objectLocalID);
}
}
}
}

View File

@@ -0,0 +1,475 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : UploadCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
// using OpenMetaverse.Capabilities;
using OpenMetaverse.Imaging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Drawing;
using System.IO;
using OpenMetaverse.Assets;
public class UploadCommand : Command
{
AutoResetEvent UploadCompleteEvent = new AutoResetEvent(false);
UUID TextureID = UUID.Zero;
DateTime start;
AssetType detectedAssetType = AssetType.Unknown;
InventoryType detectedInventoryType = InventoryType.Unknown;
System.Text.StringBuilder returnString;
const int NOTECARD_CREATE_TIMEOUT = 1000 * 10;
public UploadCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "upload";
base.Description = bot.Localization.clResourceManager.getText("Commands.Upload.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Upload.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
returnString = new System.Text.StringBuilder();
if (args.Length >= 2)
{
string inventoryName;
string fileName;
if (args.Length != 2)
return bot.Localization.clResourceManager.getText("Commands.Upload.Usage");
TextureID = UUID.Zero;
inventoryName = args[0];
fileName = args[1];
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Upload.Loading"), fileName);
switch (System.IO.Path.GetExtension(fileName))
{
case ".animatn":
detectedAssetType = AssetType.Animation;
detectedInventoryType = InventoryType.Animation;
break;
case ".bodypart":
detectedAssetType = AssetType.Bodypart;
detectedInventoryType = InventoryType.Wearable;
break;
case ".gesture":
detectedAssetType = AssetType.Gesture;
detectedInventoryType = InventoryType.Gesture;
break;
case ".clothing":
detectedAssetType = AssetType.Clothing;
detectedInventoryType = InventoryType.Wearable;
break;
case ".jpg":
case ".tga":
case ".jp2":
case ".j2c":
detectedAssetType = AssetType.Texture;
detectedInventoryType = InventoryType.Texture;
break;
case ".notecard":
detectedAssetType = AssetType.Notecard;
detectedInventoryType = InventoryType.Notecard;
break;
case ".landmark":
detectedAssetType = AssetType.Landmark;
detectedInventoryType = InventoryType.Landmark;
break;
case ".ogg":
detectedAssetType = AssetType.Sound;
detectedInventoryType = InventoryType.Sound;
break;
case ".lsl":
detectedAssetType = AssetType.LSLText;
detectedInventoryType = InventoryType.LSL;
break;
case ".lso":
detectedAssetType = AssetType.LSLBytecode;
detectedInventoryType = InventoryType.LSL;
break;
case ".wav":
default:
return bot.Localization.clResourceManager.getText("Commands.Upload.Unsupported");
}
switch (detectedAssetType)
{
case AssetType.Texture:
byte[] jpeg2k;
try
{
jpeg2k = System.IO.File.ReadAllBytes(fileName);
}
catch (Exception e)
{
return e.Message;
}
if (jpeg2k == null)
return bot.Localization.clResourceManager.getText("Commands.Upload.FailedCompress");
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Upload.CompressedUpload"));
start = DateTime.Now;
DoUpload(jpeg2k, inventoryName);
break;
case AssetType.LSLText:
byte[] rawScriptData;
try
{
rawScriptData = System.IO.File.ReadAllBytes(fileName);
}
catch (Exception e)
{
return e.Message;
}
if (rawScriptData == null)
return bot.Localization.clResourceManager.getText("Commands.Upload.FailedLoad");
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Upload.LoadedUpload"));
start = DateTime.Now;
DoUploadScript(rawScriptData, inventoryName);
break;
case AssetType.Notecard:
byte[] rawNotecardData;
try
{
rawNotecardData = System.IO.File.ReadAllBytes(fileName);
}
catch (Exception e)
{
return e.Message;
}
if (rawNotecardData == null)
return bot.Localization.clResourceManager.getText("Commands.Upload.FailedLoad");
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Upload.LoadedUpload"));
start = DateTime.Now;
DoUploadNotecard(rawNotecardData, inventoryName);
break;
default:
byte[] rawData;
try
{
rawData = System.IO.File.ReadAllBytes(fileName);
}
catch (Exception e)
{
return e.Message;
}
if (rawData == null)
return bot.Localization.clResourceManager.getText("Commands.Upload.FailedLoad");
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Upload.LoadedUpload"));
start = DateTime.Now;
DoUpload(rawData, inventoryName);
break;
}
if (UploadCompleteEvent.WaitOne(15000, false))
{
return returnString.ToString();
}
else
{
return bot.Localization.clResourceManager.getText("Commands.Upload.Timeout");
}
}
return bot.Localization.clResourceManager.getText("Commands.Upload.Usage");
}
private void DoUploadNotecard(byte[] UploadData, string FileName)
{
try
{
string desc = String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.CreatedBy"), FileName, DateTime.Now);
AutoResetEvent emptyNoteEvent = new AutoResetEvent(false);
AutoResetEvent notecardEvent = new AutoResetEvent(false);
AssetNotecard empty = new AssetNotecard();
bool emptySuccess = false, finalUploadSuccess = false;
string message = String.Empty;
UUID notecardItemID = UUID.Zero, notecardAssetID = UUID.Zero;
// create the asset
Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.Notecard), FileName, desc, AssetType.Notecard, UUID.Random(), InventoryType.Notecard, PermissionMask.All,
delegate(bool success, InventoryItem item)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.Returned"),
success, item.UUID, item.AssetUUID));
if (success)
{
// upload the asset
#region Upload an empty notecard asset first
empty.BodyText = "\n";
empty.Encode();
Client.Inventory.RequestUploadNotecardAsset(empty.AssetData, item.UUID,
delegate(bool uploadSuccess, string status, UUID itemID, UUID assetID)
{
notecardItemID = itemID;
notecardAssetID = assetID;
emptySuccess = uploadSuccess;
message = status ?? bot.Localization.clResourceManager.getText("Commands.Upload.UnknownError");
emptyNoteEvent.Set();
});
emptyNoteEvent.WaitOne(NOTECARD_CREATE_TIMEOUT, false);
#endregion Upload an empty notecard asset first
if (emptySuccess)
{
// Upload the actual notecard asset
Client.Inventory.RequestUploadNotecardAsset(UploadData, item.UUID,
delegate(bool uploadSuccess, string status, UUID itemID, UUID assetID)
{
notecardItemID = itemID;
notecardAssetID = assetID;
finalUploadSuccess = uploadSuccess;
message = status ?? bot.Localization.clResourceManager.getText("Commands.Upload.UnknownError");
notecardEvent.Set();
});
}
else
{
notecardEvent.Set();
}
}
});
notecardEvent.WaitOne(NOTECARD_CREATE_TIMEOUT, false);
if (finalUploadSuccess)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.ReturnedNotecard"),
finalUploadSuccess.ToString(), message, notecardItemID, notecardAssetID));
bot.Console.WriteLine(String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.UploadTook"), DateTime.Now.Subtract(start)));
Client.Inventory.GiveItem(notecardItemID, FileName, AssetType.Notecard, Client.MasterKey, true);
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.UploadedUUID"), notecardAssetID);
returnString.AppendLine();
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.Sent"), Client.MasterName, Client.MasterKey);
returnString.AppendLine();
UploadCompleteEvent.Set();
}
else
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.ReturnedNotecard"),
finalUploadSuccess.ToString(), message, notecardItemID, notecardAssetID));
UploadCompleteEvent.Set();
}
}
catch (System.Exception e)
{
bot.Console.WriteLine(e.ToString());
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.ErrorNotecard"), FileName);
}
}
private void DoUploadScript(byte[] UploadData, string FileName)
{
try
{
string desc = String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.CreatedBy"), FileName, DateTime.Now);
// create the asset
Client.Inventory.RequestCreateItem(Client.Inventory.FindFolderForType(AssetType.LSLText), FileName, desc, AssetType.LSLText, UUID.Random(), InventoryType.LSL, PermissionMask.All,
delegate(bool success, InventoryItem item)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.Returned"),
success, item.UUID, item.AssetUUID));
if (success)
// upload the asset
Client.Inventory.RequestUpdateScriptAgentInventory(UploadData, item.UUID, true, new InventoryManager.ScriptUpdatedCallback(delegate(bool success1, string status, UUID itemid, UUID assetid)
{
if (success1)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.ReturnedScript"),
success1, status, itemid, assetid));
bot.Console.WriteLine(String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.UploadTook"), DateTime.Now.Subtract(start)));
Client.Inventory.GiveItem(item.UUID, FileName, AssetType.LSLText, Client.MasterKey, true);
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.UploadUUID"), assetid);
returnString.AppendLine();
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.Sent"), Client.MasterName, Client.MasterKey);
returnString.AppendLine();
UploadCompleteEvent.Set();
}
}));
});
}
catch (System.Exception e)
{
bot.Console.WriteLine(e.ToString());
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.ErrorScript"), FileName);
}
}
private void DoUpload(byte[] UploadData, string FileName)
{
if (UploadData != null)
{
string name = System.IO.Path.GetFileNameWithoutExtension(FileName);
string desc = String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.CreatedBy"), FileName, DateTime.Now);
Client.Inventory.RequestCreateItemFromAsset(UploadData, name, desc,
detectedAssetType, detectedInventoryType, Client.Inventory.FindFolderForType(detectedAssetType),
/*delegate(CapsClient client, long bytesReceived, long bytesSent, long totalBytesToReceive, long totalBytesToSend)
{
if (bytesSent > 0)
bot.Console.WriteLine(String.Format("Textura subida: {0} / {1}", bytesSent, totalBytesToSend));
},*/
// CLAUNIA: Seems that libomv changes nulled this functionality
delegate(bool success, string status, UUID itemID, UUID assetID)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.Upload.ReturnedAsset"),
success, status, itemID, assetID));
bot.Console.WriteLine(String.Format(bot.Localization.clResourceManager.getText("Commands.Upload.UploadTook"), DateTime.Now.Subtract(start)));
if (!success)
{
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.Failed"), status);
returnString.AppendLine();
}
else
{
InventoryItem item = Client.Inventory.FetchItem(itemID, Client.Self.AgentID, 1000 * 15);
item.Permissions.NextOwnerMask = PermissionMask.All;
Client.Inventory.RequestUpdateItem(item);
Client.Inventory.GiveItem(itemID, FileName, detectedAssetType, Client.MasterKey, true);
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.UploadedUUID"), assetID);
returnString.AppendLine();
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.Upload.Sent"), Client.MasterName, Client.MasterKey);
returnString.AppendLine();
}
TextureID = assetID;
UploadCompleteEvent.Set();
}
);
}
}
private byte[] LoadImage(string fileName)
{
byte[] UploadData;
string lowfilename = fileName.ToLower();
Bitmap bitmap = null;
try
{
if (lowfilename.EndsWith(".jp2") || lowfilename.EndsWith(".j2c"))
{
Image image;
ManagedImage managedImage;
// Upload JPEG2000 images untouched
UploadData = System.IO.File.ReadAllBytes(fileName);
OpenJPEG.DecodeToImage(UploadData, out managedImage, out image);
bitmap = (Bitmap)image;
}
else
{
if (lowfilename.EndsWith(".tga"))
bitmap = LoadTGAClass.LoadTGA(fileName);
else
bitmap = (Bitmap)System.Drawing.Image.FromFile(fileName);
int oldwidth = bitmap.Width;
int oldheight = bitmap.Height;
if (!IsPowerOfTwo((uint)oldwidth) || !IsPowerOfTwo((uint)oldheight))
{
Bitmap resized = new Bitmap(256, 256, bitmap.PixelFormat);
Graphics graphics = Graphics.FromImage(resized);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bitmap, 0, 0, 256, 256);
bitmap.Dispose();
bitmap = resized;
oldwidth = 256;
oldheight = 256;
}
// Handle resizing to prevent excessively large images
if (oldwidth > 1024 || oldheight > 1024)
{
int newwidth = (oldwidth > 1024) ? 1024 : oldwidth;
int newheight = (oldheight > 1024) ? 1024 : oldheight;
Bitmap resized = new Bitmap(newwidth, newheight, bitmap.PixelFormat);
Graphics graphics = Graphics.FromImage(resized);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bitmap, 0, 0, newwidth, newheight);
bitmap.Dispose();
bitmap = resized;
}
UploadData = OpenJPEG.EncodeFromImage(bitmap, false);
}
}
catch (Exception ex)
{
bot.Console.WriteLine(ex.ToString() + " SL Image Upload ");
return null;
}
return UploadData;
}
private static bool IsPowerOfTwo(uint n)
{
return (n & (n - 1)) == 0 && n != 0;
}
}
}

View File

@@ -0,0 +1,218 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : UploadImageCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using OpenMetaverse.Imaging;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Drawing;
using System.IO;
public class UploadImageCommand : Command
{
AutoResetEvent UploadCompleteEvent = new AutoResetEvent(false);
UUID TextureID = UUID.Zero;
DateTime start;
System.Text.StringBuilder returnString = new System.Text.StringBuilder();
public UploadImageCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "uploadimage";
base.Description = bot.Localization.clResourceManager.getText("Commands.UploadImage.Description") + " " + bot.Localization.clResourceManager.getText("Commands.UploadImage.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length >= 2)
{
string inventoryName;
string fileName;
if (args.Length != 2)
return bot.Localization.clResourceManager.getText("Commands.UploadImage.Usage");
TextureID = UUID.Zero;
inventoryName = args[0];
fileName = args[1];
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.UploadImage.Loading"), fileName);
byte[] jpeg2k = LoadImage(fileName);
if (jpeg2k == null)
return bot.Localization.clResourceManager.getText("Commands.UploadImage.FailedConvert");
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.UploadImage.Uploading"));
start = DateTime.Now;
DoUpload(jpeg2k, inventoryName);
if (UploadCompleteEvent.WaitOne(10000, false))
{
return returnString.ToString();
}
else
{
return bot.Localization.clResourceManager.getText("Commands.UploadImage.Timeout");
}
}
return bot.Localization.clResourceManager.getText("Commands.UploadImage.Usage");
}
private void DoUpload(byte[] UploadData, string FileName)
{
if (UploadData != null)
{
string name = System.IO.Path.GetFileNameWithoutExtension(FileName);
string desc = String.Format(bot.Localization.clResourceManager.getText("Commands.UploadImage.CreatedBy"), FileName, DateTime.Now);
Client.Inventory.RequestCreateItemFromAsset(UploadData, name, desc,
AssetType.Texture, InventoryType.Texture, Client.Inventory.FindFolderForType(AssetType.Texture),
/* delegate(CapsClient client, long bytesReceived, long bytesSent, long totalBytesToReceive, long totalBytesToSend)
{
if (bytesSent > 0)
bot.Console.WriteLine(String.Format("Textura subida: {0} / {1}", bytesSent, totalBytesToSend));
},*/
// CLAUNIA: Seems that libomv changes nulled this functionality
delegate(bool success, string status, UUID itemID, UUID assetID)
{
bot.Console.WriteLine(String.Format(
bot.Localization.clResourceManager.getText("Commands.UploadImage.Returned"),
success, status, itemID, assetID));
bot.Console.WriteLine(String.Format(bot.Localization.clResourceManager.getText("Commands.UploadImage.UploadTook"), DateTime.Now.Subtract(start)));
if (!success)
{
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.UploadImage.FailedUpload"), status);
returnString.AppendLine();
}
else
{
Client.Inventory.GiveItem(itemID, FileName, AssetType.Texture, Client.MasterKey, true);
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.UploadImage.UploadedUUID"), assetID);
returnString.AppendLine();
returnString.AppendFormat(bot.Localization.clResourceManager.getText("Commands.UploadImage.ImageSent"), Client.MasterName, Client.MasterKey);
returnString.AppendLine();
}
TextureID = assetID;
UploadCompleteEvent.Set();
}
);
}
}
private byte[] LoadImage(string fileName)
{
byte[] UploadData;
string lowfilename = fileName.ToLower();
Bitmap bitmap = null;
try
{
if (lowfilename.EndsWith(".jp2") || lowfilename.EndsWith(".j2c"))
{
Image image;
ManagedImage managedImage;
// Upload JPEG2000 images untouched
UploadData = System.IO.File.ReadAllBytes(fileName);
OpenJPEG.DecodeToImage(UploadData, out managedImage, out image);
bitmap = (Bitmap)image;
}
else
{
if (lowfilename.EndsWith(".tga"))
bitmap = LoadTGAClass.LoadTGA(fileName);
else
bitmap = (Bitmap)System.Drawing.Image.FromFile(fileName);
int oldwidth = bitmap.Width;
int oldheight = bitmap.Height;
if (!IsPowerOfTwo((uint)oldwidth) || !IsPowerOfTwo((uint)oldheight))
{
Bitmap resized = new Bitmap(256, 256, bitmap.PixelFormat);
Graphics graphics = Graphics.FromImage(resized);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bitmap, 0, 0, 256, 256);
bitmap.Dispose();
bitmap = resized;
oldwidth = 256;
oldheight = 256;
}
// Handle resizing to prevent excessively large images
if (oldwidth > 1024 || oldheight > 1024)
{
int newwidth = (oldwidth > 1024) ? 1024 : oldwidth;
int newheight = (oldheight > 1024) ? 1024 : oldheight;
Bitmap resized = new Bitmap(newwidth, newheight, bitmap.PixelFormat);
Graphics graphics = Graphics.FromImage(resized);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
graphics.DrawImage(bitmap, 0, 0, newwidth, newheight);
bitmap.Dispose();
bitmap = resized;
}
UploadData = OpenJPEG.EncodeFromImage(bitmap, false);
}
}
catch (Exception ex)
{
bot.Console.WriteLine(ex.ToString() + " SL Image Upload ");
return null;
}
return UploadData;
}
private static bool IsPowerOfTwo(uint n)
{
return (n & (n - 1)) == 0 && n != 0;
}
}
}

View File

@@ -0,0 +1,101 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : ViewNotecardCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using OpenMetaverse;
using System;
using System.Collections.Generic;
using OpenMetaverse.Assets;
public class ViewNotecardCommand : Command
{
public ViewNotecardCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "viewnote";
base.Description = bot.Localization.clResourceManager.getText("Commands.ViewNotecard.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ViewNotecard.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length < 1)
{
return bot.Localization.clResourceManager.getText("Commands.ViewNotecard.Usage");
}
UUID note;
if (!UUID.TryParse(args[0], out note))
{
return bot.Localization.clResourceManager.getText("Commands.ViewNotecard.ExpectedUUID");
}
System.Threading.AutoResetEvent waitEvent = new System.Threading.AutoResetEvent(false);
System.Text.StringBuilder result = new System.Text.StringBuilder();
// verify asset is loaded in store
if (Client.Inventory.Store.Contains(note))
{
// retrieve asset from store
InventoryItem ii = (InventoryItem)Client.Inventory.Store[note];
// make request for asset
Client.Assets.RequestInventoryAsset(ii, true,
delegate(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
result.AppendFormat(bot.Localization.clResourceManager.getText("Commands.ViewNotecard.NotecardData"), Utils.BytesToString(asset.AssetData));
waitEvent.Set();
}
}
);
// wait for reply or timeout
if (!waitEvent.WaitOne(10000, false))
{
result.Append(bot.Localization.clResourceManager.getText("Commands.ViewNotecard.Timeout"));
}
// unsubscribe from reply event
}
else
{
result.Append(bot.Localization.clResourceManager.getText("Commands.ViewNotecard.NotFound"));
}
// return results
return result.ToString();
}
}
}