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