Bot auto recovery
This commit is contained in:
parent
12e02f206b
commit
3c09fb8f15
1 changed files with 15 additions and 1 deletions
|
|
@ -4,6 +4,7 @@ using SecondBotEvents.Config;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
namespace SecondBotEvents.Services
|
namespace SecondBotEvents.Services
|
||||||
{
|
{
|
||||||
|
|
@ -14,12 +15,18 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected bool ExitBot = false;
|
protected bool ExitBot = false;
|
||||||
|
|
||||||
|
protected Timer AutoRestartLoginTimer;
|
||||||
public BotClientService(EventsSecondBot setMaster) : base(setMaster)
|
public BotClientService(EventsSecondBot setMaster) : base(setMaster)
|
||||||
{
|
{
|
||||||
basicCfg = new BasicConfig(master.fromEnv, master.fromFolder);
|
basicCfg = new BasicConfig(master.fromEnv, master.fromFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void RestartTimer(object o, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
AutoRestartLoginTimer.Stop();
|
||||||
|
Restart();
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsLoaded()
|
public bool IsLoaded()
|
||||||
{
|
{
|
||||||
return basicCfg.IsLoaded();
|
return basicCfg.IsLoaded();
|
||||||
|
|
@ -28,10 +35,15 @@ namespace SecondBotEvents.Services
|
||||||
public override void Start()
|
public override void Start()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Client service [Starting]");
|
Console.WriteLine("Client service [Starting]");
|
||||||
|
AutoRestartLoginTimer = new Timer();
|
||||||
|
AutoRestartLoginTimer.Interval = 30 * 1000;
|
||||||
|
AutoRestartLoginTimer.AutoReset = false;
|
||||||
|
AutoRestartLoginTimer.Elapsed += RestartTimer;
|
||||||
Login();
|
Login();
|
||||||
}
|
}
|
||||||
public override void Stop()
|
public override void Stop()
|
||||||
{
|
{
|
||||||
|
AutoRestartLoginTimer.Stop();
|
||||||
Console.WriteLine("Client service [Stopping]");
|
Console.WriteLine("Client service [Stopping]");
|
||||||
ResetClient();
|
ResetClient();
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +55,7 @@ namespace SecondBotEvents.Services
|
||||||
|
|
||||||
protected void BotSimConnected(object o, SimConnectedEventArgs e)
|
protected void BotSimConnected(object o, SimConnectedEventArgs e)
|
||||||
{
|
{
|
||||||
|
AutoRestartLoginTimer.Stop();
|
||||||
Console.WriteLine("Client service ~ Connected to sim: "+e.Simulator.Name);
|
Console.WriteLine("Client service ~ Connected to sim: "+e.Simulator.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,6 +176,7 @@ namespace SecondBotEvents.Services
|
||||||
{
|
{
|
||||||
loginParams.URI = basicCfg.GetLoginURI();
|
loginParams.URI = basicCfg.GetLoginURI();
|
||||||
}
|
}
|
||||||
|
AutoRestartLoginTimer.Start();
|
||||||
client.Network.BeginLogin(loginParams);
|
client.Network.BeginLogin(loginParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue