diff --git a/src/EchoHub.Client/AppOrchestrator.cs b/src/EchoHub.Client/AppOrchestrator.cs index bf21ab3..a71f7c6 100644 --- a/src/EchoHub.Client/AppOrchestrator.cs +++ b/src/EchoHub.Client/AppOrchestrator.cs @@ -1373,6 +1373,21 @@ public sealed class AppOrchestrator : IDisposable _mainWindow.FocusInput(); FetchAndUpdateOnlineUsers(); }); + + if (result.ServerInfo is not null && !string.IsNullOrEmpty(result.ServerInfo.Version) + && result.ServerInfo.Version != UpdateChecker.CurrentVersion) + { + InvokeUI(() => { + var choice = MessageBox.Query(_app, "Version Mismatch", + $"Server version {result.ServerInfo.Version} does not match client version {UpdateChecker.CurrentVersion}.\n\n" + + "Some features may not work correctly. Consider updating both to the same version.", + "Continue", "Disconnect"); + + if (choice == 1) + HandleDisconnect(); + }); + } + SaveServerToConfig(dialogResult); }, "Connection failed", "Connect"); } diff --git a/src/EchoHub.Client/Services/ConnectionManager.cs b/src/EchoHub.Client/Services/ConnectionManager.cs index 110a597..40cd701 100644 --- a/src/EchoHub.Client/Services/ConnectionManager.cs +++ b/src/EchoHub.Client/Services/ConnectionManager.cs @@ -15,7 +15,8 @@ namespace EchoHub.Client.Services; internal record ConnectResult( LoginResponse Login, List Channels, - Dictionary> Histories); + Dictionary> Histories, + ServerStatusDto? ServerInfo = null); /// /// Owns connection lifecycle, authentication, SignalR event wiring, and channel tracking. @@ -67,6 +68,17 @@ internal sealed class ConnectionManager : IAsyncDisposable try { + onStatus("Fetching server info..."); + ServerStatusDto? serverInfo = null; + try + { + serverInfo = await _apiClient.GetServerInfoAsync(); + } + catch (Exception ex) + { + Log.Warning(ex, "Failed to fetch server info"); + } + onStatus("Authenticating..."); LoginResponse loginResponse; @@ -165,7 +177,7 @@ internal sealed class ConnectionManager : IAsyncDisposable } onStatus("Connected"); - return new ConnectResult(loginResponse, channels, histories); + return new ConnectResult(loginResponse, channels, histories, serverInfo); } catch { diff --git a/src/EchoHub.Core/DTOs/ServerDtos.cs b/src/EchoHub.Core/DTOs/ServerDtos.cs index a5a2f5e..b7ca71f 100644 --- a/src/EchoHub.Core/DTOs/ServerDtos.cs +++ b/src/EchoHub.Core/DTOs/ServerDtos.cs @@ -5,6 +5,7 @@ public record ServerStatusDto( string? Description, int OnlineUsers, int TotalChannels, - string RegistrationMode = "open"); + string RegistrationMode = "open", + string Version = "0.0.0"); public record EncryptionKeyResponse(string Key); diff --git a/src/EchoHub.Server/Controllers/ServerController.cs b/src/EchoHub.Server/Controllers/ServerController.cs index 1b4dbb0..8462faa 100644 --- a/src/EchoHub.Server/Controllers/ServerController.cs +++ b/src/EchoHub.Server/Controllers/ServerController.cs @@ -1,3 +1,4 @@ +using System.Reflection; using System.Security.Claims; using EchoHub.Core.DTOs; using EchoHub.Core.Models; @@ -38,12 +39,15 @@ public class ServerController : ControllerBase _ => "open", }; + var version = typeof(ServerController).Assembly.GetName().Version?.ToString(3) ?? "0.0.0"; + var status = new ServerStatusDto( _config["Server:Name"] ?? "EchoHub Server", _config["Server:Description"], userCount, channelCount, - registrationMode); + registrationMode, + version); return Ok(status); }