mirror of
https://github.com/barelyprofessional/KfChatDotNet.git
synced 2026-05-02 04:22:04 -04:00
Still having issues with not reconnecting after 203 challenge so moved the reconnect logic back out of refresh token, save cookies no matter what and now force a reconnect on WsDisconnection event if it's not ByUser
This commit is contained in:
@@ -57,7 +57,7 @@ public class ChatBot
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
RefreshXfToken(false).Wait(_cancellationToken);
|
RefreshXfToken().Wait(_cancellationToken);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -223,20 +223,16 @@ public class ChatBot
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task RefreshXfToken(bool autoConnect = true)
|
private async Task RefreshXfToken()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (await _kfTokenService.IsLoggedIn())
|
if (await _kfTokenService.IsLoggedIn())
|
||||||
{
|
{
|
||||||
_logger.Info("We were already logged in and should have a fresh cookie for chat now");
|
_logger.Info("We were already logged in and should have a fresh cookie for chat now");
|
||||||
if (autoConnect && !KfClient.IsConnected())
|
_logger.Info("Updating cookies");
|
||||||
{
|
await _kfTokenService.SaveCookies();
|
||||||
_logger.Info("Updating cookies and reconnecting");
|
KfClient.UpdateCookies(_kfTokenService.GetCookies());
|
||||||
await _kfTokenService.SaveCookies();
|
|
||||||
KfClient.UpdateCookies(_kfTokenService.GetCookies());
|
|
||||||
await KfClient.StartWsClient();
|
|
||||||
}
|
|
||||||
// Only seems to happen if the bot thinks it's already logged in
|
// Only seems to happen if the bot thinks it's already logged in
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -262,13 +258,9 @@ public class ChatBot
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.Info("Successfully logged in");
|
_logger.Info("Successfully logged in");
|
||||||
if (autoConnect && !KfClient.IsConnected())
|
_logger.Info("Updating cookies");
|
||||||
{
|
await _kfTokenService.SaveCookies();
|
||||||
_logger.Info("Updating cookies and reconnecting");
|
KfClient.UpdateCookies(_kfTokenService.GetCookies());
|
||||||
await _kfTokenService.SaveCookies();
|
|
||||||
KfClient.UpdateCookies(_kfTokenService.GetCookies());
|
|
||||||
await KfClient.StartWsClient();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnKfChatMessage(object sender, List<MessageModel> messages, MessagesJsonModel jsonPayload)
|
private void OnKfChatMessage(object sender, List<MessageModel> messages, MessagesJsonModel jsonPayload)
|
||||||
@@ -665,6 +657,10 @@ public class ChatBot
|
|||||||
_logger.Info("Chat 203'd, getting a new token");
|
_logger.Info("Chat 203'd, getting a new token");
|
||||||
RefreshXfToken().Wait(_cancellationToken);
|
RefreshXfToken().Wait(_cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (disconnectionInfo.Type == DisconnectionType.ByUser) return;
|
||||||
|
_logger.Info("Forcing reconnect");
|
||||||
|
KfClient.StartWsClient().Wait(_cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnKfWsReconnected(object sender, ReconnectionInfo reconnectionInfo)
|
private void OnKfWsReconnected(object sender, ReconnectionInfo reconnectionInfo)
|
||||||
|
|||||||
Reference in New Issue
Block a user