new command: ParcelSetMedia and helper flags
This commit is contained in:
parent
3bf412dce8
commit
fc7405d0f4
2 changed files with 197 additions and 0 deletions
183
Core/Commands/Parcel/ParcelSetMedia.cs
Normal file
183
Core/Commands/Parcel/ParcelSetMedia.cs
Normal file
|
|
@ -0,0 +1,183 @@
|
|||
using BetterSecondBotShared.Static;
|
||||
using OpenMetaverse;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BSB.Commands.CMD_Parcel
|
||||
{
|
||||
class ParcelSetMedia : CoreCommand
|
||||
{
|
||||
public override string[] ArgTypes { get { return new[] { "Flag [Repeatable]" }; } }
|
||||
public override string[] ArgHints { get { return new[] { "See flags table" }; } }
|
||||
public override int MinArgs { get { return 1; } }
|
||||
public override string Helpfile { get { return "Supports updating one or multiple media options for the current parcel<br/>Example: ParcelSetMedia|||MediaURL=http://google.com~#~MediaDesc=Google.com website<br/>Flags: " + helpers.create_dirty_table(parcel_static.get_flag_names()) + "<br/>"; } }
|
||||
|
||||
public override bool CallFunction(string[] args)
|
||||
{
|
||||
if (base.CallFunction(args) == true)
|
||||
{
|
||||
int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition);
|
||||
Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid];
|
||||
if(parcel_static.has_parcel_perm(p,bot) == true)
|
||||
{
|
||||
bool all_flags_ok = true;
|
||||
string why_failed = "";
|
||||
int loop = 1;
|
||||
foreach (string A in args)
|
||||
{
|
||||
bool format_failed = false;
|
||||
string[] bits = A.Split('=');
|
||||
if (bits.Length == 2)
|
||||
{
|
||||
switch (bits[0])
|
||||
{
|
||||
case "MediaType":
|
||||
{
|
||||
if (bits[1] == "IMG-PNG")
|
||||
{
|
||||
p.Media.MediaType = "image/png";
|
||||
}
|
||||
else if (bits[1] == "IMG-JPG")
|
||||
{
|
||||
p.Media.MediaType = "image/jpeg";
|
||||
}
|
||||
else if (bits[1] == "VID-MP4")
|
||||
{
|
||||
p.Media.MediaType = "video/mp4";
|
||||
}
|
||||
else if (bits[1] == "VID-AVI")
|
||||
{
|
||||
p.Media.MediaType = "video/x-msvideo";
|
||||
}
|
||||
else if(bits[1].StartsWith("Custom-") == true)
|
||||
{
|
||||
string mime = bits[1];
|
||||
mime = mime.Replace("Custom-", "");
|
||||
p.Media.MediaType = mime;
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "MediaWidth":
|
||||
case "MediaHeight":
|
||||
{
|
||||
if (int.TryParse(bits[1], out int size) == true)
|
||||
{
|
||||
if ((size >= 256) || (size <= 1024))
|
||||
{
|
||||
if (bits[0] == "MediaHeight")
|
||||
{
|
||||
p.Media.MediaHeight = size;
|
||||
}
|
||||
else if (bits[0] == "MediaWidth")
|
||||
{
|
||||
p.Media.MediaWidth = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true; // not sure how this happened
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "MediaID":
|
||||
{
|
||||
if (UUID.TryParse(bits[1], out UUID texture) == true)
|
||||
{
|
||||
p.Media.MediaID = texture;
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "MediaURL":
|
||||
{
|
||||
p.Media.MediaURL = bits[1];
|
||||
break;
|
||||
}
|
||||
case "MediaDesc":
|
||||
{
|
||||
p.Media.MediaDesc = bits[1];
|
||||
break;
|
||||
}
|
||||
case "MediaAutoScale":
|
||||
{
|
||||
if(bool.TryParse(bits[1],out bool output) == true)
|
||||
{
|
||||
p.Media.MediaAutoScale = output;
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "MediaLoop":
|
||||
{
|
||||
if (bool.TryParse(bits[1], out bool output) == true)
|
||||
{
|
||||
p.Media.MediaLoop = output;
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
why_failed = "Arg:" + loop.ToString() + " is not a supported media option!";
|
||||
all_flags_ok = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
format_failed = true;
|
||||
}
|
||||
if(format_failed == true)
|
||||
{
|
||||
why_failed = "Arg:" + loop.ToString() + " Not formated correctly";
|
||||
all_flags_ok = false;
|
||||
}
|
||||
if (all_flags_ok == false)
|
||||
{
|
||||
break;
|
||||
}
|
||||
loop++;
|
||||
}
|
||||
if(all_flags_ok == true)
|
||||
{
|
||||
p.Update(bot.GetClient.Network.CurrentSim, false);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Failed(why_failed);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Failed("Do not have expected perms for this parcel!");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,20 @@ namespace BSB
|
|||
flagnames.Remove("None");
|
||||
return flagnames.ToArray();
|
||||
}
|
||||
|
||||
public static Dictionary<string, string> get_media_list()
|
||||
{
|
||||
Dictionary<string, string> flags = new Dictionary<string, string>();
|
||||
flags.Add("MediaAutoScale", "Bool (True|False)");
|
||||
flags.Add("MediaLoop", "Bool (True|False)");
|
||||
flags.Add("MediaID", "UUID (Texture)");
|
||||
flags.Add("MediaURL", "String");
|
||||
flags.Add("MediaDesc", "String");
|
||||
flags.Add("MediaHeight", "Int (256 to 1024)");
|
||||
flags.Add("MediaWidth", "Int (256 to 1024)");
|
||||
flags.Add("MediaType", "String [\"IMG-PNG\",\"IMG-JPG\",\"VID-MP4\",\"VID-AVI\" or \"Custom-MIME_TYPE_CODE\"]");
|
||||
return flags;
|
||||
}
|
||||
public static Dictionary<string, ParcelFlags> get_flags_list()
|
||||
{
|
||||
Dictionary<string, ParcelFlags> flags = new Dictionary<string, ParcelFlags>();
|
||||
|
|
|
|||
Loading…
Reference in a new issue