Open sourced NatiBot

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

View File

@@ -0,0 +1,108 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : AnimationsCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.IO;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
using System.Collections.Generic;
public class AnimationsCommand : Command
{
Dictionary<UUID, UUID> alreadyRequested = new Dictionary<UUID, UUID>();
bool enabled = false;
public AnimationsCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "animations";
base.Description = bot.Localization.clResourceManager.getText("Commands.Animations.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Animations.Usage");
enabled = SecondLifeBot.Account.LoginDetails.BotConfig.GetSounds;
SecondLifeBot.Avatars.AvatarAnimation += new EventHandler<AvatarAnimationEventArgs>(Avatars_AvatarAnimation);
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.Animations.Usage");
if (args[0].ToLower() == "on")
{
enabled = true;
return bot.Localization.clResourceManager.getText("Commands.Animations.Enabled");
}
else if (args[0].ToLower() == "off")
{
enabled = false;
return bot.Localization.clResourceManager.getText("Commands.Animations.Disabled");
}
else
{
return bot.Localization.clResourceManager.getText("Commands.Animations.Usage");
}
}
void Avatars_AvatarAnimation(object sender, AvatarAnimationEventArgs e)
{
Dictionary<UUID, string> BuiltInAnimations = Animations.ToDictionary();
if (enabled && base.Client.Account.LoginDetails.BotConfig.GetSounds)
{
foreach (Animation an in e.Animations)
{
if (!BuiltInAnimations.ContainsKey(an.AnimationID))
if (!System.IO.File.Exists("./animations/" + an.AnimationID.ToString() + ".animatn"))
base.Client.Assets.RequestAsset(an.AnimationID, AssetType.Animation, true, Assets_OnAnimationReceived);
}
}
}
public void Assets_OnAnimationReceived(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
if (!System.IO.Directory.Exists("./animations"))
System.IO.Directory.CreateDirectory("./animations");
System.IO.File.WriteAllBytes("./animations/" + asset.AssetID.ToString() + ".animatn", asset.AssetData);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Downloaded"), asset.AssetID.ToString(), asset.AssetData.Length);
}
else
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Failed"), transfer.AssetID, transfer.Status);
}
}
}
}

View File

@@ -0,0 +1,99 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : DownloadAnimationCommand.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.Packets;
using System;
using System.Collections.Generic;
using System.Threading;
using System.IO;
using OpenMetaverse.Assets;
public class DownloadAnimationCommand : Command
{
string downloadResult;
System.Threading.AutoResetEvent waitEvent = new System.Threading.AutoResetEvent(false);
public DownloadAnimationCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "downloadanimation";
base.Description = bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
UUID AnimationUUID;
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Usage");
if (!UUID.TryParse(args[0], out AnimationUUID))
{
return bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.InvalidUUID");
}
Program.NBStats.AddStatData(String.Format("{0}: {1} downloading animation {2}.", DateTime.Now.ToString(), Client, args[0]));
base.Client.Assets.RequestAsset(AnimationUUID, AssetType.Animation, true, Assets_OnAnimationReceived);
if (!waitEvent.WaitOne(10000, false))
{
return bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Timeout");
}
else
{
return downloadResult;
}
}
public void Assets_OnAnimationReceived(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
if (!System.IO.Directory.Exists("./animations"))
System.IO.Directory.CreateDirectory("./animations");
System.IO.File.WriteAllBytes("./animations/" + asset.AssetID.ToString() + ".animatn", asset.AssetData);
downloadResult = String.Format(bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Downloaded"), asset.AssetID.ToString(), asset.AssetData.Length);
}
else
{
downloadResult = String.Format(bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.Failed"), transfer.AssetID, transfer.Status);
}
waitEvent.Set();
}
}
}

View File

