From 04c821dc5a17516e898ec4b831cdcc95c27b424b Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 18 Feb 2021 11:46:07 +0000 Subject: [PATCH] corrects a issue with better at home the bot would start itself when created and the athome system would also try and start leading to fun issues. --- BetterSecondbot/BetterAtHome/BetterAtHome.cs | 92 ++++++++++++++------ BetterSecondbot/Cli.cs | 2 +- Core/bottypes/AVstorageBot.cs | 9 +- Core/bottypes/AnimationsBot.cs | 3 +- Core/bottypes/SecondBot.cs | 4 +- Shared/BotTypes/BasicBot.cs | 3 +- 6 files changed, 73 insertions(+), 40 deletions(-) diff --git a/BetterSecondbot/BetterAtHome/BetterAtHome.cs b/BetterSecondbot/BetterAtHome/BetterAtHome.cs index e7d569c..f858f5a 100644 --- a/BetterSecondbot/BetterAtHome/BetterAtHome.cs +++ b/BetterSecondbot/BetterAtHome/BetterAtHome.cs @@ -14,10 +14,12 @@ namespace BetterSecondbot.BetterAtHome protected JsonConfig configfile; protected bool LoginFailed = false; - protected bool LoggingIn = false; + protected string whyfailed = ""; + protected bool LoggingIn = true; protected bool LoggedIn = false; protected bool StartingLogin = false; protected long LastLoginEvent = 0; + protected bool FiredAfterLogin = false; protected int homeregionIndexer = 0; protected long LastTeleportEvent = 0; protected List homeRegions = new List(); @@ -51,6 +53,7 @@ namespace BetterSecondbot.BetterAtHome LoginFailed = false; LoggingIn = false; LoggedIn = false; + FiredAfterLogin = false; homeregionIndexer = -1; LastTeleportEvent = 0; LastLoginEvent = helpers.UnixTimeNow(); @@ -69,18 +72,23 @@ namespace BetterSecondbot.BetterAtHome { resetSwitchs(); LoginFailed = true; + whyfailed = e.FailReason; } - else if(e.Status == LoginStatus.ConnectingToLogin) + if (LoginFailed == false) { - resetSwitchs(); - LoggingIn = true; - SetBetterAtHomeAction("Waiting for login to finish"); - } - else if(e.Status == LoginStatus.Success) - { - resetSwitchs(); - controler.Bot.AfterBotLoginHandler(); - LoggedIn = true; + if (e.Status == LoginStatus.ConnectingToLogin) + { + LoggingIn = true; + SetBetterAtHomeAction("Waiting for login to finish"); + } + else if (e.Status == LoginStatus.ConnectingToSim) + { + if (LoggedIn == false) + { + resetSwitchs(); + LoggedIn = true; + } + } } } @@ -124,6 +132,10 @@ namespace BetterSecondbot.BetterAtHome { return false; } + if(LoginFailed == true) + { + return false; + } if(LoggingIn == true) { return false; @@ -132,6 +144,7 @@ namespace BetterSecondbot.BetterAtHome { return false; } + return controler.Bot.GetClient.Network.Connected; } @@ -190,6 +203,22 @@ namespace BetterSecondbot.BetterAtHome return; } long dif = helpers.UnixTimeNow() - LastLoginEvent; + if (LoginFailed == true) + { + if (whyfailed != "presence") + { + SetBetterAtHomeAction("[DC] Unable to continue: " + whyfailed); + return; + } + else + { + if (dif < 45) + { + SetBetterAtHomeAction("[DC] Clearing logged in avatar 45 secs"); + return; + } + } + } if (dif < 15) { SetBetterAtHomeAction("[DC] Waiting for login lockout"); @@ -201,11 +230,6 @@ namespace BetterSecondbot.BetterAtHome SetBetterAtHomeAction("[DC] Waiting for Teleport lockout"); return; } - if (controler.Bot.KillMe == true) - { - SetBetterAtHomeAction("[DC] Marked for death"); - return; - } SetBetterAtHomeAction("[DC] Attempt to recover"); if (StartingLogin == true) { @@ -219,19 +243,6 @@ namespace BetterSecondbot.BetterAtHome protected void LoggedInAction() { - if((simname == "") || (controler.Bot.GetClient.Self.SimPosition.Z == 0)) - { - ChangedSim(null, null); - void_counter++; - SetBetterAtHomeAction("Void counter: "+ void_counter.ToString()); - if (void_counter == 10) - { - resetSwitchs(); - SetBetterAtHomeAction("Void detected - Resetting switchs"); - } - return; - } - void_counter = 0; SetBetterAtHomeAction("Logged In Actions"); if (controler.Bot.KillMe == true) { @@ -250,6 +261,29 @@ namespace BetterSecondbot.BetterAtHome SetBetterAtHomeAction("Waiting for Teleport lockout"); return; } + if ((simname == "") || (controler.Bot.GetClient.Self.SimPosition.Z == 0)) + { + ChangedSim(null, null); + } + if ((simname == "") || (controler.Bot.GetClient.Self.SimPosition.Z == 0)) + { + void_counter++; + SetBetterAtHomeAction("Void counter: " + void_counter.ToString()); + if (void_counter == 10) + { + void_counter = 0; + resetSwitchs(); + SetBetterAtHomeAction("Void detected - Resetting switchs"); + } + return; + } + if (FiredAfterLogin == false) + { + FiredAfterLogin = true; + controler.Bot.AfterBotLoginHandler(); + controler.Bot.reconnect = true; + } + void_counter = 0; if (homeRegions.Count == 0) { SetBetterAtHomeAction("No home regions"); diff --git a/BetterSecondbot/Cli.cs b/BetterSecondbot/Cli.cs index e91325a..22a9391 100644 --- a/BetterSecondbot/Cli.cs +++ b/BetterSecondbot/Cli.cs @@ -61,7 +61,7 @@ namespace BetterSecondBot { Bot.AsDocker(); } - Bot.Start(); + Bot.Start(false); attachEventListenerObjects(Config, as_docker); if(use_self_keep_alive == true) { diff --git a/Core/bottypes/AVstorageBot.cs b/Core/bottypes/AVstorageBot.cs index 6bb1775..40dedb0 100644 --- a/Core/bottypes/AVstorageBot.cs +++ b/Core/bottypes/AVstorageBot.cs @@ -221,12 +221,11 @@ namespace BetterSecondBot.bottypes { Client.Avatars.UUIDNameReply += Key2NameEvent; Client.Directory.DirPeopleReply += Name2KeyEvent; - if (helpers.notempty(myconfig.Security_MasterUsername) == true) - { - FindAvatarName2Key(myconfig.Security_MasterUsername); - } + } + if (helpers.notempty(myconfig.Security_MasterUsername) == true) + { + FindAvatarName2Key(myconfig.Security_MasterUsername); } - base.AfterBotLoginHandler(); } diff --git a/Core/bottypes/AnimationsBot.cs b/Core/bottypes/AnimationsBot.cs index 807a758..a3ec17a 100644 --- a/Core/bottypes/AnimationsBot.cs +++ b/Core/bottypes/AnimationsBot.cs @@ -14,8 +14,7 @@ namespace BetterSecondBot.bottypes if (reconnect == false) { Client.Avatars.AvatarAnimation += AvatarAnimationHandler; - } - reconnect = true; + } } public override void ResetAnimations() diff --git a/Core/bottypes/SecondBot.cs b/Core/bottypes/SecondBot.cs index 7c36b7b..5522d0c 100644 --- a/Core/bottypes/SecondBot.cs +++ b/Core/bottypes/SecondBot.cs @@ -29,9 +29,9 @@ namespace BetterSecondBot.bottypes started_friendship_hug = true; if (Client.Friends.FriendList.ContainsKey(master_uuid) == false) { - CallAPI("IM", new string[] { myconfig.Security_MasterUsername, "Hello master, I am sending you a friend request now!" }); + CallAPI("IM", new string[] { myconfig.Security_MasterUsername, "Hello master, I am sending you a friend request now!" }); + CallAPI("FriendRequest", new string[] { master_uuid.ToString(), "true" }); } - CallAPI("FriendRequest", new string[] { master_uuid.ToString(), "true" }); CallAPI("FriendFullPerms", new string[] { master_uuid.ToString(), "true" }); } } diff --git a/Shared/BotTypes/BasicBot.cs b/Shared/BotTypes/BasicBot.cs index a8330de..7e9912a 100644 --- a/Shared/BotTypes/BasicBot.cs +++ b/Shared/BotTypes/BasicBot.cs @@ -51,7 +51,8 @@ namespace BetterSecondBotShared.bottypes public JsonConfig getMyConfig { get { return myconfig; } } protected string version = "NotSet V1.0.0.0"; - protected bool reconnect; + public bool reconnect; + public string MyVersion { get { return version; } } public string Name { get { return myconfig.Basic_BotUserName; } } public string OwnerName { get { return myconfig.Security_MasterUsername; } }