From 3e58148299ddaa2b8ae211654eae2bdf5c2836ea Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:06:33 +0000 Subject: [PATCH] add support for DefaultHoverHeight and new HoverHeight command --- Dockerfile | 2 ++ SecondBotEvents/Commands/Movement.cs | 18 ++++++++++++++++++ SecondBotEvents/Config/BasicConfig.cs | 5 +++++ SecondBotEvents/Config/config.cs | 10 ++++++++++ SecondBotEvents/Services/BotClientService.cs | 7 ++++++- SecondBotEvents/Static/Helpers.cs | 11 +++++++++++ 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7274214..2a2b428 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,6 +25,8 @@ COPY --from=publish /app/publish . ENV basic_Username='' \ basic_Password='' \ basic_LoginURI='secondlife' \ + basic_LogCommands='true' \ + basic_DefaultHoverHeight=0.1 \ commands_AllowFundsCommands='false' \ commands_AllowIMcontrol='false' \ commands_SharedSecret='examplecode' \ diff --git a/SecondBotEvents/Commands/Movement.cs b/SecondBotEvents/Commands/Movement.cs index e5f18d5..6692718 100644 --- a/SecondBotEvents/Commands/Movement.cs +++ b/SecondBotEvents/Commands/Movement.cs @@ -13,6 +13,24 @@ namespace SecondBotEvents.Commands { } + [About("Adjusts Hover height")] + [ReturnHints("ok")] + [ReturnHintsFailure("Convert to float has failed")] + [ReturnHintsFailure("value out of range (-2.0, 2.0)")] + [ArgHints("height", "what height to hover at from (-2.0, 2.0)")] + public object HoverHeight(string height) + { + if (double.TryParse(height, out double level) == false) + { + return Failure("Convert to float has failed", new[] { height }); + } + if (SecondbotHelpers.inrange(level, -2.0, 2.0) == false) + { + return Failure("height value out of range(-2.0 to 2.0)", new[] { height }); + } + GetClient().Self.SetHoverHeight(level); + return BasicReply("ok", new[] { height }); + } [About("uses the AutoPilot to move to a location")] [ReturnHints("Error Unable to AutoPilot to location")] diff --git a/SecondBotEvents/Config/BasicConfig.cs b/SecondBotEvents/Config/BasicConfig.cs index d5bf416..bdf5322 100644 --- a/SecondBotEvents/Config/BasicConfig.cs +++ b/SecondBotEvents/Config/BasicConfig.cs @@ -14,8 +14,13 @@ namespace SecondBotEvents.Config settings.Add("Password"); settings.Add("LoginURI"); settings.Add("LogCommands"); + settings.Add("DefaultHoverHeight"); } + public double GetDefaultHoverHeight() + { + return ReadSettingAsDouble("DefaultHoverHeight", 0.1); + } public bool GetLogCommands() { return ReadSettingAsBool("LogCommands"); diff --git a/SecondBotEvents/Config/config.cs b/SecondBotEvents/Config/config.cs index 26d53f2..4825d33 100644 --- a/SecondBotEvents/Config/config.cs +++ b/SecondBotEvents/Config/config.cs @@ -169,5 +169,15 @@ namespace SecondBotEvents.Config } return value; } + + protected double ReadSettingAsDouble(string key, double defaultValue = 0) + { + bool result = double.TryParse(ReadSettingAsString(key, defaultValue.ToString()), out double value); + if (result == false) + { + return defaultValue; + } + return value; + } } } diff --git a/SecondBotEvents/Services/BotClientService.cs b/SecondBotEvents/Services/BotClientService.cs index aea377b..bd63ccd 100644 --- a/SecondBotEvents/Services/BotClientService.cs +++ b/SecondBotEvents/Services/BotClientService.cs @@ -1,4 +1,5 @@ -using OpenMetaverse; +using log4net.Core; +using OpenMetaverse; using OpenMetaverse.Assets; using SecondBotEvents.Config; using Swan; @@ -61,6 +62,10 @@ namespace SecondBotEvents.Services protected void BotSimConnected(object o, SimConnectedEventArgs e) { + if(AutoRestartLoginTimer.Enabled == true) + { + GetClient().Self.SetHoverHeight(basicCfg.GetDefaultHoverHeight()); + } AutoRestartLoginTimer.Stop(); LogFormater.Info("Client service ~ Connected to sim: "+e.Simulator.Name); } diff --git a/SecondBotEvents/Static/Helpers.cs b/SecondBotEvents/Static/Helpers.cs index 047c91c..2c4554c 100644 --- a/SecondBotEvents/Static/Helpers.cs +++ b/SecondBotEvents/Static/Helpers.cs @@ -81,6 +81,17 @@ namespace SecondBotEvents } return false; } + public static bool inrange(double current, double min, double max) + { + if (current <= max) + { + if (current >= min) + { + return true; + } + } + return false; + } public static bool inbox(float expected, float current, float drift) { return distance_check(expected, current, drift, true);