@@ -0,0 +1,100 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : DownloadSoundCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.IO;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class DownloadSoundCommand : Command
{
AutoResetEvent DownloadHandle = new AutoResetEvent(false);
string resultState;
public DownloadSoundCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "downloadsound";
base.Description = bot.Localization.clResourceManager.getText("Commands.DownloadSound.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DownloadSound.Usage");
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
UUID SoundID;
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.DownloadSound.Usage");
DownloadHandle.Reset();
if (UUID.TryParse(args[0], out SoundID))
{
Program.NBStats.AddStatData(String.Format("{0}: {1} downloading sound {2}.", DateTime.Now.ToString(), Client, args[0]));
base.Client.Assets.RequestAsset(SoundID, AssetType.Sound, true, Assets_OnSoundReceived);
if (DownloadHandle.WaitOne(120 * 1000, false))
{
return resultState;
}
else
{
return bot.Localization.clResourceManager.getText("Commands.DownloadSound.Timeout");
}
}
else
{
return bot.Localization.clResourceManager.getText("Commands.DownloadAnimation.InvalidUUID");
}
}
public void Assets_OnSoundReceived(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
if (!System.IO.Directory.Exists("./sounds"))
System.IO.Directory.CreateDirectory("./sounds");
System.IO.File.WriteAllBytes("./sounds/" + asset.AssetID.ToString() + ".ogg", asset.AssetData);
resultState = String.Format(bot.Localization.clResourceManager.getText("Commands.Sounds.Downloaded"), asset.AssetID.ToString(), asset.AssetData.Length);
}
else
{
resultState = String.Format(bot.Localization.clResourceManager.getText("Commands.Sounds.Failed"), transfer.AssetID, transfer.Status);
}
DownloadHandle.Set();
}
}
}

View File

@@ -0,0 +1,151 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : DownloadTextureCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.IO;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
public class DownloadTextureCommand : Command
{
UUID TextureID;
AutoResetEvent DownloadHandle = new AutoResetEvent(false);
TextureRequestState resultState;
AssetTexture Asset;
public DownloadTextureCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "downloadtexture";
base.Description = bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Description") + " " + bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Usage");
//SecondLifeBot.Assets.OnImageReceiveProgress += new AssetManager.ImageReceiveProgressCallback(Assets_OnImageReceiveProgress);
//SecondLifeBot.Assets.OnImageReceived += new AssetManager.ImageReceivedCallback(Assets_OnImageReceived);
}
public override string Execute(string[] args, UUID fromAgentID, bool something_else)
{
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Usage");
if (args.Length != 1 && args.Length != 2)
return bot.Localization.clResourceManager.getText("Commands.DownloadTexture.UsageLong");
TextureID = UUID.Zero;
DownloadHandle.Reset();
Asset = null;
if (UUID.TryParse(args[0], out TextureID))
{
int discardLevel = 0;
if (args.Length > 1)
{
if (!Int32.TryParse(args[1], out discardLevel))
return bot.Localization.clResourceManager.getText("Commands.DownloadTexture.UsageLong");
}
Program.NBStats.AddStatData(String.Format("{0}: {1} downloading texture {2}.", DateTime.Now.ToString(), Client, args[0]));
Client.Assets.RequestImage(TextureID, ImageType.Normal, Assets_OnImageReceived);
if (DownloadHandle.WaitOne(120 * 1000, false))
{
if (resultState == TextureRequestState.Finished)
{
if (Asset != null && Asset.Decode())
{
if (!Directory.Exists("textures/"))
Directory.CreateDirectory("textures/");
try
{
File.WriteAllBytes("textures/" + Asset.AssetID + ".jp2", Asset.AssetData);
}
catch (Exception ex)
{
bot.Console.WriteLine(ex.Message, Helpers.LogLevel.Error, Client, ex);
}
try
{
File.WriteAllBytes("textures/" + Asset.AssetID + ".tga", Asset.Image.ExportTGA());
}
catch (Exception ex)
{
bot.Console.WriteLine(ex.Message, Helpers.LogLevel.Error, Client);
}
return String.Format(bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Saved"), Asset.AssetID, Asset.Image.Width, Asset.Image.Height);
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Assets.Image.FailDecode"), TextureID.ToString());
}
}
else if (resultState == TextureRequestState.NotFound)
{
return String.Format(bot.Localization.clResourceManager.getText("Commands.DownloadTexture.NotFound"), TextureID.ToString());
}
else
{
return String.Format(bot.Localization.clResourceManager.getText("Assets.Image.FailDownload"), TextureID, resultState);
}
}
else
{
return bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Timeout");
}
}
else
{
return bot.Localization.clResourceManager.getText("Commands.DownloadTexture.Usage");
}
}
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
{
resultState = state;
Asset = asset;
DownloadHandle.Set();
}
/*private void Assets_OnImageReceiveProgress(UUID image, int lastPacket, int recieved, int total)
{
bot.Console.WriteLine(String.Format("Textura {0}: Recibidos {1} / {2} bytes", image, recieved, total));
}*/
}
}

