improvements to the way the bot handles logins and recovery
This commit is contained in:
parent
eebebc92ea
commit
03a39741e4
4 changed files with 131 additions and 77 deletions
|
|
@ -17,6 +17,8 @@ namespace BetterSecondBotShared.bottypes
|
||||||
LastStatusMessage = "No status";
|
LastStatusMessage = "No status";
|
||||||
}
|
}
|
||||||
protected List<string> SubMasters = new List<string>();
|
protected List<string> SubMasters = new List<string>();
|
||||||
|
protected bool attempted_first_login = false;
|
||||||
|
protected bool login_failed = false;
|
||||||
public bool Is_avatar_master(string name)
|
public bool Is_avatar_master(string name)
|
||||||
{
|
{
|
||||||
if (name == myconfig.Security_MasterUsername)
|
if (name == myconfig.Security_MasterUsername)
|
||||||
|
|
@ -208,6 +210,7 @@ namespace BetterSecondBotShared.bottypes
|
||||||
{
|
{
|
||||||
if (myconfig.Setting_loginURI.Length > 5)
|
if (myconfig.Setting_loginURI.Length > 5)
|
||||||
{
|
{
|
||||||
|
Info("Using custom login server");
|
||||||
Lp = new LoginParams(Client, bits[0], bits[1], myconfig.Basic_BotPassword, "BetterSecondBot", version, myconfig.Setting_loginURI);
|
Lp = new LoginParams(Client, bits[0], bits[1], myconfig.Basic_BotPassword, "BetterSecondBot", version, myconfig.Setting_loginURI);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -235,6 +238,7 @@ namespace BetterSecondBotShared.bottypes
|
||||||
Info("Basic_LoginLocation: is set to a uri! if login fails try using home or last");
|
Info("Basic_LoginLocation: is set to a uri! if login fails try using home or last");
|
||||||
}
|
}
|
||||||
Lp.Start = myconfig.Basic_LoginLocation;
|
Lp.Start = myconfig.Basic_LoginLocation;
|
||||||
|
Info("Basic_LoginLocation: First login using->"+Lp.Start);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,10 @@ namespace BetterSecondBotShared.Json
|
||||||
{
|
{
|
||||||
return "the URI to login to (leave as \"secondlife\" unless you know what your doing!)";
|
return "the URI to login to (leave as \"secondlife\" unless you know what your doing!)";
|
||||||
}
|
}
|
||||||
|
else if (cmd == "Setting_LogCommands")
|
||||||
|
{
|
||||||
|
return "Allow the bot to send command to console and discord full if enabled";
|
||||||
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
protected string GetHelp_Discord(string cmd)
|
protected string GetHelp_Discord(string cmd)
|
||||||
|
|
@ -174,11 +178,10 @@ namespace BetterSecondBotShared.Json
|
||||||
+ "2: +Crititcal\n"
|
+ "2: +Crititcal\n"
|
||||||
+ "3: +Warnings\n"
|
+ "3: +Warnings\n"
|
||||||
+ "4: +Debug\n";
|
+ "4: +Debug\n";
|
||||||
}
|
}
|
||||||
else if (cmd == "Setting_LogCommands")
|
// Name2Key
|
||||||
{
|
else if (cmd == "Name2Key_Url") { return "url to the name to key provider"; }
|
||||||
return "Allow the bot to send command to console and discord full if enabled";
|
else if (cmd == "Name2Key_Key") { return "access code for the provider"; }
|
||||||
}
|
|
||||||
return "Unknown value:" + cmd;
|
return "Unknown value:" + cmd;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -189,6 +192,7 @@ namespace BetterSecondBotShared.Json
|
||||||
else if (cmd.StartsWith("Settings") == true) { return GetHelp_Settings(cmd); }
|
else if (cmd.StartsWith("Settings") == true) { return GetHelp_Settings(cmd); }
|
||||||
else if (cmd.StartsWith("DiscordTTS") == true) { return GetHelp_DiscordTTS(cmd); }
|
else if (cmd.StartsWith("DiscordTTS") == true) { return GetHelp_DiscordTTS(cmd); }
|
||||||
else if (cmd.StartsWith("Discord") == true) { return GetHelp_Discord(cmd); }
|
else if (cmd.StartsWith("Discord") == true) { return GetHelp_Discord(cmd); }
|
||||||
|
else if (cmd.StartsWith("Http_") == true) { return GetHelp_HTTP(cmd); }
|
||||||
else { return GetHelp_Logs(cmd); }
|
else { return GetHelp_Logs(cmd); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,7 +249,8 @@ namespace BetterSecondBotShared.Json
|
||||||
else if (cmd == "Setting_AllowFunds") { return "True"; }
|
else if (cmd == "Setting_AllowFunds") { return "True"; }
|
||||||
else if (cmd == "Setting_RelayImToAvatarUUID") { return ""; }
|
else if (cmd == "Setting_RelayImToAvatarUUID") { return ""; }
|
||||||
else if (cmd == "Setting_DefaultSit_UUID") { return ""; }
|
else if (cmd == "Setting_DefaultSit_UUID") { return ""; }
|
||||||
else if (cmd == "Setting_loginURI") { return "secondlife"; }
|
else if (cmd == "Setting_loginURI") { return "secondlife"; }
|
||||||
|
else if (cmd == "Setting_LogCommands") { return "True"; }
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
protected string GetValueHint_Discord(string cmd)
|
protected string GetValueHint_Discord(string cmd)
|
||||||
|
|
@ -282,7 +287,9 @@ namespace BetterSecondBotShared.Json
|
||||||
// Logs
|
// Logs
|
||||||
if (cmd == "Log2File_Enable") { return "False"; }
|
if (cmd == "Log2File_Enable") { return "False"; }
|
||||||
else if (cmd == "Log2File_Level") { return "1"; }
|
else if (cmd == "Log2File_Level") { return "1"; }
|
||||||
else if (cmd == "Setting_LogCommands") { return "True"; }
|
// Name2Key
|
||||||
|
else if(cmd == "Name2Key_Url") { return ""; }
|
||||||
|
else if(cmd == "Name2Key_Key") { return ""; }
|
||||||
return "Unknown value:" + cmd;
|
return "Unknown value:" + cmd;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -291,9 +298,10 @@ namespace BetterSecondBotShared.Json
|
||||||
{
|
{
|
||||||
if (cmd.StartsWith("Basic") == true) { return GetValueHint_Basic(cmd); }
|
if (cmd.StartsWith("Basic") == true) { return GetValueHint_Basic(cmd); }
|
||||||
else if (cmd.StartsWith("Security") == true) { return GetValueHint_Security(cmd); }
|
else if (cmd.StartsWith("Security") == true) { return GetValueHint_Security(cmd); }
|
||||||
else if (cmd.StartsWith("Settings") == true) { return GetValueHint_Settings(cmd); }
|
else if (cmd.StartsWith("Setting_") == true) { return GetValueHint_Settings(cmd); }
|
||||||
else if (cmd.StartsWith("DiscordTTS") == true) { return GetValueHint_DiscordTTS(cmd); }
|
else if (cmd.StartsWith("DiscordTTS_") == true) { return GetValueHint_DiscordTTS(cmd); }
|
||||||
else if (cmd.StartsWith("Discord") == true) { return GetValueHint_Discord(cmd); }
|
else if (cmd.StartsWith("Discord") == true) { return GetValueHint_Discord(cmd); }
|
||||||
|
else if (cmd.StartsWith("Http_") == true) { return GetValueHint_HTTP(cmd); }
|
||||||
else { return GetValueHint_Logs(cmd); }
|
else { return GetValueHint_Logs(cmd); }
|
||||||
}
|
}
|
||||||
public override int GetCommandArgs(string cmd)
|
public override int GetCommandArgs(string cmd)
|
||||||
|
|
|
||||||
|
|
@ -155,14 +155,16 @@ namespace BSB.bottypes
|
||||||
protected string login_status = "Waiting to login";
|
protected string login_status = "Waiting to login";
|
||||||
protected override void LoginHandler(object o, LoginProgressEventArgs e)
|
protected override void LoginHandler(object o, LoginProgressEventArgs e)
|
||||||
{
|
{
|
||||||
|
attempted_first_login = true;
|
||||||
|
login_failed = false;
|
||||||
if (e.Status == LoginStatus.Success)
|
if (e.Status == LoginStatus.Success)
|
||||||
{
|
{
|
||||||
login_status = "Ok";
|
login_status = "Ok";
|
||||||
AfterBotLoginHandler();
|
|
||||||
}
|
}
|
||||||
else if(e.Status == LoginStatus.Failed)
|
else if(e.Status == LoginStatus.Failed)
|
||||||
{
|
{
|
||||||
login_status = "Login failed";
|
login_failed = true;
|
||||||
|
login_status = "Login failed <"+e.Message+">";
|
||||||
login_auto_logout = true;
|
login_auto_logout = true;
|
||||||
if (e.FailReason == "presence")
|
if (e.FailReason == "presence")
|
||||||
{
|
{
|
||||||
|
|
@ -189,6 +191,7 @@ namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
login_status = "Redirecting";
|
login_status = "Redirecting";
|
||||||
}
|
}
|
||||||
|
Info("Login status -> " + login_status);
|
||||||
|
|
||||||
}
|
}
|
||||||
public virtual void GroupsHandler(object sender, CurrentGroupsEventArgs e)
|
public virtual void GroupsHandler(object sender, CurrentGroupsEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -9,55 +9,110 @@ namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
public abstract class AtHome : MessageSwitcherBot
|
public abstract class AtHome : MessageSwitcherBot
|
||||||
{
|
{
|
||||||
protected string LoggedOutNextAction()
|
protected long ConnectionLostAt = 0;
|
||||||
|
protected override void AfterBotLoginHandler()
|
||||||
{
|
{
|
||||||
string addon = "";
|
base.AfterBotLoginHandler();
|
||||||
long dif = helpers.UnixTimeNow() - last_reconnect_attempt;
|
last_tp_attempt_unixtime = helpers.UnixTimeNow() + 30;
|
||||||
if ((login_auto_logout == false) && (reconnect_mode == false) && (after_login_fired == true))
|
if (reconnect == true)
|
||||||
{
|
{
|
||||||
|
ResetAtHome();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Client.Self.AlertMessage += AlertEvent;
|
||||||
|
Client.Network.SimChanged += ChangeSim;
|
||||||
|
}
|
||||||
|
if (Client.Network.Connected == true)
|
||||||
|
{
|
||||||
|
if (Client.Network.CurrentSim != null)
|
||||||
|
{
|
||||||
|
if (IsSimHome(Client.Network.CurrentSim.Name) == true)
|
||||||
|
{
|
||||||
|
if (UUID.TryParse(myconfig.Setting_DefaultSit_UUID, out UUID sit_UUID) == true)
|
||||||
|
{
|
||||||
|
Client.Self.RequestSit(sit_UUID, Vector3.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
after_login_fired = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string FirstLoginStage()
|
||||||
|
{
|
||||||
|
long dif = helpers.UnixTimeNow() - last_reconnect_attempt;
|
||||||
|
if (login_auto_logout == true)
|
||||||
|
{
|
||||||
|
if (last_reconnect_attempt == 0)
|
||||||
|
{
|
||||||
|
return login_status;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (auto_logout_login_recover == false)
|
||||||
|
{
|
||||||
|
auto_logout_login_recover = true;
|
||||||
|
last_reconnect_attempt = helpers.UnixTimeNow();
|
||||||
|
return "W4>" + login_status + " (20 secs)";
|
||||||
|
}
|
||||||
|
else if (dif >= 20)
|
||||||
|
{
|
||||||
|
login_auto_logout = false;
|
||||||
|
auto_logout_login_recover = false;
|
||||||
|
last_reconnect_attempt = helpers.UnixTimeNow();
|
||||||
|
Start(true);
|
||||||
|
return "Restarting first login [Using Alt locations]";
|
||||||
|
}
|
||||||
|
return "Waiting for cooldown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return login_status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string LoggedInConnectionLost()
|
||||||
|
{
|
||||||
|
long dif = helpers.UnixTimeNow() - last_reconnect_attempt;
|
||||||
|
if (reconnect_mode == true)
|
||||||
|
{
|
||||||
last_tested_home_id = -1;
|
last_tested_home_id = -1;
|
||||||
last_tp_attempt_unixtime = 0;
|
last_tp_attempt_unixtime = 0;
|
||||||
after_login_fired = false;
|
after_login_fired = false;
|
||||||
teleported = false;
|
teleported = false;
|
||||||
reconnect_mode = true;
|
reconnect_mode = true;
|
||||||
last_reconnect_attempt = helpers.UnixTimeNow();
|
last_reconnect_attempt = helpers.UnixTimeNow();
|
||||||
addon = "Connection lost - switching to recovery mode";
|
return "Connection lost - switching to recovery mode";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (dif <= 60)
|
||||||
|
{
|
||||||
|
return "W4> Network reset timeout [60 secs]";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
last_reconnect_attempt = helpers.UnixTimeNow();
|
||||||
|
reconnect = true;
|
||||||
|
Start(true);
|
||||||
|
return "Attempting reconnect";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected string LoggedOutNextAction()
|
||||||
|
{
|
||||||
|
if (login_auto_logout == true)
|
||||||
|
{
|
||||||
|
return FirstLoginStage();
|
||||||
|
}
|
||||||
|
if ((attempted_first_login == true) && (login_failed == true))
|
||||||
|
{
|
||||||
|
return LoggedInConnectionLost();
|
||||||
}
|
}
|
||||||
else if ((login_auto_logout == false) && (reconnect_mode == false) && (after_login_fired == false))
|
return "";
|
||||||
{
|
|
||||||
addon = login_status;
|
|
||||||
}
|
|
||||||
else if ((login_auto_logout == false) && (reconnect_mode == true) && (dif > 120))
|
|
||||||
{
|
|
||||||
addon = "Attempting reconnect";
|
|
||||||
last_reconnect_attempt = helpers.UnixTimeNow();
|
|
||||||
reconnect = true;
|
|
||||||
Start(true);
|
|
||||||
}
|
|
||||||
else if ((login_auto_logout == false) && (reconnect_mode == true) && (dif <= 120))
|
|
||||||
{
|
|
||||||
addon = "W4>Reconnect attempt timer";
|
|
||||||
}
|
|
||||||
else if ((login_auto_logout == true) && (auto_logout_login_recover == false))
|
|
||||||
{
|
|
||||||
auto_logout_login_recover = true;
|
|
||||||
last_reconnect_attempt = helpers.UnixTimeNow();
|
|
||||||
addon = "W4>" + login_status + " (10 secs)";
|
|
||||||
}
|
|
||||||
else if ((login_auto_logout == true) && (auto_logout_login_recover == true) && (dif >= 10))
|
|
||||||
{
|
|
||||||
login_auto_logout = false;
|
|
||||||
auto_logout_login_recover = false;
|
|
||||||
last_reconnect_attempt = helpers.UnixTimeNow();
|
|
||||||
addon = "Restarting first login";
|
|
||||||
Start();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
addon = login_status;
|
|
||||||
}
|
|
||||||
Debug("Function/LoggedOutNextAction - "+ addon);
|
|
||||||
return addon;
|
|
||||||
}
|
}
|
||||||
protected int last_tested_home_id = -1;
|
protected int last_tested_home_id = -1;
|
||||||
protected long last_tp_attempt_unixtime;
|
protected long last_tp_attempt_unixtime;
|
||||||
|
|
@ -119,6 +174,7 @@ namespace BSB.bottypes
|
||||||
teleported = false;
|
teleported = false;
|
||||||
reconnect_mode = false;
|
reconnect_mode = false;
|
||||||
last_tp_attempt_unixtime = 0;
|
last_tp_attempt_unixtime = 0;
|
||||||
|
avoid_sims = new Dictionary<string, long>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -134,10 +190,14 @@ namespace BSB.bottypes
|
||||||
|
|
||||||
protected void ExpireOldAvoidSims()
|
protected void ExpireOldAvoidSims()
|
||||||
{
|
{
|
||||||
if(avoid_sims.Count() > 0)
|
if (avoid_sims.Count() > 0)
|
||||||
{
|
{
|
||||||
List<string> remove_keys = new List<string>();
|
List<string> remove_keys = new List<string>();
|
||||||
long now = helpers.UnixTimeNow();
|
long now = helpers.UnixTimeNow();
|
||||||
|
if (GetClient.Network.Connected == false)
|
||||||
|
{
|
||||||
|
now -= 240; // when logged out, add 240s to all sims we are avoiding
|
||||||
|
}
|
||||||
foreach (KeyValuePair<string,long> avoids in avoid_sims)
|
foreach (KeyValuePair<string,long> avoids in avoid_sims)
|
||||||
{
|
{
|
||||||
if(avoids.Value < now)
|
if(avoids.Value < now)
|
||||||
|
|
@ -351,6 +411,10 @@ namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
if (Client.Network.CurrentSim != null)
|
if (Client.Network.CurrentSim != null)
|
||||||
{
|
{
|
||||||
|
if(after_login_fired == false)
|
||||||
|
{
|
||||||
|
AfterBotLoginHandler();
|
||||||
|
}
|
||||||
reply = AtHomeStatus(LoggedinAthome());
|
reply = AtHomeStatus(LoggedinAthome());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -370,31 +434,6 @@ namespace BSB.bottypes
|
||||||
return base.GetStatus();
|
return base.GetStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void AfterBotLoginHandler()
|
|
||||||
{
|
|
||||||
base.AfterBotLoginHandler();
|
|
||||||
last_tp_attempt_unixtime = helpers.UnixTimeNow() + 30;
|
|
||||||
if (reconnect == true)
|
|
||||||
{
|
|
||||||
ResetAtHome();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Client.Self.AlertMessage += AlertEvent;
|
|
||||||
Client.Network.SimChanged += ChangeSim;
|
|
||||||
}
|
|
||||||
if (IsSimHome(Client.Network.CurrentSim.Name) == true)
|
|
||||||
{
|
|
||||||
if (UUID.TryParse(myconfig.Setting_DefaultSit_UUID, out UUID sit_UUID) == true)
|
|
||||||
{
|
|
||||||
Client.Self.RequestSit(sit_UUID, Vector3.Zero);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
after_login_fired = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public string TeleportWithSLurl(string sl_url)
|
public string TeleportWithSLurl(string sl_url)
|
||||||
{
|
{
|
||||||
string[] bits = helpers.ParseSLurl(sl_url);
|
string[] bits = helpers.ParseSLurl(sl_url);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue