Open sourced NatiBot
This commit is contained in:
87
SLBot/bot/Commands/Prims/BuyCommand.cs
Normal file
87
SLBot/bot/Commands/Prims/BuyCommand.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : BuyCommand.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.Threading;
|
||||
|
||||
public class BuyCommand : Command
|
||||
{
|
||||
private ManualResetEvent ObjectPropertiesEvent = new ManualResetEvent(false);
|
||||
|
||||
public BuyCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "buy";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.Buy.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Buy.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
UUID target;
|
||||
ObjectPropertiesEvent = new ManualResetEvent(false);
|
||||
|
||||
if (args.Length != 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.Buy.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)
|
||||
{
|
||||
Client.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
||||
Client.Objects.RequestObject(Client.Network.CurrentSim, targetPrim.LocalID);
|
||||
ObjectPropertiesEvent.WaitOne(10000, false);
|
||||
Client.Objects.ObjectProperties -= Objects_OnObjectProperties;
|
||||
Client.Objects.BuyObject(Client.Network.CurrentSim, targetPrim.LocalID, targetPrim.Properties.SaleType, targetPrim.Properties.SalePrice, Client.GroupID, Client.Inventory.FindFolderForType(AssetType.RootFolder));
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Buy.Bought"), targetPrim.Properties.Name);
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Buy.NotFound"), args[0]);
|
||||
}
|
||||
|
||||
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
ObjectPropertiesEvent.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
211
SLBot/bot/Commands/Prims/ChangePermsCommand.cs
Normal file
211
SLBot/bot/Commands/Prims/ChangePermsCommand.cs
Normal file
@@ -0,0 +1,211 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ChangePermsCommand.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 ChangePermsCommand : Command
|
||||
{
|
||||
AutoResetEvent GotPermissionsEvent = new AutoResetEvent(false);
|
||||
UUID SelectedObject = UUID.Zero;
|
||||
Dictionary<UUID, Primitive> Objects = new Dictionary<UUID, Primitive>();
|
||||
PermissionMask Perms = PermissionMask.None;
|
||||
bool PermsSent = false;
|
||||
int PermCount = 0;
|
||||
|
||||
public ChangePermsCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
SecondLifeBot.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
||||
base.Name = "changeperms";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.ChangePerms.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ChangePerms.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
UUID rootID;
|
||||
Primitive rootPrim;
|
||||
List<Primitive> childPrims;
|
||||
List<uint> localIDs = new List<uint>();
|
||||
|
||||
// Reset class-wide variables
|
||||
PermsSent = false;
|
||||
Objects.Clear();
|
||||
Perms = PermissionMask.None;
|
||||
PermCount = 0;
|
||||
|
||||
if (args.Length < 1 || args.Length > 4)
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.Usage");
|
||||
|
||||
if (!UUID.TryParse(args[0], out rootID))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.Usage");
|
||||
|
||||
for (int i = 1; i < args.Length; i++)
|
||||
{
|
||||
switch (args[i].ToLower())
|
||||
{
|
||||
case "copy":
|
||||
Perms |= PermissionMask.Copy;
|
||||
break;
|
||||
case "mod":
|
||||
Perms |= PermissionMask.Modify;
|
||||
break;
|
||||
case "xfer":
|
||||
Perms |= PermissionMask.Transfer;
|
||||
break;
|
||||
default:
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.Usage");
|
||||
}
|
||||
}
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.ChangePerms.Permisson"), Perms.ToString());
|
||||
|
||||
// Find the requested prim
|
||||
rootPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == rootID;
|
||||
});
|
||||
if (rootPrim == null)
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ChangePerms.NotFound"), rootID.ToString());
|
||||
else
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.ChangePerms.Found"), rootPrim.ID.ToString());
|
||||
|
||||
if (rootPrim.ParentID != 0)
|
||||
{
|
||||
// This is not actually a root prim, find the root
|
||||
if (!Client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(rootPrim.ParentID, out rootPrim))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.RootNotFound");
|
||||
else
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.ChangePerms.Root"), rootPrim.ID.ToString());
|
||||
}
|
||||
|
||||
// Find all of the child objects linked to this root
|
||||
childPrims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ParentID == rootPrim.LocalID;
|
||||
});
|
||||
|
||||
// Build a dictionary of primitives for referencing later
|
||||
Objects[rootPrim.ID] = rootPrim;
|
||||
for (int i = 0; i < childPrims.Count; i++)
|
||||
Objects[childPrims[i].ID] = childPrims[i];
|
||||
|
||||
// Build a list of all the localIDs to set permissions for
|
||||
localIDs.Add(rootPrim.LocalID);
|
||||
for (int i = 0; i < childPrims.Count; i++)
|
||||
localIDs.Add(childPrims[i].LocalID);
|
||||
|
||||
// Go through each of the three main permissions and enable or disable them
|
||||
#region Set Linkset Permissions
|
||||
|
||||
PermCount = 0;
|
||||
if ((Perms & PermissionMask.Modify) == PermissionMask.Modify)
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, true);
|
||||
else
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, false);
|
||||
PermsSent = true;
|
||||
|
||||
if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.ModFail");
|
||||
|
||||
PermCount = 0;
|
||||
if ((Perms & PermissionMask.Copy) == PermissionMask.Copy)
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, true);
|
||||
else
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, false);
|
||||
PermsSent = true;
|
||||
|
||||
if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.CopyFail");
|
||||
|
||||
PermCount = 0;
|
||||
if ((Perms & PermissionMask.Transfer) == PermissionMask.Transfer)
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, true);
|
||||
else
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, false);
|
||||
PermsSent = true;
|
||||
|
||||
if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ChangePerms.XferFail");
|
||||
|
||||
#endregion Set Linkset Permissions
|
||||
|
||||
// Check each prim for task inventory and set permissions on the task inventory
|
||||
int taskItems = 0;
|
||||
foreach (Primitive prim in Objects.Values)
|
||||
{
|
||||
if ((prim.Flags & PrimFlags.InventoryEmpty) == 0)
|
||||
{
|
||||
List<InventoryBase> items = Client.Inventory.GetTaskInventory(prim.ID, prim.LocalID, 1000 * 30);
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (!(items[i] is InventoryFolder))
|
||||
{
|
||||
InventoryItem item = (InventoryItem)items[i];
|
||||
item.Permissions.NextOwnerMask = Perms;
|
||||
|
||||
Client.Inventory.UpdateTaskInventory(prim.LocalID, item);
|
||||
++taskItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ChangePerms.Done"), Perms.ToString(), localIDs.Count,
|
||||
taskItems);
|
||||
}
|
||||
|
||||
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
if (PermsSent)
|
||||
{
|
||||
if (Objects.ContainsKey(e.Properties.ObjectID))
|
||||
{
|
||||
// FIXME: Confirm the current operation against properties.Permissions.NextOwnerMask
|
||||
|
||||
++PermCount;
|
||||
if (PermCount >= Objects.Count)
|
||||
GotPermissionsEvent.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
658
SLBot/bot/Commands/Prims/DumpAttachmentCommand.cs
Normal file
658
SLBot/bot/Commands/Prims/DumpAttachmentCommand.cs
Normal file
@@ -0,0 +1,658 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : DumpAttachmentCommand.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.Utilities;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using OpenMetaverse.StructuredData;
|
||||
using OpenMetaverse.Assets;
|
||||
|
||||
public class DumpAttachmentCommand : Command
|
||||
{
|
||||
List<UUID> Textures = new List<UUID>();
|
||||
AutoResetEvent GotPermissionsEvent = new AutoResetEvent(false);
|
||||
Primitive.ObjectProperties Properties;
|
||||
bool GotPermissions = false;
|
||||
UUID SelectedObject = UUID.Zero;
|
||||
Dictionary<UUID, Primitive> PrimsWaiting = new Dictionary<UUID, Primitive>();
|
||||
AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
|
||||
private string DestinationDirectory = null;
|
||||
|
||||
public DumpAttachmentCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
SecondLifeBot.Objects.ObjectPropertiesFamily += new EventHandler<ObjectPropertiesFamilyEventArgs>(Objects_OnObjectPropertiesFamily);
|
||||
SecondLifeBot.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
||||
SecondLifeBot.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
|
||||
|
||||
base.Client = SecondLifeBot;
|
||||
base.Name = "dumpattachment";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (args.Length < 2)
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Usage");
|
||||
}
|
||||
|
||||
switch (args[1])
|
||||
{
|
||||
// Chest
|
||||
case "Chest":
|
||||
break;
|
||||
// Skull
|
||||
case "Skull":
|
||||
break;
|
||||
// Left shoulder
|
||||
case "LeftShoulder":
|
||||
break;
|
||||
// Right shoulder
|
||||
case "RightShoulder":
|
||||
break;
|
||||
// Left hand
|
||||
case "LeftHand":
|
||||
break;
|
||||
// Right hand
|
||||
case "RightHand":
|
||||
break;
|
||||
// Left foot
|
||||
case "LeftFoot":
|
||||
break;
|
||||
// Right foot
|
||||
case "RightFoot":
|
||||
break;
|
||||
// Spine
|
||||
case "Spine":
|
||||
break;
|
||||
// Pelvis
|
||||
case "Pelvis":
|
||||
break;
|
||||
// Mouth
|
||||
case "Mouth":
|
||||
break;
|
||||
// Chin
|
||||
case "Chin":
|
||||
break;
|
||||
// Left ear
|
||||
case "LeftEar":
|
||||
break;
|
||||
// Right ear
|
||||
case "RightEar":
|
||||
break;
|
||||
// Left eyeball
|
||||
case "LeftEyeball":
|
||||
break;
|
||||
// Right eyeball
|
||||
case "RightEyeball":
|
||||
break;
|
||||
// Nose
|
||||
case "Nose":
|
||||
break;
|
||||
// Right upper arm
|
||||
case "RightUpperArm":
|
||||
break;
|
||||
// Right forearm
|
||||
case "RightForearm":
|
||||
break;
|
||||
// Left upper arm
|
||||
case "LeftUpperArm":
|
||||
break;
|
||||
// Left forearm
|
||||
case "LeftForearm":
|
||||
break;
|
||||
// Right hip
|
||||
case "RightHip":
|
||||
break;
|
||||
// Right upper leg
|
||||
case "RightUpperLeg":
|
||||
break;
|
||||
// Right lower leg
|
||||
case "RightLowerLeg":
|
||||
break;
|
||||
// Left hip
|
||||
case "LeftHip":
|
||||
break;
|
||||
// Left upper leg
|
||||
case "LeftUpperLeg":
|
||||
break;
|
||||
// Left lower leg
|
||||
case "LeftLowerLeg":
|
||||
break;
|
||||
// Stomach
|
||||
case "Stomach":
|
||||
break;
|
||||
// Left pectoral
|
||||
case "LeftPec":
|
||||
break;
|
||||
// Right pectoral
|
||||
case "RightPec":
|
||||
break;
|
||||
// Emerald viewer extra attachment points
|
||||
// Chest 2
|
||||
case "Chest2":
|
||||
break;
|
||||
// Skull 2
|
||||
case "Skull2":
|
||||
break;
|
||||
// Left shoulder 2
|
||||
case "LeftShoulder2":
|
||||
break;
|
||||
// Right shoulder 2
|
||||
case "RightShoulder2":
|
||||
break;
|
||||
// Left hand 2
|
||||
case "LeftHand2":
|
||||
break;
|
||||
// Right hand 2
|
||||
case "RightHand2":
|
||||
break;
|
||||
// Left foot 2
|
||||
case "LeftFoot2":
|
||||
break;
|
||||
// Right foot 2
|
||||
case "RightFoot2":
|
||||
break;
|
||||
// Spine 2
|
||||
case "Spine2":
|
||||
break;
|
||||
// Pelvis 2
|
||||
case "Pelvis2":
|
||||
break;
|
||||
// Mouth 2
|
||||
case "Mouth2":
|
||||
break;
|
||||
// Chin 2
|
||||
case "Chin2":
|
||||
break;
|
||||
// Left ear 2
|
||||
case "LeftEar2":
|
||||
break;
|
||||
// Right ear 2
|
||||
case "RightEar2":
|
||||
break;
|
||||
// Left eyeball 2
|
||||
case "LeftEyeball2":
|
||||
break;
|
||||
// Right eyeball 2
|
||||
case "RightEyeball2":
|
||||
break;
|
||||
// Nose 2
|
||||
case "Nose2":
|
||||
break;
|
||||
// Right upper arm 2
|
||||
case "RightUpperArm2":
|
||||
break;
|
||||
// Right forearm 2
|
||||
case "RightForearm2":
|
||||
break;
|
||||
// Left upper arm 2
|
||||
case "LeftUpperArm2":
|
||||
break;
|
||||
// Left forearm 2
|
||||
case "LeftForearm2":
|
||||
break;
|
||||
// Right hip 2
|
||||
case "RightHip2":
|
||||
break;
|
||||
// Right upper leg 2
|
||||
case "RightUpperLeg2":
|
||||
break;
|
||||
// Right lower leg 2
|
||||
case "RightLowerLeg2":
|
||||
break;
|
||||
// Left hip 2
|
||||
case "LeftHip2":
|
||||
break;
|
||||
// Left upper leg 2
|
||||
case "LeftUpperLeg2":
|
||||
break;
|
||||
// Left lower leg 2
|
||||
case "LeftLowerLeg2":
|
||||
break;
|
||||
// Stomach 2
|
||||
case "Stomach2":
|
||||
break;
|
||||
// Left pectoral 2
|
||||
case "LeftPec2":
|
||||
break;
|
||||
// Right pectoral 2
|
||||
case "RightPec2":
|
||||
break;
|
||||
// Left Knee
|
||||
case "LeftKnee":
|
||||
break;
|
||||
// Right Knee
|
||||
case "RightKnee":
|
||||
break;
|
||||
// Bridge
|
||||
case "Bridge":
|
||||
break;
|
||||
default:
|
||||
return bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Invalid");
|
||||
}
|
||||
|
||||
Avatar av = base.Client.Network.CurrentSim.ObjectsAvatars.Find(
|
||||
delegate(Avatar a)
|
||||
{
|
||||
return a.ID.Equals((UUID)args[0]);
|
||||
}
|
||||
);
|
||||
|
||||
Program.NBStats.AddStatData(String.Format("{0}: {1} dumping attachment {2} of {3}.", DateTime.Now.ToString(), Client, args[1], args[0]));
|
||||
|
||||
List<Primitive> list = base.Client.Network.CurrentSim.ObjectsPrimitives.FindAll(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ParentID == av.LocalID;
|
||||
});
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
Primitive primitive = list[i];
|
||||
NBAttachmentPoint point = StateToAttachmentPoint(primitive.PrimData.State);
|
||||
|
||||
if (point.ToString() == args[1])
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (args[1] == "false")
|
||||
{
|
||||
result = ExportAttachment(primitive.ID, primitive.LocalID, point.ToString(), (UUID)args[0], false);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ExportAttachment(primitive.ID, primitive.LocalID, point.ToString(), (UUID)args[0], true);
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
builder.AppendLine(string.Format(bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Success"), new object[] { point }));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AppendLine(string.Format(bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Fail"), new object[] { point }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DestinationDirectory = null;
|
||||
|
||||
//builder.AppendLine("Exportados " + list.Count + " objetos");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public string CreateFileName(string AttachmentPointName, string PrimName)
|
||||
{
|
||||
string corrected_PrimName;
|
||||
string FinalName;
|
||||
|
||||
if (PrimName == "")
|
||||
corrected_PrimName = "Object";
|
||||
else
|
||||
corrected_PrimName = PrimName;
|
||||
|
||||
corrected_PrimName = corrected_PrimName.Replace(" ", "_");
|
||||
corrected_PrimName = corrected_PrimName.Replace(":", ";");
|
||||
corrected_PrimName = corrected_PrimName.Replace("*", "+");
|
||||
corrected_PrimName = corrected_PrimName.Replace("|", "I");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\\", "[");
|
||||
corrected_PrimName = corrected_PrimName.Replace("/", "]");
|
||||
corrected_PrimName = corrected_PrimName.Replace("?", "¿");
|
||||
corrected_PrimName = corrected_PrimName.Replace(">", "}");
|
||||
corrected_PrimName = corrected_PrimName.Replace("<", "{");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\"", "'");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\n", " ");
|
||||
|
||||
FinalName = corrected_PrimName + " (" + AttachmentPointName + ").xml";
|
||||
|
||||
return FinalName;
|
||||
}
|
||||
|
||||
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
|
||||
{
|
||||
string TextureDestination;
|
||||
|
||||
if (DestinationDirectory == null)
|
||||
TextureDestination = "attachments/Textures/";
|
||||
else
|
||||
TextureDestination = DestinationDirectory + "Textures/";
|
||||
|
||||
if (!Directory.Exists(TextureDestination))
|
||||
Directory.CreateDirectory(TextureDestination);
|
||||
|
||||
if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
|
||||
{
|
||||
lock (Textures)
|
||||
Textures.Remove(asset.AssetID);
|
||||
|
||||
if (state == TextureRequestState.Finished)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(TextureDestination + asset.AssetID + ".jp2", asset.AssetData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client);
|
||||
}
|
||||
|
||||
if (asset.Decode())
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes(TextureDestination + asset.AssetID + ".tga", asset.Image.ExportTGA());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.Message, Helpers.LogLevel.Error, Client);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.FailDecode"), asset.AssetID);
|
||||
}
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.ImageDownloaded"), asset.AssetID);
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.FailDownload"), asset.AssetID, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
|
||||
{
|
||||
if (e.SourceID == Client.MasterKey)
|
||||
{
|
||||
//Client.DebugLog("Master is now selecting " + targetID.ToString());
|
||||
SelectedObject = e.TargetID;
|
||||
}
|
||||
}
|
||||
|
||||
public static NBAttachmentPoint StateToAttachmentPoint(uint state)
|
||||
{
|
||||
const uint ATTACHMENT_MASK = 0xF0;
|
||||
uint fixedState = (((byte)state & ATTACHMENT_MASK) >> 4) | (((byte)state & ~ATTACHMENT_MASK) << 4);
|
||||
return (NBAttachmentPoint)fixedState;
|
||||
}
|
||||
|
||||
private static bool CompareLocalIDs(uint id, uint SearchedID)
|
||||
{
|
||||
if (id == SearchedID)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ExportAttachment(UUID ObjectUUID, uint LocalID, string AttachmentPosition, UUID AvatarID, bool DumpImages)
|
||||
{
|
||||
Predicate<Primitive> match = null;
|
||||
UUID id;
|
||||
|
||||
//UUID.TryParse(ObjectUUID, out id);
|
||||
id = ObjectUUID;
|
||||
|
||||
Primitive primitive = base.Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == id;
|
||||
});
|
||||
if (primitive != null)
|
||||
{
|
||||
uint localid = LocalID;
|
||||
base.Client.Objects.SelectObject(base.Client.Network.CurrentSim, LocalID);
|
||||
base.Client.Objects.RequestObjectPropertiesFamily(base.Client.Network.CurrentSim, id);
|
||||
this.GotPermissionsEvent.WaitOne(0x2710, false);
|
||||
#if !DEBUG
|
||||
if (!GotPermissions)
|
||||
{
|
||||
//return "Couldn't fetch permissions for the requested object, try again";
|
||||
}
|
||||
else
|
||||
{
|
||||
GotPermissions = false;
|
||||
if (Properties.OwnerID != Client.Self.AgentID &&
|
||||
Properties.OwnerID != Client.MasterKey || Properties.Permissions.EveryoneMask != PermissionMask.All)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
this.GotPermissions = false;
|
||||
if (match == null)
|
||||
{
|
||||
match = delegate(Primitive prim)
|
||||
{
|
||||
if (prim.LocalID != localid)
|
||||
{
|
||||
return prim.ParentID == localid;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
List<Primitive> objects = base.Client.Network.CurrentSim.ObjectsPrimitives.FindAll(match);
|
||||
List<Primitive> objects2 = new List<Primitive>();
|
||||
|
||||
bool complete = RequestObjectProperties(objects2, 250);
|
||||
|
||||
if (!complete)
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.DumpAttachment.NotProperties"));
|
||||
foreach (UUID uuid in PrimsWaiting.Keys)
|
||||
bot.Console.WriteLine(uuid.ToString());
|
||||
}
|
||||
|
||||
List<uint> ObjectsIDs = new List<uint>();
|
||||
|
||||
for (int j = 0; j < objects.Count; j++)
|
||||
{
|
||||
ObjectsIDs.Add(objects[j].LocalID);
|
||||
}
|
||||
|
||||
for (int j = 0; j < objects.Count; j++)
|
||||
{
|
||||
base.Client.Objects.SelectObject(base.Client.Network.CurrentSim, objects[j].LocalID);
|
||||
}
|
||||
|
||||
for (int j = 0; j < objects.Count; j++)
|
||||
{
|
||||
Primitive IntermediatePrimitive;
|
||||
|
||||
IntermediatePrimitive = objects[j];
|
||||
|
||||
if (ObjectsIDs.FindIndex(delegate(uint lid)
|
||||
{
|
||||
return lid == IntermediatePrimitive.ParentID;
|
||||
}) == -1)
|
||||
{
|
||||
IntermediatePrimitive.ParentID = 0;
|
||||
}
|
||||
|
||||
objects2.Add(IntermediatePrimitive);
|
||||
}
|
||||
|
||||
for (int j = 0; j < objects.Count; j++)
|
||||
{
|
||||
base.Client.Objects.DeselectObject(base.Client.Network.CurrentSim, objects[j].LocalID);
|
||||
}
|
||||
|
||||
string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(objects2));
|
||||
try
|
||||
{
|
||||
string AvatarName;
|
||||
|
||||
if (DestinationDirectory == null)
|
||||
{
|
||||
if (!this.Client.key2Name(AvatarID, out AvatarName))
|
||||
AvatarName = AvatarID.ToString();
|
||||
|
||||
DestinationDirectory = "./attachments/" + AvatarName + "_" +
|
||||
System.DateTime.Now.Year.ToString() +
|
||||
System.DateTime.Now.Month.ToString() +
|
||||
System.DateTime.Now.Day.ToString() +
|
||||
System.DateTime.Now.Hour.ToString() +
|
||||
//System.DateTime.Now.Minute.ToString() +
|
||||
//System.DateTime.Now.Second.ToString() +
|
||||
"/";
|
||||
}
|
||||
|
||||
string RealFileName;
|
||||
|
||||
if (objects[0].Properties != null)
|
||||
RealFileName = CreateFileName(AttachmentPosition, objects[0].Properties.Name);
|
||||
else
|
||||
RealFileName = CreateFileName(AttachmentPosition, "Object");
|
||||
|
||||
if (!Directory.Exists(DestinationDirectory))
|
||||
Directory.CreateDirectory(DestinationDirectory);
|
||||
File.WriteAllText(DestinationDirectory + RealFileName, output);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
base.Client.Objects.DeselectObject(base.Client.Network.CurrentSim, LocalID);
|
||||
bot.Console.WriteLine(e.Message);
|
||||
return false;
|
||||
}
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.DumpAttachment.Exported"), objects2.Count, DestinationDirectory, AttachmentPosition);
|
||||
|
||||
// Create a list of all of the textures to download
|
||||
List<ImageRequest> textureRequests = new List<ImageRequest>();
|
||||
|
||||
if (DumpImages == true)
|
||||
{
|
||||
lock (Textures)
|
||||
{
|
||||
for (int i = 0; i < objects2.Count; i++)
|
||||
{
|
||||
Primitive prim = objects2[i];
|
||||
|
||||
if (prim.Textures.DefaultTexture.TextureID != Primitive.TextureEntry.WHITE_TEXTURE &&
|
||||
!Textures.Contains(prim.Textures.DefaultTexture.TextureID))
|
||||
{
|
||||
Textures.Add(prim.Textures.DefaultTexture.TextureID);
|
||||
}
|
||||
|
||||
for (int j = 0; j < prim.Textures.FaceTextures.Length; j++)
|
||||
{
|
||||
if (prim.Textures.FaceTextures[j] != null &&
|
||||
prim.Textures.FaceTextures[j].TextureID != Primitive.TextureEntry.WHITE_TEXTURE &&
|
||||
!Textures.Contains(prim.Textures.FaceTextures[j].TextureID))
|
||||
{
|
||||
Textures.Add(prim.Textures.FaceTextures[j].TextureID);
|
||||
}
|
||||
}
|
||||
|
||||
if (prim.Sculpt != null)
|
||||
{
|
||||
if (prim.Sculpt.SculptTexture != UUID.Zero && !Textures.Contains(prim.Sculpt.SculptTexture))
|
||||
{
|
||||
Textures.Add(prim.Sculpt.SculptTexture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create a request list from all of the images
|
||||
for (int i = 0; i < Textures.Count; i++)
|
||||
textureRequests.Add(new ImageRequest(Textures[i], ImageType.Normal, 1013000.0f, 0));
|
||||
}
|
||||
|
||||
// Download all of the textures in the export list
|
||||
foreach (ImageRequest request in textureRequests)
|
||||
{
|
||||
base.Client.Assets.RequestImage(request.ImageID, request.Type, Assets_OnImageReceived);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
base.Client.Objects.DeselectObject(base.Client.Network.CurrentSim, LocalID);
|
||||
return true;
|
||||
//return ("XML exported, began downloading " + this.Textures.Count + " textures");
|
||||
}
|
||||
//return string.Concat(new object[] { "Couldn't find UUID ", id.ToString(), " in the ", base.Client.Network.CurrentSim.ObjectsPrimitives.Count, "objects currently indexed in the current simulator" });
|
||||
return false;
|
||||
}
|
||||
|
||||
void Objects_OnObjectPropertiesFamily(object sender, ObjectPropertiesFamilyEventArgs e)
|
||||
{
|
||||
Properties = new Primitive.ObjectProperties();
|
||||
Properties.SetFamilyProperties(e.Properties);
|
||||
GotPermissions = true;
|
||||
GotPermissionsEvent.Set();
|
||||
}
|
||||
|
||||
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
PrimsWaiting.Remove(e.Properties.ObjectID);
|
||||
|
||||
if (PrimsWaiting.Count == 0)
|
||||
AllPropertiesReceived.Set();
|
||||
}
|
||||
}
|
||||
|
||||
private bool RequestObjectProperties(List<Primitive> objects, int msPerRequest)
|
||||
{
|
||||
// Create an array of the local IDs of all the prims we are requesting properties for
|
||||
uint[] localids = new uint[objects.Count];
|
||||
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
PrimsWaiting.Clear();
|
||||
|
||||
for (int i = 0; i < objects.Count; ++i)
|
||||
{
|
||||
localids[i] = objects[i].LocalID;
|
||||
PrimsWaiting.Add(objects[i].ID, objects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Client.Objects.SelectObjects(Client.Network.CurrentSim, localids);
|
||||
|
||||
return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
101
SLBot/bot/Commands/Prims/DumpAttachmentsCommand.cs
Normal file
101
SLBot/bot/Commands/Prims/DumpAttachmentsCommand.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : DumpAttachmentsCommand.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.Utilities;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using OpenMetaverse.StructuredData;
|
||||
|
||||
public class DumpAttachmentsCommand : Command
|
||||
{
|
||||
private Object thisLock = new Object();
|
||||
|
||||
public DumpAttachmentsCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Client = SecondLifeBot;
|
||||
base.Name = "dumpattachments";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.DumpAttachments.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DumpAttachments.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.DumpAttachments.Usage");
|
||||
}
|
||||
|
||||
Avatar av = base.Client.Network.CurrentSim.ObjectsAvatars.Find(
|
||||
delegate(Avatar a)
|
||||
{
|
||||
return a.ID.Equals((UUID)args[0]);
|
||||
}
|
||||
);
|
||||
|
||||
List<Primitive> list = base.Client.Network.CurrentSim.ObjectsPrimitives.FindAll(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ParentID == av.LocalID;
|
||||
});
|
||||
|
||||
Program.NBStats.AddStatData(String.Format("{0}: {1} dumping all attachments of {2}.", DateTime.Now.ToString(), Client, args[0]));
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
lock (thisLock)
|
||||
{
|
||||
string cmd;
|
||||
|
||||
Primitive primitive = list[i];
|
||||
NBAttachmentPoint point = StateToAttachmentPoint(primitive.PrimData.State);
|
||||
|
||||
cmd = "dumpattachment " + args[0] + " " + point.ToString()/* + " false"*/;
|
||||
|
||||
this.Client.DoCommand(cmd, fromAgentID, fromSL);
|
||||
}
|
||||
}
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.DumpAttachments.Done"), list.Count);
|
||||
}
|
||||
|
||||
public static NBAttachmentPoint StateToAttachmentPoint(uint state)
|
||||
{
|
||||
const uint ATTACHMENT_MASK = 0xF0;
|
||||
uint fixedState = (((byte)state & ATTACHMENT_MASK) >> 4) | (((byte)state & ~ATTACHMENT_MASK) << 4);
|
||||
return (NBAttachmentPoint)fixedState;
|
||||
}
|
||||
}
|
||||
}
|
||||
314
SLBot/bot/Commands/Prims/ExportCommand.cs
Normal file
314
SLBot/bot/Commands/Prims/ExportCommand.cs
Normal file
@@ -0,0 +1,314 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ExportCommand.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.StructuredData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using OpenMetaverse.Assets;
|
||||
|
||||
public class ExportCommand : Command
|
||||
{
|
||||
List<UUID> Textures = new List<UUID>();
|
||||
AutoResetEvent GotPermissionsEvent = new AutoResetEvent(false);
|
||||
Primitive.ObjectProperties Properties;
|
||||
bool GotPermissions = false;
|
||||
UUID SelectedObject = UUID.Zero;
|
||||
|
||||
Dictionary<UUID, Primitive> PrimsWaiting = new Dictionary<UUID, Primitive>();
|
||||
AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
|
||||
|
||||
public ExportCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
SecondLifeBot.Objects.ObjectPropertiesFamily += new EventHandler<ObjectPropertiesFamilyEventArgs>(Objects_OnObjectPropertiesFamily);
|
||||
SecondLifeBot.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
||||
SecondLifeBot.Avatars.ViewerEffectPointAt += new EventHandler<ViewerEffectPointAtEventArgs>(Avatars_ViewerEffectPointAt);
|
||||
base.Name = "export";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.Export.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Export.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
if (args.Length != 2 && !(args.Length == 1 && SelectedObject != UUID.Zero))
|
||||
return bot.Localization.clResourceManager.getText("Commands.Export.Usage");
|
||||
|
||||
UUID id;
|
||||
uint localid;
|
||||
string file;
|
||||
|
||||
if (args.Length == 2)
|
||||
{
|
||||
file = args[1];
|
||||
if (!UUID.TryParse(args[0], out id))
|
||||
return bot.Localization.clResourceManager.getText("Commands.Export.Usage");
|
||||
}
|
||||
else
|
||||
{
|
||||
file = args[0];
|
||||
id = SelectedObject;
|
||||
}
|
||||
|
||||
Primitive exportPrim;
|
||||
|
||||
exportPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == id;
|
||||
}
|
||||
);
|
||||
|
||||
Program.NBStats.AddStatData(String.Format("{0}: {1} exporting object {2} on sim {3}.", DateTime.Now.ToString(), Client, id, Client.Network.CurrentSim.Name));
|
||||
|
||||
if (exportPrim != null)
|
||||
{
|
||||
if (exportPrim.ParentID != 0)
|
||||
localid = exportPrim.ParentID;
|
||||
else
|
||||
localid = exportPrim.LocalID;
|
||||
|
||||
// Check for export permission first
|
||||
Client.Objects.SelectObject(Client.Network.CurrentSim, localid);
|
||||
Client.Objects.RequestObjectPropertiesFamily(Client.Network.CurrentSim, id);
|
||||
GotPermissionsEvent.WaitOne(1000 * 10, false);
|
||||
|
||||
#if !DEBUG
|
||||
if (!GotPermissions)
|
||||
{
|
||||
//return "Couldn't fetch permissions for the requested object, try again";
|
||||
}
|
||||
else
|
||||
{
|
||||
GotPermissions = false;
|
||||
if (Properties.OwnerID != Client.Self.AgentID &&
|
||||
Properties.OwnerID != Client.MasterKey || Properties.Permissions.EveryoneMask != PermissionMask.All)
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("NoPermissions");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
List<Primitive> prims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
return (prim.LocalID == localid || prim.ParentID == localid);
|
||||
}
|
||||
);
|
||||
|
||||
bool complete = RequestObjectProperties(prims, 250);
|
||||
|
||||
if (!complete)
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Export.NotProperties"));
|
||||
//foreach (UUID uuid in PrimsWaiting.Keys)
|
||||
// bot.Console.WriteLine(uuid.ToString());
|
||||
}
|
||||
|
||||
string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(prims));
|
||||
|
||||
if (Directory.Exists("objects/") == false)
|
||||
{
|
||||
Directory.CreateDirectory("objects/");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText("objects/" + file, output);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Export.Exported"), prims.Count, file);
|
||||
|
||||
// Create a list of all of the textures to download
|
||||
List<ImageRequest> textureRequests = new List<ImageRequest>();
|
||||
|
||||
lock (Textures)
|
||||
{
|
||||
for (int i = 0; i < prims.Count; i++)
|
||||
{
|
||||
Primitive prim = prims[i];
|
||||
|
||||
if (prim.Textures != null)
|
||||
{
|
||||
if (prim.Textures.DefaultTexture != null) //WTF
|
||||
{
|
||||
if (prim.Textures.DefaultTexture.TextureID != Primitive.TextureEntry.WHITE_TEXTURE &&
|
||||
!Textures.Contains(prim.Textures.DefaultTexture.TextureID))
|
||||
{
|
||||
Textures.Add(prim.Textures.DefaultTexture.TextureID);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 0; j < prim.Textures.FaceTextures.Length; j++)
|
||||
{
|
||||
if (prim.Textures.FaceTextures[j] != null &&
|
||||
prim.Textures.FaceTextures[j].TextureID != Primitive.TextureEntry.WHITE_TEXTURE &&
|
||||
!Textures.Contains(prim.Textures.FaceTextures[j].TextureID))
|
||||
{
|
||||
Textures.Add(prim.Textures.FaceTextures[j].TextureID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (prim.Sculpt != null && prim.Sculpt.SculptTexture != UUID.Zero && !Textures.Contains(prim.Sculpt.SculptTexture))
|
||||
{
|
||||
Textures.Add(prim.Sculpt.SculptTexture);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a request list from all of the images
|
||||
for (int i = 0; i < Textures.Count; i++)
|
||||
textureRequests.Add(new ImageRequest(Textures[i], ImageType.Normal, 1013000.0f, 0));
|
||||
}
|
||||
|
||||
// Download all of the textures in the export list
|
||||
foreach (ImageRequest request in textureRequests)
|
||||
{
|
||||
Client.Assets.RequestImage(request.ImageID, request.Type, Assets_OnImageReceived);
|
||||
}
|
||||
|
||||
Client.Objects.DeselectObject(base.Client.Network.CurrentSim, localid);
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Export.Downloading"), Textures.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Export.NotFound"), id.ToString(),
|
||||
Client.Network.CurrentSim.ObjectsPrimitives.Count);
|
||||
}
|
||||
}
|
||||
|
||||
private bool RequestObjectProperties(List<Primitive> objects, int msPerRequest)
|
||||
{
|
||||
// Create an array of the local IDs of all the prims we are requesting properties for
|
||||
uint[] localids = new uint[objects.Count];
|
||||
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
PrimsWaiting.Clear();
|
||||
|
||||
for (int i = 0; i < objects.Count; ++i)
|
||||
{
|
||||
localids[i] = objects[i].LocalID;
|
||||
PrimsWaiting.Add(objects[i].ID, objects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Client.Objects.SelectObjects(Client.Network.CurrentSim, localids);
|
||||
|
||||
return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
|
||||
}
|
||||
|
||||
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
|
||||
{
|
||||
if (Directory.Exists("textures/") == false)
|
||||
{
|
||||
Directory.CreateDirectory("textures/");
|
||||
}
|
||||
|
||||
if (state == TextureRequestState.Finished && Textures.Contains(asset.AssetID))
|
||||
{
|
||||
lock (Textures)
|
||||
Textures.Remove(asset.AssetID);
|
||||
|
||||
if (state == TextureRequestState.Finished)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes("textures/" + asset.AssetID + ".jp2", asset.AssetData);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bot.Console.WriteLine(ex.Message, Helpers.LogLevel.Error, Client);
|
||||
}
|
||||
|
||||
if (asset.Decode())
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllBytes("textures/" + asset.AssetID + ".tga", asset.Image.ExportTGA());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
bot.Console.WriteLine(ex.Message, Helpers.LogLevel.Error, Client);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.FailDecode"), asset.AssetID);
|
||||
}
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.ImageDownloaded"), asset.AssetID);
|
||||
}
|
||||
else
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.FailDownload"), asset.AssetID, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Avatars_ViewerEffectPointAt(object sender, ViewerEffectPointAtEventArgs e)
|
||||
{
|
||||
if (e.SourceID == Client.MasterKey)
|
||||
{
|
||||
//Client.DebugLog("Master is now selecting " + targetID.ToString());
|
||||
SelectedObject = e.TargetID;
|
||||
}
|
||||
}
|
||||
|
||||
void Objects_OnObjectPropertiesFamily(object sender, ObjectPropertiesFamilyEventArgs e)
|
||||
{
|
||||
Properties = new Primitive.ObjectProperties();
|
||||
Properties.SetFamilyProperties(e.Properties);
|
||||
GotPermissions = true;
|
||||
GotPermissionsEvent.Set();
|
||||
}
|
||||
|
||||
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
PrimsWaiting.Remove(e.Properties.ObjectID);
|
||||
|
||||
if (PrimsWaiting.Count == 0)
|
||||
AllPropertiesReceived.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
245
SLBot/bot/Commands/Prims/ExportParticlesCommand.cs
Normal file
245
SLBot/bot/Commands/Prims/ExportParticlesCommand.cs
Normal file
@@ -0,0 +1,245 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ExportParticlesCommand.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;
|
||||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
public class ExportParticlesCommand : Command
|
||||
{
|
||||
public ExportParticlesCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "exportparticles";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.ExportParticles.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ExportParticles.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
Predicate<Primitive> match = null;
|
||||
UUID id;
|
||||
bool FoundParticleSystem = false;
|
||||
|
||||
if (args.Length != 1)
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.ExportParticles.Usage");
|
||||
}
|
||||
if (!UUID.TryParse(args[0], out id))
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.ExportParticles.Usage");
|
||||
}
|
||||
|
||||
lock (base.Client.Network.Simulators)
|
||||
{
|
||||
for (int i = 0; i < base.Client.Network.Simulators.Count; i++)
|
||||
{
|
||||
Primitive primitive2 = base.Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == id;
|
||||
});
|
||||
|
||||
if (primitive2 != null)
|
||||
{
|
||||
uint localid;
|
||||
if (primitive2.ParentID != 0)
|
||||
{
|
||||
localid = primitive2.ParentID;
|
||||
}
|
||||
else
|
||||
{
|
||||
localid = primitive2.LocalID;
|
||||
}
|
||||
|
||||
if (match == null)
|
||||
{
|
||||
match = delegate(Primitive prim)
|
||||
{
|
||||
if (prim.LocalID != localid)
|
||||
{
|
||||
return prim.ParentID == localid;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
List<Primitive> objects = base.Client.Network.Simulators[i].ObjectsPrimitives.FindAll(match);
|
||||
|
||||
if (objects != null)
|
||||
{
|
||||
for (int j = 0; j < objects.Count; j++)
|
||||
{
|
||||
Primitive exportPrim = objects[j];
|
||||
|
||||
if (exportPrim.ParticleSys.CRC != 0)
|
||||
{
|
||||
Program.NBStats.AddStatData(String.Format("{0}: {1} exporting particles of object {2} on sim {3}.", DateTime.Now.ToString(), Client, id.ToString(), Client.Network.CurrentSim.Name));
|
||||
|
||||
StringBuilder lsl = new StringBuilder();
|
||||
|
||||
#region Particle System to LSL
|
||||
|
||||
lsl.Append("default" + Environment.NewLine);
|
||||
lsl.Append("{" + Environment.NewLine);
|
||||
lsl.Append(" state_entry()" + Environment.NewLine);
|
||||
lsl.Append(" {" + Environment.NewLine);
|
||||
lsl.Append(" llParticleSystem([" + Environment.NewLine);
|
||||
|
||||
lsl.Append(" PSYS_PART_FLAGS, 0");
|
||||
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.InterpColor) != 0)
|
||||
lsl.Append(" | PSYS_PART_INTERP_COLOR_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.InterpScale) != 0)
|
||||
lsl.Append(" | PSYS_PART_INTERP_SCALE_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.Bounce) != 0)
|
||||
lsl.Append(" | PSYS_PART_BOUNCE_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.Wind) != 0)
|
||||
lsl.Append(" | PSYS_PART_WIND_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.FollowSrc) != 0)
|
||||
lsl.Append(" | PSYS_PART_FOLLOW_SRC_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.FollowVelocity) != 0)
|
||||
lsl.Append(" | PSYS_PART_FOLLOW_VELOCITY_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.TargetPos) != 0)
|
||||
lsl.Append(" | PSYS_PART_TARGET_POS_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.TargetLinear) != 0)
|
||||
lsl.Append(" | PSYS_PART_TARGET_LINEAR_MASK");
|
||||
if ((exportPrim.ParticleSys.PartDataFlags & Primitive.ParticleSystem.ParticleDataFlags.Emissive) != 0)
|
||||
lsl.Append(" | PSYS_PART_EMISSIVE_MASK");
|
||||
|
||||
lsl.Append(",");
|
||||
lsl.Append(Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_PATTERN, 0");
|
||||
|
||||
if ((exportPrim.ParticleSys.Pattern & Primitive.ParticleSystem.SourcePattern.Drop) != 0)
|
||||
lsl.Append(" | PSYS_SRC_PATTERN_DROP");
|
||||
if ((exportPrim.ParticleSys.Pattern & Primitive.ParticleSystem.SourcePattern.Explode) != 0)
|
||||
lsl.Append(" | PSYS_SRC_PATTERN_EXPLODE");
|
||||
if ((exportPrim.ParticleSys.Pattern & Primitive.ParticleSystem.SourcePattern.Angle) != 0)
|
||||
lsl.Append(" | PSYS_SRC_PATTERN_ANGLE");
|
||||
if ((exportPrim.ParticleSys.Pattern & Primitive.ParticleSystem.SourcePattern.AngleCone) != 0)
|
||||
lsl.Append(" | PSYS_SRC_PATTERN_ANGLE_CONE");
|
||||
if ((exportPrim.ParticleSys.Pattern & Primitive.ParticleSystem.SourcePattern.AngleConeEmpty) != 0)
|
||||
lsl.Append(" | PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY");
|
||||
|
||||
lsl.Append("," + Environment.NewLine);
|
||||
|
||||
lsl.Append(" PSYS_PART_START_ALPHA, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartStartColor.A) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_END_ALPHA, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartEndColor.A) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_START_COLOR, " + exportPrim.ParticleSys.PartStartColor.ToRGBString() + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_END_COLOR, " + exportPrim.ParticleSys.PartEndColor.ToRGBString() + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_START_SCALE, <" + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartStartScaleX) + ", " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartStartScaleY) + ", 0>, " + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_END_SCALE, <" + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartEndScaleX) + ", " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartEndScaleY) + ", 0>, " + Environment.NewLine);
|
||||
lsl.Append(" PSYS_PART_MAX_AGE, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.PartMaxAge) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_MAX_AGE, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.MaxAge) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_ACCEL, " + exportPrim.ParticleSys.PartAcceleration.ToString() + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_BURST_PART_COUNT, " + String.Format(new CultureInfo("en-US"), "{0:0}", exportPrim.ParticleSys.BurstPartCount) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_BURST_RADIUS, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.BurstRadius) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_BURST_RATE, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.BurstRate) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_BURST_SPEED_MIN, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.BurstSpeedMin) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_BURST_SPEED_MAX, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.BurstSpeedMax) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_INNERANGLE, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.InnerAngle) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_OUTERANGLE, " + String.Format(new CultureInfo("en-US"), "{0:0.00000}", exportPrim.ParticleSys.OuterAngle) + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_OMEGA, " + exportPrim.ParticleSys.AngularVelocity.ToString() + "," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_TEXTURE, (key)\"" + exportPrim.ParticleSys.Texture.ToString() + "\"," + Environment.NewLine);
|
||||
lsl.Append(" PSYS_SRC_TARGET_KEY, (key)\"" + exportPrim.ParticleSys.Target.ToString() + "\"" + Environment.NewLine);
|
||||
|
||||
lsl.Append(" ]);" + Environment.NewLine);
|
||||
lsl.Append(" }" + Environment.NewLine);
|
||||
lsl.Append("}" + Environment.NewLine);
|
||||
|
||||
#endregion Particle System to LSL
|
||||
|
||||
if (!Directory.Exists("./particles"))
|
||||
Directory.CreateDirectory("./particles");
|
||||
|
||||
File.WriteAllText("./particles/" + CreateFileName(id.ToString(), primitive2.Position.ToString(), primitive2.Text, exportPrim.LocalID), lsl.ToString());
|
||||
|
||||
//File.WriteAllText("./particles/" + id.ToString() + "_" + exportPrim.LocalID.ToString() + ".lsl", lsl.ToString());
|
||||
|
||||
//return builder.ToString();
|
||||
FoundParticleSystem = true;
|
||||
}
|
||||
}
|
||||
if (FoundParticleSystem)
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ExportParticles.Exported"), id.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ExportParticles.NoParticles"), id.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ExportParticles.ObjectNotFound"), id.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ExportParticles.PrimNotFound"), id.ToString());
|
||||
}
|
||||
|
||||
private string CreateFileName(string UUID, string Location, string PrimName, uint localID)
|
||||
{
|
||||
string corrected_PrimName;
|
||||
string corrected_Location;
|
||||
string FinalName;
|
||||
|
||||
if (PrimName == "")
|
||||
PrimName = "Object";
|
||||
|
||||
corrected_PrimName = PrimName.Replace(" ", "_");
|
||||
corrected_PrimName = corrected_PrimName.Replace(":", ";");
|
||||
corrected_PrimName = corrected_PrimName.Replace("*", "+");
|
||||
corrected_PrimName = corrected_PrimName.Replace("|", "I");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\\", "[");
|
||||
corrected_PrimName = corrected_PrimName.Replace("/", "]");
|
||||
corrected_PrimName = corrected_PrimName.Replace("?", "¿");
|
||||
corrected_PrimName = corrected_PrimName.Replace(">", "}");
|
||||
corrected_PrimName = corrected_PrimName.Replace("<", "{");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\"", "'");
|
||||
corrected_PrimName = corrected_PrimName.Replace("\n", " ");
|
||||
|
||||
corrected_Location = Location.Replace(">", "}");
|
||||
corrected_Location = corrected_Location.Replace("<", "{");
|
||||
|
||||
FinalName = corrected_PrimName + " (" + UUID + ", " + corrected_Location + ", " + localID.ToString() + ").lsl";
|
||||
|
||||
return FinalName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
139
SLBot/bot/Commands/Prims/FindObjectsCommand.cs
Normal file
139
SLBot/bot/Commands/Prims/FindObjectsCommand.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : FindObjectsCommand.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;
|
||||
using System.Text;
|
||||
|
||||
public class FindObjectsCommand : Command
|
||||
{
|
||||
Dictionary<UUID, Primitive> PrimsWaiting = new Dictionary<UUID, Primitive>();
|
||||
AutoResetEvent AllPropertiesReceived = new AutoResetEvent(false);
|
||||
StringBuilder sbResult = new StringBuilder();
|
||||
|
||||
public FindObjectsCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
SecondLifeBot.Objects.ObjectProperties += new EventHandler<ObjectPropertiesEventArgs>(Objects_OnObjectProperties);
|
||||
base.Name = "findobjects";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.FindObjects.Description") + " " + bot.Localization.clResourceManager.getText("Commands.FindObjects.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
sbResult = new StringBuilder();
|
||||
|
||||
// *** parse arguments ***
|
||||
if ((args.Length < 1) || (args.Length > 2))
|
||||
return bot.Localization.clResourceManager.getText("Commands.FindObjects.Usage");
|
||||
float radius = float.Parse(args[0]);
|
||||
string searchString = (args.Length > 1) ? args[1] : "";
|
||||
|
||||
// *** get current location ***
|
||||
Vector3 location = Client.Self.SimPosition;
|
||||
|
||||
// *** find all objects in radius ***
|
||||
List<Primitive> prims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
Vector3 pos = prim.Position;
|
||||
return ((prim.ParentID == 0) && (pos != Vector3.Zero) && (Vector3.Distance(pos, location) < radius));
|
||||
}
|
||||
);
|
||||
|
||||
// *** request properties of these objects ***
|
||||
bool complete = RequestObjectProperties(prims, 250);
|
||||
|
||||
foreach (Primitive p in prims)
|
||||
{
|
||||
string name = p.Properties.Name;
|
||||
if ((name != null) && (name.Contains(searchString)))
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.FindObjects.Info"), name, p.ID.ToString());
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
if (!complete)
|
||||
{
|
||||
sbResult.AppendLine(bot.Localization.clResourceManager.getText("Commands.FindObjects.Unable"));
|
||||
foreach (UUID uuid in PrimsWaiting.Keys)
|
||||
sbResult.AppendLine(uuid.ToString());
|
||||
}
|
||||
|
||||
sbResult.AppendFormat("Commands.FindObjects.Done");
|
||||
return sbResult.ToString();
|
||||
}
|
||||
|
||||
private bool RequestObjectProperties(List<Primitive> objects, int msPerRequest)
|
||||
{
|
||||
// Create an array of the local IDs of all the prims we are requesting properties for
|
||||
uint[] localids = new uint[objects.Count];
|
||||
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
PrimsWaiting.Clear();
|
||||
|
||||
for (int i = 0; i < objects.Count; ++i)
|
||||
{
|
||||
localids[i] = objects[i].LocalID;
|
||||
PrimsWaiting.Add(objects[i].ID, objects[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Client.Objects.SelectObjects(Client.Network.CurrentSim, localids);
|
||||
|
||||
return AllPropertiesReceived.WaitOne(2000 + msPerRequest * objects.Count, false);
|
||||
}
|
||||
|
||||
void Objects_OnObjectProperties(object sender, ObjectPropertiesEventArgs e)
|
||||
{
|
||||
lock (PrimsWaiting)
|
||||
{
|
||||
Primitive prim;
|
||||
if (PrimsWaiting.TryGetValue(e.Properties.ObjectID, out prim))
|
||||
{
|
||||
prim.Properties = e.Properties;
|
||||
}
|
||||
PrimsWaiting.Remove(e.Properties.ObjectID);
|
||||
|
||||
if (PrimsWaiting.Count == 0)
|
||||
AllPropertiesReceived.Set();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
310
SLBot/bot/Commands/Prims/ImportCommand.cs
Normal file
310
SLBot/bot/Commands/Prims/ImportCommand.cs
Normal file
@@ -0,0 +1,310 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ImportCommand.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.StructuredData;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
public class ImportCommand : Command
|
||||
{
|
||||
private enum ImporterState
|
||||
{
|
||||
RezzingParent,
|
||||
RezzingChildren,
|
||||
Linking,
|
||||
Idle
|
||||
}
|
||||
|
||||
private class Linkset
|
||||
{
|
||||
public Primitive RootPrim;
|
||||
public List<Primitive> Children = new List<Primitive>();
|
||||
|
||||
public Linkset()
|
||||
{
|
||||
RootPrim = new Primitive();
|
||||
}
|
||||
|
||||
public Linkset(Primitive rootPrim)
|
||||
{
|
||||
RootPrim = rootPrim;
|
||||
}
|
||||
}
|
||||
|
||||
Primitive currentPrim;
|
||||
Vector3 currentPosition;
|
||||
AutoResetEvent primDone = new AutoResetEvent(false);
|
||||
List<Primitive> primsCreated;
|
||||
List<uint> linkQueue;
|
||||
uint rootLocalID;
|
||||
ImporterState state = ImporterState.Idle;
|
||||
|
||||
public ImportCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "import";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.Import.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Import.Usage");
|
||||
SecondLifeBot.Objects.ObjectUpdate += Objects_OnNewPrim;
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
primDone.Reset();
|
||||
|
||||
if (args.Length < 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.Import.Usage");
|
||||
|
||||
string filename = args[0];
|
||||
UUID GroupID = (args.Length > 1) ? Client.GroupID : UUID.Zero;
|
||||
string xml;
|
||||
List<Primitive> prims;
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
try
|
||||
{
|
||||
xml = File.ReadAllText(filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
xml = File.ReadAllText("./objects/" + filename);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
prims = Helpers.OSDToPrimList(OSDParser.DeserializeLLSDXml(xml));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Import.DeserializeFail"), filename, e.Message);
|
||||
}
|
||||
|
||||
// Build an organized structure from the imported prims
|
||||
Dictionary<uint, Linkset> linksets = new Dictionary<uint, Linkset>();
|
||||
for (int i = 0; i < prims.Count; i++)
|
||||
{
|
||||
Primitive prim = prims[i];
|
||||
|
||||
if (prim.ParentID == 0)
|
||||
{
|
||||
if (linksets.ContainsKey(prim.LocalID))
|
||||
linksets[prim.LocalID].RootPrim = prim;
|
||||
else
|
||||
linksets[prim.LocalID] = new Linkset(prim);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!linksets.ContainsKey(prim.ParentID))
|
||||
linksets[prim.ParentID] = new Linkset();
|
||||
|
||||
linksets[prim.ParentID].Children.Add(prim);
|
||||
}
|
||||
}
|
||||
|
||||
primsCreated = new List<Primitive>();
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Import.Importing"), linksets.Count);
|
||||
|
||||
foreach (Linkset linkset in linksets.Values)
|
||||
{
|
||||
if (linkset.RootPrim.LocalID != 0)
|
||||
{
|
||||
state = ImporterState.RezzingParent;
|
||||
currentPrim = linkset.RootPrim;
|
||||
// HACK: Import the structure just above our head
|
||||
// We need a more elaborate solution for importing with relative or absolute offsets
|
||||
linkset.RootPrim.Position = Client.Self.SimPosition;
|
||||
linkset.RootPrim.Position.Z += 3.0f;
|
||||
currentPosition = linkset.RootPrim.Position;
|
||||
|
||||
// Rez the root prim with no rotation
|
||||
Quaternion rootRotation = linkset.RootPrim.Rotation;
|
||||
linkset.RootPrim.Rotation = Quaternion.Identity;
|
||||
|
||||
Client.Objects.AddPrim(Client.Network.CurrentSim, linkset.RootPrim.PrimData, GroupID,
|
||||
linkset.RootPrim.Position, linkset.RootPrim.Scale, linkset.RootPrim.Rotation);
|
||||
|
||||
if (!primDone.WaitOne(15000, false))
|
||||
{
|
||||
primsCreated.Clear();
|
||||
return bot.Localization.clResourceManager.getText("Commands.Import.RootFail");
|
||||
}
|
||||
|
||||
Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, linkset.RootPrim.Position);
|
||||
|
||||
state = ImporterState.RezzingChildren;
|
||||
|
||||
// Rez the child prims
|
||||
foreach (Primitive prim in linkset.Children)
|
||||
{
|
||||
currentPrim = prim;
|
||||
currentPosition = prim.Position + linkset.RootPrim.Position;
|
||||
|
||||
Client.Objects.AddPrim(Client.Network.CurrentSim, prim.PrimData, GroupID, currentPosition,
|
||||
prim.Scale, prim.Rotation);
|
||||
|
||||
if (!primDone.WaitOne(15000, false))
|
||||
{
|
||||
primsCreated.Clear();
|
||||
return bot.Localization.clResourceManager.getText("Commands.Import.ChildFail");
|
||||
}
|
||||
Client.Objects.SetPosition(Client.Network.CurrentSim, primsCreated[primsCreated.Count - 1].LocalID, currentPosition);
|
||||
|
||||
}
|
||||
|
||||
// Create a list of the local IDs of the newly created prims
|
||||
List<uint> primIDs = new List<uint>(primsCreated.Count);
|
||||
primIDs.Add(rootLocalID); // Root prim is first in list.
|
||||
|
||||
if (linkset.Children.Count != 0)
|
||||
{
|
||||
// Add the rest of the prims to the list of local IDs
|
||||
foreach (Primitive prim in primsCreated)
|
||||
{
|
||||
if (prim.LocalID != rootLocalID)
|
||||
primIDs.Add(prim.LocalID);
|
||||
}
|
||||
linkQueue = new List<uint>(primIDs.Count);
|
||||
linkQueue.AddRange(primIDs);
|
||||
|
||||
// Link and set the permissions + rotation
|
||||
state = ImporterState.Linking;
|
||||
Client.Objects.LinkPrims(Client.Network.CurrentSim, linkQueue);
|
||||
|
||||
if (primDone.WaitOne(1000 * linkset.Children.Count, false))
|
||||
Client.Objects.SetRotation(Client.Network.CurrentSim, rootLocalID, rootRotation);
|
||||
else
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Import.LinkFail"), linkQueue.Count);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.Objects.SetRotation(Client.Network.CurrentSim, rootLocalID, rootRotation);
|
||||
}
|
||||
|
||||
// Set permissions on newly created prims
|
||||
Client.Objects.SetPermissions(Client.Network.CurrentSim, primIDs,
|
||||
PermissionWho.Everyone | PermissionWho.Group | PermissionWho.NextOwner,
|
||||
PermissionMask.All, true);
|
||||
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Import.DeRezzing"));
|
||||
Client.Inventory.RequestDeRezToInventory(rootLocalID);
|
||||
|
||||
state = ImporterState.Idle;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Skip linksets with a missing root prim
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Import.MissingRoot"));
|
||||
}
|
||||
|
||||
// Reset everything for the next linkset
|
||||
primsCreated.Clear();
|
||||
}
|
||||
|
||||
return bot.Localization.clResourceManager.getText("Commands.Import.Complete");
|
||||
}
|
||||
|
||||
void Objects_OnNewPrim(object sender, PrimEventArgs e)
|
||||
{
|
||||
Primitive prim = e.Prim;
|
||||
|
||||
if ((prim.Flags & PrimFlags.CreateSelected) == 0)
|
||||
return; // We received an update for an object we didn't create
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ImporterState.RezzingParent:
|
||||
rootLocalID = prim.LocalID;
|
||||
goto case ImporterState.RezzingChildren;
|
||||
case ImporterState.RezzingChildren:
|
||||
if (!primsCreated.Contains(prim))
|
||||
{
|
||||
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Import.Properties"), prim.LocalID);
|
||||
// TODO: Is there a way to set all of this at once, and update more ObjectProperties stuff?
|
||||
Client.Objects.SetPosition(e.Simulator, prim.LocalID, currentPosition);
|
||||
Client.Objects.SetTextures(e.Simulator, prim.LocalID, currentPrim.Textures);
|
||||
|
||||
if (currentPrim.Light.Intensity > 0)
|
||||
{
|
||||
Client.Objects.SetLight(e.Simulator, prim.LocalID, currentPrim.Light);
|
||||
}
|
||||
|
||||
Client.Objects.SetFlexible(e.Simulator, prim.LocalID, currentPrim.Flexible);
|
||||
|
||||
if (currentPrim.Sculpt.SculptTexture != UUID.Zero)
|
||||
{
|
||||
Client.Objects.SetSculpt(e.Simulator, prim.LocalID, currentPrim.Sculpt);
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(currentPrim.Properties.Name))
|
||||
Client.Objects.SetName(e.Simulator, prim.LocalID, currentPrim.Properties.Name);
|
||||
if (!String.IsNullOrEmpty(currentPrim.Properties.Description))
|
||||
Client.Objects.SetDescription(e.Simulator, prim.LocalID, currentPrim.Properties.Description);
|
||||
|
||||
primsCreated.Add(prim);
|
||||
primDone.Set();
|
||||
}
|
||||
break;
|
||||
case ImporterState.Linking:
|
||||
lock (linkQueue)
|
||||
{
|
||||
int index = linkQueue.IndexOf(prim.LocalID);
|
||||
if (index != -1)
|
||||
{
|
||||
linkQueue.RemoveAt(index);
|
||||
if (linkQueue.Count == 0)
|
||||
primDone.Set();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
96
SLBot/bot/Commands/Prims/ObjectInventoryCommand.cs
Normal file
96
SLBot/bot/Commands/Prims/ObjectInventoryCommand.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : ObjectInventoryCommand.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 ObjectInventoryCommand : Command
|
||||
{
|
||||
public ObjectInventoryCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "objectinventory";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Description") + " " + bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Usage");
|
||||
|
||||
uint objectLocalID;
|
||||
UUID objectID;
|
||||
if (!UUID.TryParse(args[0], out objectID))
|
||||
return bot.Localization.clResourceManager.getText("Commands.ObjectInventory.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.ObjectInventory.NotFound"), objectID.ToString());
|
||||
|
||||
List<InventoryBase> items = Client.Inventory.GetTaskInventory(objectID, objectLocalID, 1000 * 30);
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
string result = String.Empty;
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (items[i] is InventoryFolder)
|
||||
{
|
||||
result += String.Format(bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Folder"), items[i].Name) + Environment.NewLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
InventoryItem item = (InventoryItem)items[i];
|
||||
result += String.Format(bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Item"), item.Name, item.Description,
|
||||
item.AssetType, item.UUID) + Environment.NewLine;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.ObjectInventory.Failed"), objectLocalID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
190
SLBot/bot/Commands/Prims/PrimInfoCommand.cs
Normal file
190
SLBot/bot/Commands/Prims/PrimInfoCommand.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : PrimInfoCommand.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;
|
||||
|
||||
public class PrimInfoCommand : Command
|
||||
{
|
||||
StringBuilder sbResult = new StringBuilder();
|
||||
|
||||
public PrimInfoCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "priminfo";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Description") + " " + bot.Localization.clResourceManager.getText("Commands.PrimInfo.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
UUID primID;
|
||||
sbResult = new StringBuilder();
|
||||
|
||||
if (args.Length != 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.PrimInfo.Usage");
|
||||
|
||||
if (UUID.TryParse(args[0], out primID))
|
||||
{
|
||||
Primitive target = Client.Network.CurrentSim.ObjectsPrimitives.Find(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == primID;
|
||||
}
|
||||
);
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
string targetName, targetDescription, targetCreator, targetOwner, targerLastOwner, targetGroup, targetSitName, targetTouchName;
|
||||
|
||||
if (target.Properties.Name == "")
|
||||
targetName = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else
|
||||
targetName = target.Properties.Name;
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Name"), targetName);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.Description == "")
|
||||
targetDescription = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else
|
||||
targetDescription = target.Properties.Description;
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.PrimDescription"), targetDescription);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.CreatorID == UUID.Zero)
|
||||
targetCreator = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else if (!Client.key2Name(target.Properties.CreatorID, out targetCreator))
|
||||
targetCreator = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Unknown");
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Creator"), targetCreator, target.Properties.CreatorID);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.OwnerID == UUID.Zero)
|
||||
targetOwner = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else if (!Client.key2Name(target.Properties.OwnerID, out targetOwner))
|
||||
targetOwner = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Unknown");
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Owner"), targetOwner, target.Properties.OwnerID);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.LastOwnerID == UUID.Zero)
|
||||
targerLastOwner = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else if (!Client.key2Name(target.Properties.LastOwnerID, out targerLastOwner))
|
||||
targerLastOwner = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Unknown");
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.LastOwner"), targerLastOwner, target.Properties.LastOwnerID);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.GroupID == UUID.Zero)
|
||||
targetGroup = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else if (!Client.key2Name(target.Properties.GroupID, out targetGroup))
|
||||
targetGroup = bot.Localization.clResourceManager.getText("Commands.PrimInfo.Unknown");
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Group"), targetGroup, target.Properties.GroupID);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.SitName == "")
|
||||
targetSitName = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else
|
||||
targetSitName = target.Properties.SitName;
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.SitName"), targetSitName);
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Properties.TouchName == "")
|
||||
targetTouchName = bot.Localization.clResourceManager.getText("Commands.PrimInfo.None");
|
||||
else
|
||||
targetTouchName = target.Properties.TouchName;
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.TouchName"), targetTouchName);
|
||||
sbResult.AppendLine();
|
||||
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Position"), target.Position.ToString());
|
||||
sbResult.AppendLine();
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Date"), target.Properties.CreationDate.ToString());
|
||||
sbResult.AppendLine();
|
||||
|
||||
if (target.Text != String.Empty)
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Text") + target.Text);
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
|
||||
if (target.Light != null)
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Light"), target.Light.ToString());
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
|
||||
if (target.ParticleSys.CRC != 0)
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Particles"), target.ParticleSys.ToString());
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
|
||||
if (target.Textures != null)
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.TextureEntry"));
|
||||
sbResult.AppendLine();
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Default"),
|
||||
target.Textures.DefaultTexture.TextureID.ToString());
|
||||
sbResult.AppendLine();
|
||||
|
||||
for (int i = 0; i < target.Textures.FaceTextures.Length; i++)
|
||||
{
|
||||
if (target.Textures.FaceTextures[i] != null)
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Face"), i,
|
||||
target.Textures.FaceTextures[i].TextureID.ToString());
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Null"));
|
||||
sbResult.AppendLine();
|
||||
}
|
||||
|
||||
sbResult.AppendFormat(bot.Localization.clResourceManager.getText("Commands.PrimInfo.Done"));
|
||||
|
||||
return sbResult.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.PrimInfo.NotFound"), primID.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.PrimInfo.Usage");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
99
SLBot/bot/Commands/Prims/PrimRegexCommand.cs
Normal file
99
SLBot/bot/Commands/Prims/PrimRegexCommand.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : PrimRegexCommand.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.RegularExpressions;
|
||||
|
||||
public class PrimRegexCommand : Command
|
||||
{
|
||||
public PrimRegexCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "primregex";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.PrimRegex.Description") + " " + bot.Localization.clResourceManager.getText("Commands.PrimRegex.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
if (args.Length < 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.PrimRegex.Usage");
|
||||
|
||||
try
|
||||
{
|
||||
// Build the predicat from the args list
|
||||
string predicatPrim = string.Empty;
|
||||
for (int i = 0; i < args.Length; i++)
|
||||
predicatPrim += args[i] + " ";
|
||||
predicatPrim = predicatPrim.TrimEnd();
|
||||
|
||||
// Build Regex
|
||||
Regex regexPrimName = new Regex(predicatPrim.ToLower());
|
||||
|
||||
// Print result
|
||||
bot.Console.WriteLine(string.Format(bot.Localization.clResourceManager.getText("Commands.PrimRegex.Searching"), predicatPrim,
|
||||
Client.Network.CurrentSim.ObjectsPrimitives.Count));
|
||||
|
||||
Client.Network.CurrentSim.ObjectsPrimitives.ForEach(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
if (prim.Text != null && regexPrimName.IsMatch(prim.Text.ToLower()))
|
||||
{
|
||||
bot.Console.WriteLine(string.Format(bot.Localization.clResourceManager.getText("Commands.PrimRegex.Prim"), prim.Properties.Name,
|
||||
prim.ID, prim.Flags.ToString(), prim.Text, prim.Properties.Description));
|
||||
}
|
||||
else if (prim.Properties.Name != null && regexPrimName.IsMatch(prim.Properties.Name.ToLower()))
|
||||
{
|
||||
bot.Console.WriteLine(string.Format(bot.Localization.clResourceManager.getText("Commands.PrimRegex.Prim"), prim.Properties.Name,
|
||||
prim.ID, prim.Flags.ToString(), prim.Text, prim.Properties.Description));
|
||||
}
|
||||
else if (prim.Properties.Description != null && regexPrimName.IsMatch(prim.Properties.Description.ToLower()))
|
||||
{
|
||||
bot.Console.WriteLine(string.Format(bot.Localization.clResourceManager.getText("Commands.PrimRegex.Prim"), prim.Properties.Name,
|
||||
prim.ID, prim.Flags.ToString(), prim.Text, prim.Properties.Description));
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
bot.Console.WriteLine(e.Message);
|
||||
return bot.Localization.clResourceManager.getText("Commands.PrimRegex.Error");
|
||||
}
|
||||
|
||||
return bot.Localization.clResourceManager.getText("Commands.PrimRegex.Done");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
79
SLBot/bot/Commands/Prims/SitCommand.cs
Normal file
79
SLBot/bot/Commands/Prims/SitCommand.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : SitCommand.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 SitCommand : Command
|
||||
{
|
||||
public SitCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "sit";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.Sit.Description");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
Primitive closest = null;
|
||||
double closestDistance = Double.MaxValue;
|
||||
|
||||
Client.Network.CurrentSim.ObjectsPrimitives.ForEach(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
float distance = Vector3.Distance(Client.Self.SimPosition, prim.Position);
|
||||
|
||||
if (closest == null || distance < closestDistance)
|
||||
{
|
||||
closest = prim;
|
||||
closestDistance = distance;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (closest != null)
|
||||
{
|
||||
Client.Self.RequestSit(closest.ID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Sit.Sit"), closest.ID, closest.LocalID, closestDistance);
|
||||
}
|
||||
else
|
||||
{
|
||||
return bot.Localization.clResourceManager.getText("Commands.Sit.NotFound");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
76
SLBot/bot/Commands/Prims/SitOnCommand.cs
Normal file
76
SLBot/bot/Commands/Prims/SitOnCommand.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : SitOnCommand.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 SitOnCommand : Command
|
||||
{
|
||||
public SitOnCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "siton";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.SitOn.Description") + " " + bot.Localization.clResourceManager.getText("Commands.SitOn.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
if (args.Length != 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.SitOn.Usage");
|
||||
|
||||
UUID target;
|
||||
|
||||
if (UUID.TryParse(args[0], out target))
|
||||
{
|
||||
Primitive targetPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(
|
||||
delegate(Primitive prim)
|
||||
{
|
||||
return prim.ID == target;
|
||||
}
|
||||
);
|
||||
|
||||
if (targetPrim != null)
|
||||
{
|
||||
Client.Self.RequestSit(targetPrim.ID, Vector3.Zero);
|
||||
Client.Self.Sit();
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.SitOn.Sit"), targetPrim.ID.ToString(),
|
||||
targetPrim.LocalID);
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.SitOn.NotFound"), args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
74
SLBot/bot/Commands/Prims/TouchCommand.cs
Normal file
74
SLBot/bot/Commands/Prims/TouchCommand.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
The Disc Image Chef
|
||||
----------------------------------------------------------------------------
|
||||
|
||||
Filename : TouchCommand.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 TouchCommand : Command
|
||||
{
|
||||
public TouchCommand(SecondLifeBot SecondLifeBot)
|
||||
{
|
||||
base.Name = "touch";
|
||||
base.Description = bot.Localization.clResourceManager.getText("Commands.Touch.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Touch.Usage");
|
||||
}
|
||||
|
||||
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
|
||||
{
|
||||
UUID target;
|
||||
|
||||
if (args.Length != 1)
|
||||
return bot.Localization.clResourceManager.getText("Commands.Touch.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)
|
||||
{
|
||||
Client.Self.Touch(targetPrim.LocalID);
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Touch.Touched"), targetPrim.LocalID);
|
||||
}
|
||||
}
|
||||
|
||||
return String.Format(bot.Localization.clResourceManager.getText("Commands.Touch.NotFound"), args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user