From 69b4ef9e15b901aa3d8c403d8a9d1ce88c623cb2 Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Mon, 31 May 2021 13:34:54 +0100 Subject: [PATCH] Avoid restart sims support --- BetterSecondbot/BetterAtHome/BetterAtHome.cs | 77 +++++++++++++++++--- Core/bottypes/CommandsBot.cs | 5 ++ Dockerfile | 3 +- Shared/Json/JsonConfig.cs | 2 + Shared/Json/JsonConfigApi.cs | 10 ++- 5 files changed, 83 insertions(+), 14 deletions(-) diff --git a/BetterSecondbot/BetterAtHome/BetterAtHome.cs b/BetterSecondbot/BetterAtHome/BetterAtHome.cs index 98f4db3..d1b9df6 100644 --- a/BetterSecondbot/BetterAtHome/BetterAtHome.cs +++ b/BetterSecondbot/BetterAtHome/BetterAtHome.cs @@ -5,6 +5,7 @@ using BetterSecondBot.bottypes; using OpenMetaverse; using System.Collections.Generic; using BetterSecondBotShared.logs; +using System; namespace BetterSecondbot.BetterAtHome { @@ -25,20 +26,34 @@ namespace BetterSecondbot.BetterAtHome protected int homeregionIndexer = 0; protected long LastTeleportEvent = 0; protected List homeRegions = new List(); + protected List avoidRestartRegions = new List(); protected string LastLoginStatus = "None"; + protected bool returnHomeDisabled = false; + protected long returnHomeDisabledUntill = 0; + + + + Dictionary AvoidSimList = new Dictionary(); public BetterAtHome(Cli setcontroler, JsonConfig configfile) { controler = setcontroler; this.configfile = configfile; attach_events(); SetBetterAtHomeAction("Standby"); - foreach (string a in this.configfile.Basic_HomeRegions) + foreach (string a in configfile.Basic_HomeRegions) { string[] bits = helpers.ParseSLurl(a); homeRegions.Add(bits[0]); LogFormater.Info("Added home region: " + bits[0]); } + foreach (string a in configfile.Basic_AvoidRestartRegions) + { + string[] bits = helpers.ParseSLurl(a); + avoidRestartRegions.Add(bits[0]); + LogFormater.Info("Added restart region: " + bits[0]); + } + } protected void attach_events() @@ -222,8 +237,10 @@ namespace BetterSecondbot.BetterAtHome protected void AlertMessage(object o, AlertMessageEventArgs e) { - if(e.Message.Contains("restart") == true) + if(e.Message.ToLower().Contains("restart") == true) { + returnHomeDisabled = true; + returnHomeDisabledUntill = helpers.UnixTimeNow() + (60 * 10); AvoidSim(); } } @@ -256,7 +273,7 @@ namespace BetterSecondbot.BetterAtHome return AvoidSimList.ContainsKey(bits[0]); } - Dictionary AvoidSimList = new Dictionary(); + protected void AvoidSim() { if(AvoidSimList.ContainsKey(simname) == false) @@ -322,6 +339,23 @@ namespace BetterSecondbot.BetterAtHome SetBetterAtHomeAction("Marked for death"); return; } + if (SimInAvoid() == true) + { + SetBetterAtHomeAction("Attempting to avoid this sim"); + if (gotoAvoidRestartRegion(true) == false) + { + gotoNextHomeRegion(true); + } + return; + } + long remaining = returnHomeDisabledUntill - helpers.UnixTimeNow(); + if ((returnHomeDisabled == true) && (remaining > 0)) + { + remaining = remaining / 60; + remaining++; + SetBetterAtHomeAction("Avoid restart lockout - about " + remaining.ToString() + " min('s) remaining"); + return; + } long dif = helpers.UnixTimeNow() - LastLoginEvent; if (dif < 15) { @@ -359,15 +393,9 @@ namespace BetterSecondbot.BetterAtHome return; } void_counter = 0; - if (SimInAvoid() == true) - { - SetBetterAtHomeAction("Attempting to avoid this sim"); - gotoNextHomeRegion(true); - return; - } if (controler.getBot().TeleportStatus() == true) { - SetBetterAtHomeAction("Teleported"); + SetBetterAtHomeAction("Teleported by script/master"); return; } if (homeRegions.Count == 0) @@ -384,6 +412,35 @@ namespace BetterSecondbot.BetterAtHome return; } + protected int avoidregionIndexer = -1; + protected bool gotoAvoidRestartRegion(bool force) + { + if (avoidRestartRegions.Count == 0) + { + SetBetterAtHomeAction("No avoidRestart regions"); + return false; + } + avoidregionIndexer++; + if (avoidregionIndexer >= avoidRestartRegions.Count) + { + SetBetterAtHomeAction("Attempted all avoidRestart regions giving up"); + avoidregionIndexer = -1; + return false; + } + if (IsInAvoidList(configfile.Basic_AvoidRestartRegions[avoidregionIndexer]) == true) + { + if (force == true) + { + return gotoAvoidRestartRegion(true); + } + SetBetterAtHomeAction("next avoidRegion is alreay in the avoid list"); + return false; + } + SetBetterAtHomeAction("Teleporting to avoid restart region: " + avoidRestartRegions[avoidregionIndexer]); + LastTeleportEvent = helpers.UnixTimeNow(); + controler.getBot().TeleportWithSLurl(configfile.Basic_AvoidRestartRegions[avoidregionIndexer]); + return true; + } protected void gotoNextHomeRegion(bool force) { diff --git a/Core/bottypes/CommandsBot.cs b/Core/bottypes/CommandsBot.cs index 74d9144..9e41c8f 100644 --- a/Core/bottypes/CommandsBot.cs +++ b/Core/bottypes/CommandsBot.cs @@ -300,6 +300,11 @@ namespace BetterSecondBot.bottypes if ((avatar == true) && ((sender_uuid == master_uuid) || (SubMasters.Contains(sender_name) == true))) { frommaster = true; + if(message == "fakerestart") + { + AlertMessageEventArgs args = new AlertMessageEventArgs("this is a fake restart message"); + AlertEvent(this, args); + } } try { diff --git a/Dockerfile b/Dockerfile index 69a623e..13af006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,8 +26,9 @@ COPY --from=publish /app/publish . ENV Basic_BotUserName='' ENV Basic_BotPassword='' -ENV Basic_HomeRegions='http://maps.secondlife.com/secondlife/Viserion/50/140/23' +ENV Basic_HomeRegions='Viserion/50/140/23' ENV Basic_LoginLocation='home' +ENV Basic_AvoidRestartRegions='Just the Tip/60/96/1490' ENV Security_MasterUsername='Madpeter Zond' ENV Security_SubMasters='X X,Y Y,Z Z' diff --git a/Shared/Json/JsonConfig.cs b/Shared/Json/JsonConfig.cs index 68f951b..1331f42 100644 --- a/Shared/Json/JsonConfig.cs +++ b/Shared/Json/JsonConfig.cs @@ -70,6 +70,8 @@ namespace BetterSecondBotShared.Json public string Basic_BotPassword { get; set; } public string[] Basic_HomeRegions { get; set; } + public string[] Basic_AvoidRestartRegions { get; set; } + public string Basic_LoginLocation { get; set; } // Security diff --git a/Shared/Json/JsonConfigApi.cs b/Shared/Json/JsonConfigApi.cs index 5345238..6b231ea 100644 --- a/Shared/Json/JsonConfigApi.cs +++ b/Shared/Json/JsonConfigApi.cs @@ -31,13 +31,16 @@ namespace BetterSecondBotShared.Json } else if (cmd == "Basic_HomeRegions") { - return "a CSV of SLURLs that the bot will attempt to return to after avoiding a sim shutdown (In testing)"; + return "a CSV of SLURLs that the bot will attempt to return to after avoiding a sim shutdown"; } else if (cmd == "Basic_LoginLocation") { return "the location to login to: home or last or a region/X/Y/Z string example: Tentacles/128/64/109"; } - + else if (cmd == "Basic_AvoidRestartRegions") + { + return "a CSV of SLURLs the bot will use to attempt to avoid a restart, if empty it will use HomeRegions and get stuck there"; + } return ""; } protected string GetHelp_Security(string cmd) @@ -191,8 +194,9 @@ namespace BetterSecondBotShared.Json // Basic if (cmd == "Basic_BotUserName") { return "Example Resident"; } else if (cmd == "Basic_BotPassword") { return "Pass"; } - else if (cmd == "Basic_HomeRegions") { return "http://maps.secondlife.com/secondlife/Viserion/50/140/23"; } + else if (cmd == "Basic_HomeRegions") { return "Viserion/50/140/23"; } else if (cmd == "Basic_LoginLocation") { return "home"; } + else if(cmd == "Basic_AvoidRestartRegions") { return "Just the Tip/60/96/1490"; } return ""; } protected string GetValueHint_Security(string cmd)