diff --git a/MareSynchronos/UI/MainUi.cs b/MareSynchronos/UI/MainUi.cs index e61100d..ae1333b 100644 --- a/MareSynchronos/UI/MainUi.cs +++ b/MareSynchronos/UI/MainUi.cs @@ -7,7 +7,6 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Net.Mime; using System.Numerics; using System.Threading.Tasks; using MareSynchronos.API; @@ -84,10 +83,15 @@ namespace MareSynchronos.UI } else { - string error = _configuration.FullPause ? "Disconnected" : _apiController.ServerAlive ? "Unauthorized" : "Service unavailable"; + var error = _configuration.FullPause ? "Disconnected" + : !_apiController.ServerAlive + ? "Service unavailable" + : !_apiController.ServerSupportsThisClient + ? "Service version mismatch" + : "Unauthorized"; ImGui.TextColored(ImGuiColors.DalamudRed, $"No UID ({error})"); ImGui.SetWindowFontScale(1.0f); - if (_apiController.ServerAlive && !_configuration.FullPause) + if (_apiController.ServerAlive && !_configuration.FullPause && _apiController.ServerSupportsThisClient) { ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed); UiShared.TextWrapped("Your account is not present on the service anymore or you are banned."); @@ -101,6 +105,11 @@ namespace MareSynchronos.UI _configuration.Save(); SwitchFromMainUiToIntro?.Invoke(); } + } else if (!_apiController.ServerSupportsThisClient) + { + ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed); + UiShared.TextWrapped("The server or your client is outdated. If the client has recently been updated for breaking service changes, the service must follow suit."); + ImGui.PopStyleColor(); } } diff --git a/MareSynchronos/WebAPI/ApiController.Connectivity.cs b/MareSynchronos/WebAPI/ApiController.Connectivity.cs index 0e23e67..df4fac2 100644 --- a/MareSynchronos/WebAPI/ApiController.Connectivity.cs +++ b/MareSynchronos/WebAPI/ApiController.Connectivity.cs @@ -18,6 +18,7 @@ namespace MareSynchronos.WebAPI #if DEBUG public const string MainServer = "darkarchons Debug Server (Dev Server (CH))"; public const string MainServiceUri = "wss://darkarchon.internet-box.ch:5000"; + public readonly int[] SupportedServerVersions = { 1 }; #else public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)"; public const string MainServiceUri = "to be defined"; @@ -37,10 +38,10 @@ namespace MareSynchronos.WebAPI private CancellationTokenSource? _uploadCancellationTokenSource; private HubConnection? _userHub; - private LoggedInUserDto? _loggedInUser; - public bool IsModerator => (_loggedInUser?.IsAdmin ?? false) || (_loggedInUser?.IsModerator ?? false); + private ConnectionDto? _connectionDto; + public bool IsModerator => (_connectionDto?.IsAdmin ?? false) || (_connectionDto?.IsModerator ?? false); - public bool IsAdmin => _loggedInUser?.IsAdmin ?? false; + public bool IsAdmin => _connectionDto?.IsAdmin ?? false; public ApiController(Configuration pluginConfiguration, DalamudUtil dalamudUtil) { @@ -95,7 +96,7 @@ namespace MareSynchronos.WebAPI public List AdminForbiddenFiles { get; private set; } = new(); - public bool IsConnected => !string.IsNullOrEmpty(UID); + public bool IsConnected => !string.IsNullOrEmpty(UID) && ServerSupportsThisClient; public bool IsDownloading => CurrentDownloads.Count > 0; @@ -108,11 +109,13 @@ namespace MareSynchronos.WebAPI public bool ServerAlive => (_heartbeatHub?.State ?? HubConnectionState.Disconnected) == HubConnectionState.Connected; + public bool ServerSupportsThisClient => SupportedServerVersions.Contains(_connectionDto?.ServerVersion ?? 0); + public Dictionary ServerDictionary => new Dictionary() { { MainServiceUri, MainServer } } .Concat(_pluginConfiguration.CustomServerList) .ToDictionary(k => k.Key, k => k.Value); - public string UID => _loggedInUser?.UID ?? string.Empty; + public string UID => _connectionDto?.UID ?? string.Empty; private string ApiUri => _pluginConfiguration.ApiUri; public int OnlineUsers { get; private set; } @@ -143,15 +146,17 @@ namespace MareSynchronos.WebAPI await _adminHub.StartAsync(token); OnlineUsers = await _userHub.InvokeAsync("GetOnlineUsers", token); - + _userHub.On("UsersOnline", (count) => OnlineUsers = count); + if (_pluginConfiguration.FullPause) { - _loggedInUser = null; + _connectionDto = null; return; } - _loggedInUser = await _heartbeatHub.InvokeAsync("Heartbeat", token); - if (!string.IsNullOrEmpty(UID) && !token.IsCancellationRequested) // user is authorized + _connectionDto = await _heartbeatHub.InvokeAsync("Heartbeat", token); + if (!string.IsNullOrEmpty(UID) && !token.IsCancellationRequested + && ServerSupportsThisClient) // user is authorized && server is legit { Logger.Debug("Initializing data"); _userHub.On("UpdateClientPairs", UpdateLocalClientPairsCallback); @@ -160,7 +165,6 @@ namespace MareSynchronos.WebAPI (s) => PairedClientOffline?.Invoke(s, EventArgs.Empty)); _userHub.On("AddOnlinePairedPlayer", (s) => PairedClientOnline?.Invoke(s, EventArgs.Empty)); - _userHub.On("UsersOnline", (count) => OnlineUsers = count); _adminHub.On("ForcedReconnect", UserForcedReconnectCallback); PairedClients = await _userHub!.InvokeAsync>("GetPairedClients", token); @@ -239,7 +243,7 @@ namespace MareSynchronos.WebAPI { Logger.Debug("Connection restored"); OnlineUsers = _userHub!.InvokeAsync("GetOnlineUsers").Result; - _loggedInUser = _heartbeatHub!.InvokeAsync("Heartbeat").Result; + _connectionDto = _heartbeatHub!.InvokeAsync("Heartbeat").Result; Connected?.Invoke(this, EventArgs.Empty); return Task.CompletedTask; }