2023-03-26 13:47:18 +00:00
|
|
|
|
using System;
|
|
|
|
|
using Dalamud.Game.Gui;
|
|
|
|
|
using Dalamud.Logging;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
using Grpc.Net.Client;
|
2022-11-24 22:28:31 +00:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2023-02-15 01:38:04 +00:00
|
|
|
|
using Pal.Client.Configuration;
|
2023-02-17 14:51:45 +00:00
|
|
|
|
using Pal.Client.DependencyInjection;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
namespace Pal.Client.Net;
|
|
|
|
|
|
|
|
|
|
internal sealed partial class RemoteApi : IDisposable
|
2022-10-23 02:38:58 +00:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
2023-03-30 20:01:43 +00:00
|
|
|
|
public const string RemoteUrl = "http://localhost:5415";
|
2022-10-23 02:38:58 +00:00
|
|
|
|
#else
|
2023-07-30 20:32:04 +00:00
|
|
|
|
public const string RemoteUrl = "https://connect.palacepal.com";
|
2022-10-23 02:38:58 +00:00
|
|
|
|
#endif
|
2023-03-30 20:01:43 +00:00
|
|
|
|
private readonly string _userAgent =
|
|
|
|
|
$"{typeof(RemoteApi).Assembly.GetName().Name?.Replace(" ", "")}/{typeof(RemoteApi).Assembly.GetName().Version?.ToString(2)}";
|
2022-10-30 19:39:12 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
private readonly ILoggerFactory _loggerFactory;
|
|
|
|
|
private readonly ILogger<RemoteApi> _logger;
|
|
|
|
|
private readonly Chat _chat;
|
|
|
|
|
private readonly ConfigurationManager _configurationManager;
|
|
|
|
|
private readonly IPalacePalConfiguration _configuration;
|
2022-11-24 22:28:31 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
private GrpcChannel? _channel;
|
|
|
|
|
private LoginInfo _loginInfo = new(null);
|
|
|
|
|
private bool _warnedAboutUpgrade;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
public RemoteApi(
|
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
|
ILogger<RemoteApi> logger,
|
|
|
|
|
Chat chat,
|
|
|
|
|
ConfigurationManager configurationManager,
|
|
|
|
|
IPalacePalConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
_loggerFactory = loggerFactory;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_chat = chat;
|
|
|
|
|
_configurationManager = configurationManager;
|
|
|
|
|
_configuration = configuration;
|
|
|
|
|
}
|
2023-02-15 22:17:19 +00:00
|
|
|
|
|
2023-03-30 20:01:43 +00:00
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
_logger.LogDebug("Disposing gRPC channel");
|
|
|
|
|
_channel?.Dispose();
|
|
|
|
|
_channel = null;
|
2022-10-23 02:38:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|