View File

@@ -0,0 +1,108 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : SoundsCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.IO;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
using System.Collections.Generic;
public class SoundsCommand : Command
{
Dictionary<UUID, UUID> alreadyRequested = new Dictionary<UUID, UUID>();
bool enabled = false;
public SoundsCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "sounds";
base.Description = bot.Localization.clResourceManager.getText("Commands.Sounds.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Textures.Usage");
enabled = SecondLifeBot.Account.LoginDetails.BotConfig.GetSounds;
SecondLifeBot.Sound.SoundTrigger += new EventHandler<SoundTriggerEventArgs>(Sound_SoundTrigger);
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.Sounds.Usage");
if (args[0].ToLower() == "on")
{
enabled = true;
return bot.Localization.clResourceManager.getText("Commands.Sounds.Enabled");
}
else if (args[0].ToLower() == "off")
{
enabled = false;
return bot.Localization.clResourceManager.getText("Commands.Sounds.Disabled");
}
else
{
return bot.Localization.clResourceManager.getText("Commands.Sounds.Usage");
}
}
void Sound_SoundTrigger(object sender, SoundTriggerEventArgs e)
{
if (enabled && base.Client.Account.LoginDetails.BotConfig.GetTextures)
{
#if DEBUG
bot.Console.WriteLine(this.Client, "GETTING SOUND: Gain: {0}, Object: {1}, Owner: {2}, Parent: {3}, Position: {4}, Region: {5}, ID: {6}",
e.Gain.ToString(), e.ObjectID.ToString(), e.OwnerID.ToString(), e.ParentID.ToString(),
e.Position.ToString(), e.RegionHandle.ToString(), e.SoundID.ToString());
#endif
if (!System.IO.File.Exists("./sounds/" + e.SoundID.ToString() + ".ogg"))
base.Client.Assets.RequestAsset(e.SoundID, AssetType.Sound, true, Assets_OnSoundReceived);
}
}
public void Assets_OnSoundReceived(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
if (!System.IO.Directory.Exists("./sounds"))
System.IO.Directory.CreateDirectory("./sounds");
System.IO.File.WriteAllBytes("./sounds/" + asset.AssetID.ToString() + ".ogg", asset.AssetData);
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Sounds.Downloaded"), asset.AssetID.ToString(), asset.AssetData.Length);
}
else
{
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Commands.Sounds.Failed"), transfer.AssetID, transfer.Status);
}
}
}
}

View File

