adjust how the bot deals with DC events
This commit is contained in:
parent
dff8897804
commit
41272be55a
18 changed files with 205 additions and 41 deletions
|
|
@ -1213,6 +1213,10 @@ namespace OpenMetaverse.StructuredData
|
||||||
|
|
||||||
public static OSD Deserialize(byte[] data)
|
public static OSD Deserialize(byte[] data)
|
||||||
{
|
{
|
||||||
|
if(data == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
string header = Encoding.ASCII.GetString(data, 0, data.Length >= 17 ? 17 : data.Length);
|
string header = Encoding.ASCII.GetString(data, 0, data.Length >= 17 ? 17 : data.Length);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ namespace SecondBotEvents
|
||||||
public TriggerOnEventService TriggerOnEventService { get { return (TriggerOnEventService)GetService("TriggerOnEventService"); } }
|
public TriggerOnEventService TriggerOnEventService { get { return (TriggerOnEventService)GetService("TriggerOnEventService"); } }
|
||||||
|
|
||||||
public CurrentOutfitFolder CurrentOutfitFolder { get { return (CurrentOutfitFolder)GetService("CurrentOutfitFolder"); } }
|
public CurrentOutfitFolder CurrentOutfitFolder { get { return (CurrentOutfitFolder)GetService("CurrentOutfitFolder"); } }
|
||||||
|
public RecoveryService RecoveryService { get { return (RecoveryService)GetService("RecoveryService"); } }
|
||||||
public RLVService RLV { get { return (RLVService)GetService("RLVService"); } }
|
public RLVService RLV { get { return (RLVService)GetService("RLVService"); } }
|
||||||
|
|
||||||
public CustomCommandsService CustomCommandsService { get { return (CustomCommandsService)GetService("CustomCommandsService"); } }
|
public CustomCommandsService CustomCommandsService { get { return (CustomCommandsService)GetService("CustomCommandsService"); } }
|
||||||
|
|
@ -75,10 +76,10 @@ namespace SecondBotEvents
|
||||||
}
|
}
|
||||||
private readonly object BotclientEventNoticesLockable = new object();
|
private readonly object BotclientEventNoticesLockable = new object();
|
||||||
|
|
||||||
public void TriggerBotClientEvent(bool asRestart)
|
public void TriggerBotClientEvent(bool asRestart,bool asDC)
|
||||||
{
|
{
|
||||||
EventHandler<BotClientNotice> handler = BotclientEventNotices;
|
EventHandler<BotClientNotice> handler = BotclientEventNotices;
|
||||||
handler?.Invoke(this, new BotClientNotice(asRestart));
|
handler?.Invoke(this, new BotClientNotice(asRestart, asDC));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -151,10 +152,12 @@ namespace SecondBotEvents
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void StartServices()
|
public void StartServices()
|
||||||
{
|
{
|
||||||
|
Ready = false;
|
||||||
services = new Dictionary<string, BotServices>();
|
services = new Dictionary<string, BotServices>();
|
||||||
lastStatus = new Dictionary<string, string>();
|
lastStatus = new Dictionary<string, string>();
|
||||||
|
StopService("RecoveryService"); // kill the recovery service if its still running
|
||||||
RegisterService("BotClientService", false);
|
RegisterService("BotClientService", false);
|
||||||
RegisterService("DataStoreService");
|
RegisterService("DataStoreService");
|
||||||
RegisterService("RLVService");
|
RegisterService("RLVService");
|
||||||
|
|
@ -170,6 +173,7 @@ namespace SecondBotEvents
|
||||||
RegisterService("TriggerOnEventService");
|
RegisterService("TriggerOnEventService");
|
||||||
RegisterService("RelayService");
|
RegisterService("RelayService");
|
||||||
RegisterService("ChatGptService");
|
RegisterService("ChatGptService");
|
||||||
|
RegisterService("RecoveryService");
|
||||||
if (BotClient.IsLoaded() == false)
|
if (BotClient.IsLoaded() == false)
|
||||||
{
|
{
|
||||||
LogFormater.Info("Config is not loaded :(");
|
LogFormater.Info("Config is not loaded :(");
|
||||||
|
|
@ -178,7 +182,6 @@ namespace SecondBotEvents
|
||||||
}
|
}
|
||||||
BotClient.Start();
|
BotClient.Start();
|
||||||
Ready = true;
|
Ready = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, string> lastStatus = new Dictionary<string, string>();
|
Dictionary<string, string> lastStatus = new Dictionary<string, string>();
|
||||||
|
|
@ -205,22 +208,36 @@ namespace SecondBotEvents
|
||||||
TriggerSystemStatusMessageEvent(false, "");
|
TriggerSystemStatusMessageEvent(false, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void StopServices()
|
public void StopService(string service)
|
||||||
|
{
|
||||||
|
if (services.ContainsKey(service) == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
services[service].Stop();
|
||||||
|
services.Remove(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void StopServices(string skip="")
|
||||||
{
|
{
|
||||||
Ready = false;
|
Ready = false;
|
||||||
Dictionary<string, BotServices> copy = services;
|
Dictionary<string, BotServices> copy = services;
|
||||||
foreach (KeyValuePair<string, BotServices> A in copy)
|
foreach (KeyValuePair<string, BotServices> A in copy)
|
||||||
{
|
{
|
||||||
if(A.Key == "BotClientService")
|
if((A.Key == "BotClientService") || (A.Key == skip))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
A.Value.Stop();
|
A.Value.Stop();
|
||||||
services.Remove(A.Key);
|
services.Remove(A.Key);
|
||||||
}
|
}
|
||||||
|
if (skip == "")
|
||||||
|
{
|
||||||
services["BotClientService"].Stop();
|
services["BotClientService"].Stop();
|
||||||
services.Remove("BotClientService");
|
services.Remove("BotClientService");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Exit()
|
public bool Exit()
|
||||||
{
|
{
|
||||||
|
|
@ -244,9 +261,16 @@ namespace SecondBotEvents
|
||||||
public class BotClientNotice
|
public class BotClientNotice
|
||||||
{
|
{
|
||||||
public bool isRestart = false;
|
public bool isRestart = false;
|
||||||
public BotClientNotice(bool asRestart=false)
|
public bool isDC = false;
|
||||||
|
public bool isStart = false;
|
||||||
|
public BotClientNotice(bool asRestart=false, bool asDC=false)
|
||||||
{
|
{
|
||||||
isRestart = asRestart;
|
isRestart = asRestart;
|
||||||
|
isDC = asDC;
|
||||||
|
if((isRestart == false) && (isDC == false))
|
||||||
|
{
|
||||||
|
isStart = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ namespace SecondBotEvents.Services
|
||||||
LogoutExpected = true;
|
LogoutExpected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool getLogoutExpected()
|
||||||
|
{
|
||||||
|
return LogoutExpected;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsConnected()
|
public bool IsConnected()
|
||||||
{
|
{
|
||||||
if (client == null) { return false; }
|
if (client == null) { return false; }
|
||||||
|
|
@ -40,6 +45,7 @@ namespace SecondBotEvents.Services
|
||||||
protected void RestartTimer(object o, ElapsedEventArgs e)
|
protected void RestartTimer(object o, ElapsedEventArgs e)
|
||||||
{
|
{
|
||||||
AutoRestartLoginTimer.Stop();
|
AutoRestartLoginTimer.Stop();
|
||||||
|
AutoRestartLoginTimer = null;
|
||||||
LogFormater.Info("Recovery underway - waiting 4 secs then restarting bot");
|
LogFormater.Info("Recovery underway - waiting 4 secs then restarting bot");
|
||||||
Thread.Sleep(4000);
|
Thread.Sleep(4000);
|
||||||
Restart();
|
Restart();
|
||||||
|
|
@ -74,6 +80,7 @@ namespace SecondBotEvents.Services
|
||||||
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
||||||
{
|
{
|
||||||
LogFormater.Info("Client service ~ Logged out");
|
LogFormater.Info("Client service ~ Logged out");
|
||||||
|
master.TriggerBotClientEvent(true,!getLogoutExpected());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BotSimConnected(object o, SimConnectedEventArgs e)
|
protected void BotSimConnected(object o, SimConnectedEventArgs e)
|
||||||
|
|
@ -92,16 +99,6 @@ namespace SecondBotEvents.Services
|
||||||
protected void BotDisconnected(object o, DisconnectedEventArgs e)
|
protected void BotDisconnected(object o, DisconnectedEventArgs e)
|
||||||
{
|
{
|
||||||
LogFormater.Info("Client service ~ Network disconnected: " + e.Message);
|
LogFormater.Info("Client service ~ Network disconnected: " + e.Message);
|
||||||
if (LogoutExpected == false)
|
|
||||||
{
|
|
||||||
AutoRestartLoginTimer = new Timer();
|
|
||||||
AutoRestartLoginTimer.Interval = 75 * 1000;
|
|
||||||
AutoRestartLoginTimer.AutoReset = false;
|
|
||||||
AutoRestartLoginTimer.Elapsed += RestartTimer;
|
|
||||||
AutoRestartLoginTimer.Start();
|
|
||||||
LogFormater.Info("Client service ~ Unexpected disconnect (starting reconnect timer for 75s)");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BotLoginStatus(object o, LoginProgressEventArgs e)
|
protected void BotLoginStatus(object o, LoginProgressEventArgs e)
|
||||||
|
|
@ -114,6 +111,10 @@ namespace SecondBotEvents.Services
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogFormater.Info("Client service ~ Login status: " + e.Status.ToString());
|
LogFormater.Info("Client service ~ Login status: " + e.Status.ToString());
|
||||||
|
if (e.Status == LoginStatus.Success)
|
||||||
|
{
|
||||||
|
master.TriggerBotClientEvent(true, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void SendIM(UUID avatar, string message)
|
public void SendIM(UUID avatar, string message)
|
||||||
{
|
{
|
||||||
|
|
@ -184,18 +185,8 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void ResetClient()
|
protected void ResetClient()
|
||||||
{
|
{
|
||||||
bool isRestart = false;
|
|
||||||
if (client != null)
|
|
||||||
{
|
|
||||||
if (client.Network != null)
|
|
||||||
{
|
|
||||||
client.Network.Logout();
|
|
||||||
}
|
|
||||||
isRestart = true;
|
|
||||||
}
|
|
||||||
client = null;
|
client = null;
|
||||||
client = new GridClient();
|
client = new GridClient();
|
||||||
master.TriggerBotClientEvent(isRestart);
|
|
||||||
client.Network.SimConnected += BotSimConnected;
|
client.Network.SimConnected += BotSimConnected;
|
||||||
client.Network.LoggedOut += BotLoggedOut;
|
client.Network.LoggedOut += BotLoggedOut;
|
||||||
client.Network.Disconnected += BotDisconnected;
|
client.Network.Disconnected += BotDisconnected;
|
||||||
|
|
|
||||||
|
|
@ -479,6 +479,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("ChatGpt [Attached to new client]");
|
LogFormater.Info("ChatGpt [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
|
|
@ -371,11 +371,18 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
acceptNewCommands = false;
|
acceptNewCommands = false;
|
||||||
LogFormater.Info("Commands service [Attached to new client]");
|
LogFormater.Info("Commands service [Attached to new client]");
|
||||||
|
if (e.isDC == false)
|
||||||
|
{
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
protected void BotLoggedOut(object o, LoggedOutEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -49,15 +49,30 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
{
|
{
|
||||||
|
if (running == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (running == true)
|
if (running == true)
|
||||||
{
|
{
|
||||||
LogFormater.Info("COF inventor [Stopping]");
|
LogFormater.Info("COF inventor [Stopping]");
|
||||||
}
|
}
|
||||||
running = false;
|
running = false;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
master.BotClientNoticeEvent -= BotClientRestart;
|
||||||
|
GetClient().Network.LoggedOut -= BotLoggedOut;
|
||||||
|
GetClient().Network.SimConnected -= BotLoggedIn;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("COF inventory [Attached to new client]");
|
LogFormater.Info("COF inventory [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("CustomCommands service [Attached to new client]");
|
LogFormater.Info("CustomCommands service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
|
|
@ -841,6 +841,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
botConnected = false;
|
botConnected = false;
|
||||||
LogFormater.Info("DataStore Service [Attached to new client]");
|
LogFormater.Info("DataStore Service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
|
|
@ -222,6 +222,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("Dialog service [Attached to new client]");
|
LogFormater.Info("Dialog service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
|
|
@ -642,8 +642,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
if (e.isRestart == false)
|
if (e.isStart == false)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("Discord service [Avi link - waiting]");
|
LogFormater.Info("Discord service [Avi link - waiting]");
|
||||||
AcceptEventsFromSL = false;
|
AcceptEventsFromSL = false;
|
||||||
LoginEventsAttached = false;
|
LoginEventsAttached = false;
|
||||||
|
|
@ -652,7 +654,6 @@ namespace SecondBotEvents.Services
|
||||||
GetClient().Self.IM -= BotImMessage;
|
GetClient().Self.IM -= BotImMessage;
|
||||||
GetClient().Groups.CurrentGroups -= GroupCurrent;
|
GetClient().Groups.CurrentGroups -= GroupCurrent;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -120,6 +120,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("Events service [Attached to new client]");
|
LogFormater.Info("Events service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
|
|
@ -292,6 +292,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
botConnected = false;
|
botConnected = false;
|
||||||
LogFormater.Info("Homebound Service [Attached to new client]");
|
LogFormater.Info("Homebound Service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
acceptBotCommands = false;
|
acceptBotCommands = false;
|
||||||
LogFormater.Info("HTTP service [Attached to new client]");
|
LogFormater.Info("HTTP service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
botConnected = false;
|
botConnected = false;
|
||||||
LogFormater.Info("Interaction Service [Attached to new client]");
|
LogFormater.Info("Interaction Service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogFormater.Info("RLV service [Attached to new client]");
|
LogFormater.Info("RLV service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
GetClient().Network.SimConnected += BotLoggedIn;
|
GetClient().Network.SimConnected += BotLoggedIn;
|
||||||
|
|
|
||||||
78
SecondBotEvents/Services/RecoveryService.cs
Normal file
78
SecondBotEvents/Services/RecoveryService.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
using OpenMetaverse;
|
||||||
|
using SecondBotEvents.Config;
|
||||||
|
using System.Threading;
|
||||||
|
using Timer = System.Timers.Timer;
|
||||||
|
namespace SecondBotEvents.Services
|
||||||
|
{
|
||||||
|
public class RecoveryService : BotServices
|
||||||
|
{
|
||||||
|
protected Timer AutoRestartLoginTimer;
|
||||||
|
protected new BasicConfig myConfig;
|
||||||
|
public RecoveryService(EventsSecondBot setMaster) : base(setMaster)
|
||||||
|
{
|
||||||
|
myConfig = new BasicConfig(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Status()
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
|
{
|
||||||
|
if(e.isStart == true)
|
||||||
|
{
|
||||||
|
LogFormater.Info("RecoveryService [Attached to new client]");
|
||||||
|
}
|
||||||
|
else if(e.isDC == true)
|
||||||
|
{
|
||||||
|
TriggerRecovery();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void TriggerRecovery()
|
||||||
|
{
|
||||||
|
LogFormater.Info("RecoveryService [Triggered]");
|
||||||
|
if(master.BotClient != null)
|
||||||
|
{
|
||||||
|
if(master.BotClient.client != null)
|
||||||
|
{
|
||||||
|
if(master.BotClient.client.Network != null)
|
||||||
|
{
|
||||||
|
master.BotClient.client.Network.BeginLogout(); // attempt to flag logout
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (master.BotClient != null)
|
||||||
|
{
|
||||||
|
master.BotClient.flagLogoutExpected();
|
||||||
|
}
|
||||||
|
master.StopServices("RecoveryService"); // stop everything but recovery and the core bot service
|
||||||
|
Thread.Sleep(2 * 1000); // give it 2 secs
|
||||||
|
master.StopService("BotClientService");
|
||||||
|
Thread.Sleep(75 * 1000); // wait 75 secs
|
||||||
|
master.StartServices();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Start(bool updateEnabled = false, bool setEnabledTo = false)
|
||||||
|
{
|
||||||
|
if (updateEnabled)
|
||||||
|
{
|
||||||
|
myConfig.setEnabled(setEnabledTo);
|
||||||
|
}
|
||||||
|
Stop();
|
||||||
|
master.BotClientNoticeEvent += BotClientRestart;
|
||||||
|
LogFormater.Info("Relay Service [Starting]");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Stop()
|
||||||
|
{
|
||||||
|
if (running == true)
|
||||||
|
{
|
||||||
|
LogFormater.Info("Relay Service [Stopping]");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +42,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
botConnected = false;
|
botConnected = false;
|
||||||
LogFormater.Info("Relay Service [Attached to new client]");
|
LogFormater.Info("Relay Service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,10 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotClientRestart(object o, BotClientNotice e)
|
protected void BotClientRestart(object o, BotClientNotice e)
|
||||||
{
|
{
|
||||||
|
if (e.isStart == false)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
botConnected = false;
|
botConnected = false;
|
||||||
LogFormater.Info("OnEvent Service [Attached to new client]");
|
LogFormater.Info("OnEvent Service [Attached to new client]");
|
||||||
GetClient().Network.LoggedOut += BotLoggedOut;
|
GetClient().Network.LoggedOut += BotLoggedOut;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue