From 15b6443cf01fab60cbe21e33fa161eac9a23a5f3 Mon Sep 17 00:00:00 2001 From: HueByte Date: Thu, 19 Feb 2026 06:18:43 +0100 Subject: [PATCH] refactor: Remove PublicPort configuration and update registration logic --- .../Services/ServerDirectoryService.cs | 21 +++++++------------ src/EchoHub.Server/appsettings.example.json | 3 +-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/EchoHub.Server/Services/ServerDirectoryService.cs b/src/EchoHub.Server/Services/ServerDirectoryService.cs index 878caad..44b96fc 100644 --- a/src/EchoHub.Server/Services/ServerDirectoryService.cs +++ b/src/EchoHub.Server/Services/ServerDirectoryService.cs @@ -23,7 +23,6 @@ public sealed class ServerDirectoryService( } var host = configuration["Server:PublicHost"]; - var port = configuration.GetValue("Server:PublicPort"); if (string.IsNullOrWhiteSpace(host)) { @@ -31,12 +30,6 @@ public sealed class ServerDirectoryService( return; } - if (port <= 0) - { - logger.LogWarning("PublicServer is enabled but Server:PublicPort is invalid — skipping directory registration"); - return; - } - var serverName = configuration["Server:Name"] ?? "EchoHub Server"; var description = configuration["Server:Description"]; @@ -48,7 +41,7 @@ public sealed class ServerDirectoryService( _connection.Reconnected += async _ => { logger.LogInformation("Reconnected to directory — re-registering server"); - await RegisterAsync(serverName, description, host, port); + await RegisterAsync(serverName, description, host); }; _connection.Closed += ex => @@ -64,7 +57,7 @@ public sealed class ServerDirectoryService( try { await _connection.StartAsync(stoppingToken); - logger.LogInformation("Connected to directory at {Url}", DirectoryHubUrl); + logger.LogInformation("Successfully connected to EchoHubSpace API at {Url}", DirectoryHubUrl); break; } catch (Exception ex) @@ -78,7 +71,7 @@ public sealed class ServerDirectoryService( return; // Register on first connect - await RegisterAsync(serverName, description, host, port); + await RegisterAsync(serverName, description, host); // Poll user count and send updates while (!stoppingToken.IsCancellationRequested) @@ -105,7 +98,7 @@ public sealed class ServerDirectoryService( } } - private async Task RegisterAsync(string name, string? description, string host, int port) + private async Task RegisterAsync(string name, string? description, string host) { if (_connection?.State != HubConnectionState.Connected) return; @@ -113,10 +106,10 @@ public sealed class ServerDirectoryService( try { var userCount = presenceTracker.GetOnlineUserCount(); - var dto = new RegisterServerDto(name, description, host, port, userCount); + var dto = new RegisterServerDto(name, description, host, userCount); await _connection.InvokeAsync("RegisterServer", dto); _lastReportedUserCount = userCount; - logger.LogInformation("Registered with directory as {Name} at {Host}:{Port}", name, host, port); + logger.LogInformation("Registered with directory as {Name} at {Host}", name, host); } catch (Exception ex) { @@ -136,4 +129,4 @@ public sealed class ServerDirectoryService( } } -internal record RegisterServerDto(string Name, string? Description, string Host, int Port, int UserCount); +internal record RegisterServerDto(string Name, string? Description, string Host, int UserCount); diff --git a/src/EchoHub.Server/appsettings.example.json b/src/EchoHub.Server/appsettings.example.json index 1596469..46200f0 100644 --- a/src/EchoHub.Server/appsettings.example.json +++ b/src/EchoHub.Server/appsettings.example.json @@ -12,8 +12,7 @@ "Name": "My EchoHub Server", "Description": "A self-hosted EchoHub chat server", "PublicServer": false, - "PublicHost": "", - "PublicPort": 5000 + "PublicHost": "" }, "Serilog": { "MinimumLevel": {