@@ -0,0 +1,182 @@
/***************************************************************************
The Disc Image Chef
----------------------------------------------------------------------------
Filename : TexturesCommand.cs
Version : 1.0.326
Author(s) : Natalia Portillo
Component : NatiBot
Revision : r326
Last change by : Natalia Portillo
Date : 2010/01/01
--[ License ] --------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
----------------------------------------------------------------------------
Copyright (C) 2008-2014 Claunia.com
****************************************************************************/
namespace bot.Commands
{
using bot;
using System;
using System.IO;
using System.Threading;
using OpenMetaverse;
using OpenMetaverse.Assets;
using System.Collections.Generic;
public class TexturesCommand : Command
{
Dictionary<UUID, UUID> alreadyRequested = new Dictionary<UUID, UUID>();
bool enabled = false;
public TexturesCommand(SecondLifeBot SecondLifeBot)
{
base.Name = "textures";
base.Description = bot.Localization.clResourceManager.getText("Commands.Textures.Description") + " " + bot.Localization.clResourceManager.getText("Commands.Textures.Usage");
enabled = SecondLifeBot.Account.LoginDetails.BotConfig.GetTextures;
SecondLifeBot.Objects.ObjectUpdate += new EventHandler<PrimEventArgs>(Objects_OnNewPrim);
SecondLifeBot.Objects.AvatarUpdate += Objects_OnNewAvatar;
}
public override string Execute(string[] args, UUID fromAgentID, bool fromSL)
{
if (args.Length != 1)
return bot.Localization.clResourceManager.getText("Commands.Textures.Usage");
if (args[0].ToLower() == "on")
{
enabled = true;
return bot.Localization.clResourceManager.getText("Commands.Textures.Enabled");
}
else if (args[0].ToLower() == "off")
{
enabled = false;
return bot.Localization.clResourceManager.getText("Commands.Textures.Disabled");
}
else
{
return bot.Localization.clResourceManager.getText("Commands.Textures.Usage");
}
}
void Objects_OnNewAvatar(object sender, AvatarUpdateEventArgs e)
{
if (enabled && base.Client.Account.LoginDetails.BotConfig.GetTextures)
{
// Search this avatar for textures
for (int i = 0; i < e.Avatar.Textures.FaceTextures.Length; i++)
{
Primitive.TextureEntryFace face = e.Avatar.Textures.FaceTextures[i];
if (face != null)
{
if (!alreadyRequested.ContainsKey(face.TextureID))
{
alreadyRequested[face.TextureID] = face.TextureID;
// Determine if this is a baked outfit texture or a normal texture
ImageType type = ImageType.Normal;
AvatarTextureIndex index = (AvatarTextureIndex)i;
switch (index)
{
case AvatarTextureIndex.EyesBaked:
case AvatarTextureIndex.HeadBaked:
case AvatarTextureIndex.LowerBaked:
case AvatarTextureIndex.SkirtBaked:
case AvatarTextureIndex.UpperBaked:
type = ImageType.Baked;
break;
}
if (!File.Exists("textures/" + face.TextureID + ".jp2"))
Client.Assets.RequestImage(face.TextureID, type, Assets_OnImageReceived);
}
}
}
}
}
void Objects_OnNewPrim(object sender, PrimEventArgs e)
{
Primitive prim = e.Prim;
if (enabled && base.Client.Account.LoginDetails.BotConfig.GetTextures)
{
// Search this prim for textures
for (int i = 0; i < prim.Textures.FaceTextures.Length; i++)
{
Primitive.TextureEntryFace face = prim.Textures.FaceTextures[i];
if (face != null)
{
if (!alreadyRequested.ContainsKey(face.TextureID))
{
alreadyRequested[face.TextureID] = face.TextureID;
if (!File.Exists("textures/" + face.TextureID + ".jp2"))
Client.Assets.RequestImage(face.TextureID, ImageType.Normal, Assets_OnImageReceived);
}
}
}
}
}
private void Assets_OnImageReceived(TextureRequestState state, AssetTexture asset)
{
if (state == TextureRequestState.Finished && enabled && alreadyRequested.ContainsKey(asset.AssetID))
{
if (state == TextureRequestState.Finished)
{
if (!Directory.Exists("textures"))
Directory.CreateDirectory("textures");
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.Downloaded"), asset.AssetID, asset.AssetData.Length);
}
else
bot.Console.WriteLine(bot.Localization.clResourceManager.getText("Assets.Image.FailDownload"), asset.AssetID, state);
}
}
}
}