new commands and http api improvements

This commit is contained in:
Madpeterz 2021-02-04 13:38:58 +00:00
parent 97c6c52abc
commit de9364a2d8
9 changed files with 307 additions and 19 deletions

View file

@ -404,12 +404,12 @@ namespace BetterSecondBotShared.Json
{
LogFormater.Warn("Http disabled: Http_Host must be vaild or \"docker\" - Given: (" + jsonConfig.Http_Host + ")");
}
else if (jsonConfig.Http_Host == "docker")
{
jsonConfig.Http_Host = "http://*:8080";
}
else
{
{
if (jsonConfig.Http_Host == "docker")
{
jsonConfig.Http_Host = "http://*:80";
}
jsonConfig.Http_Enable = true;
}
}

View file

@ -15,6 +15,18 @@ namespace BetterSecondBot.HttpService
public SecondbotInventory(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { }
[Route(HttpVerbs.Get, "/rezobject/{item}/{token}")]
public object rezobject(string item, string token, [FormField] string newname)
{
if (tokens.Allow(token, getClientIP()) == true)
{
bool status = bot.GetCommandsInterface.Call("RezObject", item);
return BasicReply(status.ToString());
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Post, "/rename/{item}/{token}")]
public object rename(string item, string token, [FormField] string newname)
{

View file

@ -46,29 +46,129 @@ namespace BetterSecondBot.HttpService
}
[Route(HttpVerbs.Get, "/friends/{token}")]
public object friends(string token)
public object Friends(string token)
{
return BasicReply(bot.getJsonFriendlist());
if (tokens.Allow(token, getClientIP()) == true)
{
return BasicReply(bot.getJsonFriendlist());
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/walkto/{x}/{y}/{z}/{token}")]
public object WalkTo(string x, string y, string z, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
bool status = bot.GetCommandsInterface.Call("AutoPilot", "<"+x+","+y+","+z+">");
if (status == true)
{
return BasicReply("Accepted");
}
return BasicReply("Error Unable to AutoPilot to location");
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/nearme/{token}")]
public object nearme(string token)
[Route(HttpVerbs.Get, "/gesture/{gesture}/{token}")]
public object Gesture(string gesture, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
bool status = bot.GetCommandsInterface.Call("PlayGesture", gesture);
if (status == true)
{
return BasicReply("Accepted");
}
return BasicReply("Error with gesture");
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/teleport/{region}/{x}/{y}/{z}/{token}")]
public object Teleport(string region,string x, string y, string z, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
bool status = bot.GetCommandsInterface.Call("Teleport", ""+region+"/" + x + "/" + y + "/" + z + "");
if (status == true)
{
return BasicReply("Accepted");
}
return BasicReply("Error Unable to Teleport to location");
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/regiontile/{regionname}/{token}")]
public object Regiontile(string regionname, string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (bot.GetClient.Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region))
{
return BasicReply(region.MapImageID.ToString());
}
else
{
return BasicReply("Unable to find region");
}
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/nearmewithdetails/{token}")]
public object NearmeWithDetails(string token)
{
if (bot.GetClient.Network.CurrentSim != null)
{
Dictionary<UUID, string> NearMe = new Dictionary<UUID, string>();
List<NearMeDetails> BetterNearMe = new List<NearMeDetails>();
Dictionary<uint, Avatar> avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy();
foreach (Avatar av in avcopy.Values)
{
if (av.ID != bot.GetClient.Self.AgentID)
{
NearMe.Add(av.ID, av.Name);
NearMeDetails details = new NearMeDetails();
details.id = av.ID.ToString();
details.name = av.Name;
details.x = (int)Math.Round(av.Position.X);
details.y = (int)Math.Round(av.Position.Y);
details.z = (int)Math.Round(av.Position.Z);
details.range = (int)Math.Round(Vector3.Distance(av.Position,bot.GetClient.Self.SimPosition));
BetterNearMe.Add(details);
}
}
return BasicReply(JsonConvert.SerializeObject(NearMe));
return BasicReply(JsonConvert.SerializeObject(BetterNearMe));
}
return BasicReply("Error");
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/nearme/{token}")]
public object Nearme(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
if (bot.GetClient.Network.CurrentSim != null)
{
Dictionary<UUID, string> NearMe = new Dictionary<UUID, string>();
Dictionary<uint, Avatar> avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy();
foreach (Avatar av in avcopy.Values)
{
if (av.ID != bot.GetClient.Self.AgentID)
{
NearMe.Add(av.ID, av.Name);
}
}
return BasicReply(JsonConvert.SerializeObject(NearMe));
}
return BasicReply("Error not in a sim");
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/hello")]
@ -107,6 +207,32 @@ namespace BetterSecondBot.HttpService
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/regionname/{token}")]
public object Regionname(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
return BasicReply(bot.GetClient.Network.CurrentSim.Name);
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Get, "/location/{token}")]
public object Location(string token)
{
if (tokens.Allow(token, getClientIP()) == true)
{
Dictionary<string, int> pos = new Dictionary<string, int>();
pos.Add("x",(int)Math.Round(bot.GetClient.Self.SimPosition.X));
pos.Add("y", (int)Math.Round(bot.GetClient.Self.SimPosition.Y));
pos.Add("z", (int)Math.Round(bot.GetClient.Self.SimPosition.Z));
return BasicReply(JsonConvert.SerializeObject(pos));
}
return BasicReply("Token not accepted");
}
[Route(HttpVerbs.Post, "/command/{token}")]
public async Task<object> command(string token)
{
@ -136,5 +262,16 @@ namespace BetterSecondBot.HttpService
public string AuthCode { get; set; }
}
public class NearMeDetails
{
public string id { get; set; }
public string name { get; set; }
public int x { get; set; }
public int y { get; set; }
public int z { get; set; }
public int range { get; set; }
}
}

View file

@ -499,6 +499,12 @@ namespace BetterSecondBot.WikiMake
core.callable.Add(new friends());
core.callable.Add(new nearme());
core.callable.Add(new hello());
core.callable.Add(new regiontile());
core.callable.Add(new location());
core.callable.Add(new regionname());
core.callable.Add(new nearmewithdetails());
core.callable.Add(new walkto());
core.callable.Add(new teleport());
endpoints.Add(core);
Endpoint inventory = new Endpoint();
inventory.name = "inventory";
@ -508,6 +514,7 @@ namespace BetterSecondBot.WikiMake
inventory.callable.Add(new realuuid());
inventory.callable.Add(new send());
inventory.callable.Add(new delete());
inventory.callable.Add(new rezobject());
endpoints.Add(inventory);
Endpoint im = new Endpoint();
im.name = "im";
@ -795,6 +802,18 @@ namespace BetterSecondBot.WikiMake
}
}
public class gesture : APIcall
{
public override void Setup()
{
about = "Attempts to play a gesture";
values.Add("gesture", new KeyValuePair<string, string>("URLARG", "UUID of the gesture"));
returns.Add("Accepted");
returns.Add("Invaild gesture UUID for arg 1");
base.Setup();
}
}
public class command : postAPIcall
{
public override void Setup()
@ -976,7 +995,7 @@ namespace BetterSecondBot.WikiMake
public override void Setup()
{
about = "fetchs the groupchat history";
values.Add("group ", new KeyValuePair<string, string>("URLARG", "UUID of the group"));
values.Add("group", new KeyValuePair<string, string>("URLARG", "UUID of the group"));
returns.Add("Group UUID invaild");
returns.Add("Group Chat");
base.Setup();
@ -988,7 +1007,7 @@ namespace BetterSecondBot.WikiMake
public override void Setup()
{
about = "sends a message to the groupchat";
values.Add("group ", new KeyValuePair<string, string>("URLARG", "UUID of the group"));
values.Add("group", new KeyValuePair<string, string>("URLARG", "UUID of the group"));
values.Add("message ", new KeyValuePair<string, string>("string", "the message to send"));
returns.Add("Group UUID invaild");
returns.Add("Processing");
@ -1006,6 +1025,92 @@ namespace BetterSecondBot.WikiMake
}
}
public class location : APIcall
{
public override void Setup()
{
about = "Fetchs the current location of the bot";
returns.Add("array of X,Y,Z values");
base.Setup();
}
}
public class walkto : APIcall
{
public override void Setup()
{
about = "uses the AutoPilot to move to a location";
values.Add("x", new KeyValuePair<string, string>("URLARG", "X location to AutoPilot to"));
values.Add("y", new KeyValuePair<string, string>("URLARG", "Y location to AutoPilot to"));
values.Add("z", new KeyValuePair<string, string>("URLARG", "Z location to AutoPilot to"));
returns.Add("Error Unable to AutoPilot to location");
returns.Add("Accepted");
base.Setup();
}
}
public class teleport : APIcall
{
public override void Setup()
{
about = "uses the AutoPilot to move to a location";
values.Add("region", new KeyValuePair<string, string>("URLARG", "the name of the region we are going to"));
values.Add("x", new KeyValuePair<string, string>("URLARG", "X location"));
values.Add("y", new KeyValuePair<string, string>("URLARG", "Y location"));
values.Add("z", new KeyValuePair<string, string>("URLARG", "Z location"));
returns.Add("Error Unable to Teleport to location");
returns.Add("Accepted");
base.Setup();
}
}
public class regionname : APIcall
{
public override void Setup()
{
about = "Fetchs the current region name";
returns.Add("string regionname");
base.Setup();
}
}
public class nearmewithdetails : APIcall
{
public override void Setup()
{
about = "an improved version of near me with extra details<br/>NearMeDetails is a object formated as follows<br/><ul><li>id</li><li>name</li><li>x</li><li>y</li><li>z</li><li>range</li></ul>";
returns.Add("array NearMeDetails");
base.Setup();
}
}
public class regiontile : APIcall
{
public override void Setup()
{
about = "Fetchs the regions map tile";
values.Add("region", new KeyValuePair<string, string>("URLARG", "string name of region"));
returns.Add("Unable to find region");
returns.Add("Texture UUID");
base.Setup();
}
}
public class rezobject : APIcall
{
public override void Setup()
{
about = "rezs the item at the bots current location";
values.Add("item", new KeyValuePair<string, string>("URLARG", "UUID of item to rez"));
returns.Add("true|false");
base.Setup();
}
}
public class localchatsay : postAPIcall
{
public override void Setup()
@ -1017,4 +1122,6 @@ namespace BetterSecondBot.WikiMake
}
}
}

View file

@ -0,0 +1,25 @@
using OpenMetaverse;
namespace BSB.Commands.Animation
{
public class PlayGesture : CoreCommand_1arg
{
public override string[] ArgTypes { get { return new[] { "UUID" }; } }
public override string[] ArgHints { get { return new[] { "The UUID of the gesture to play" }; } }
public override string Helpfile { get { return "Triggers a gesture [once]"; } }
public override bool CallFunction(string[] args)
{
if (base.CallFunction(args) == true)
{
if (UUID.TryParse(args[0], out UUID gesture) == true)
{
InventoryItem itm = bot.GetClient.Inventory.FetchItem(gesture, bot.GetClient.Self.AgentID, (3 * 1000));
bot.GetClient.Self.PlayGesture(itm.AssetUUID);
return true;
}
return Failed("Invaild gesture UUID for arg 1");
}
return false;
}
}
}

View file

@ -23,6 +23,7 @@ namespace BSB.Commands.Movement
{
if (helpers.inrange(pos.Z, 0, 5000) == true)
{
bot.GetClient.Self.AutoPilotCancel();
bot.GetClient.Self.Movement.TurnToward(pos, true);
Thread.Sleep(500);
uint Globalx, Globaly;

View file

@ -17,6 +17,7 @@ namespace BSB.Commands.Movement
{
if(base.CallFunction(args) == true)
{
bot.GetClient.Self.AutoPilotCancel();
if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true)
{
bot.TeleportWithSLurl(args[0]);

View file

@ -65,7 +65,7 @@ namespace BSB.bottypes
im_chat_unread.Add(avatar, false);
}
var date = DateTime.Now;
im_chat_history[avatar].Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + sendername + ":" + message + "");
im_chat_history[avatar].Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + sendername + ": " + message + "");
if (im_chat_history[avatar].Count > imchatlimit)
{
im_chat_history[avatar].RemoveAt(0);
@ -78,7 +78,7 @@ namespace BSB.bottypes
public override void AddToLocalChat(string name, string message)
{
var date = DateTime.Now;
LocalChat_history.Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ":" + message + "");
LocalChat_history.Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ": " + message + "");
if (LocalChat_history.Count > localchatlimit)
{
LocalChat_history.RemoveAt(0);
@ -163,7 +163,7 @@ namespace BSB.bottypes
group_chat_unread.Add(group, false);
}
var date = DateTime.Now;
group_chat_history[group].Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ":" + message + "");
group_chat_history[group].Add("[" + date.Hour.ToString() + ":" + date.Minute.ToString() + "] " + name + ": " + message + "");
if (group_chat_history[group].Count > groupchatlimit)
{
group_chat_history[group].RemoveAt(0);

View file

@ -20,11 +20,16 @@ namespace LibreMetaverse
[NonSerialized]
private readonly GridClient Client;
private static readonly HttpClient httpClient = new HttpClient();
private static HttpClient httpClient;
public InventoryAISClient(GridClient client)
{
Client = client;
HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
httpClient = new HttpClient(clientHandler);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Add("User-Agent", "LibreMetaverse AIS Client");
}