mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
refactor: Remove PublicPort configuration and update registration logic
This commit is contained in:
@@ -23,7 +23,6 @@ public sealed class ServerDirectoryService(
|
|||||||
}
|
}
|
||||||
|
|
||||||
var host = configuration["Server:PublicHost"];
|
var host = configuration["Server:PublicHost"];
|
||||||
var port = configuration.GetValue<int>("Server:PublicPort");
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(host))
|
if (string.IsNullOrWhiteSpace(host))
|
||||||
{
|
{
|
||||||
@@ -31,12 +30,6 @@ public sealed class ServerDirectoryService(
|
|||||||
return;
|
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 serverName = configuration["Server:Name"] ?? "EchoHub Server";
|
||||||
var description = configuration["Server:Description"];
|
var description = configuration["Server:Description"];
|
||||||
|
|
||||||
@@ -48,7 +41,7 @@ public sealed class ServerDirectoryService(
|
|||||||
_connection.Reconnected += async _ =>
|
_connection.Reconnected += async _ =>
|
||||||
{
|
{
|
||||||
logger.LogInformation("Reconnected to directory — re-registering server");
|
logger.LogInformation("Reconnected to directory — re-registering server");
|
||||||
await RegisterAsync(serverName, description, host, port);
|
await RegisterAsync(serverName, description, host);
|
||||||
};
|
};
|
||||||
|
|
||||||
_connection.Closed += ex =>
|
_connection.Closed += ex =>
|
||||||
@@ -64,7 +57,7 @@ public sealed class ServerDirectoryService(
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _connection.StartAsync(stoppingToken);
|
await _connection.StartAsync(stoppingToken);
|
||||||
logger.LogInformation("Connected to directory at {Url}", DirectoryHubUrl);
|
logger.LogInformation("Successfully connected to EchoHubSpace API at {Url}", DirectoryHubUrl);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -78,7 +71,7 @@ public sealed class ServerDirectoryService(
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Register on first connect
|
// Register on first connect
|
||||||
await RegisterAsync(serverName, description, host, port);
|
await RegisterAsync(serverName, description, host);
|
||||||
|
|
||||||
// Poll user count and send updates
|
// Poll user count and send updates
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
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)
|
if (_connection?.State != HubConnectionState.Connected)
|
||||||
return;
|
return;
|
||||||
@@ -113,10 +106,10 @@ public sealed class ServerDirectoryService(
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var userCount = presenceTracker.GetOnlineUserCount();
|
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);
|
await _connection.InvokeAsync("RegisterServer", dto);
|
||||||
_lastReportedUserCount = userCount;
|
_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)
|
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);
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
"Name": "My EchoHub Server",
|
"Name": "My EchoHub Server",
|
||||||
"Description": "A self-hosted EchoHub chat server",
|
"Description": "A self-hosted EchoHub chat server",
|
||||||
"PublicServer": false,
|
"PublicServer": false,
|
||||||
"PublicHost": "",
|
"PublicHost": ""
|
||||||
"PublicPort": 5000
|
|
||||||
},
|
},
|
||||||
"Serilog": {
|
"Serilog": {
|
||||||
"MinimumLevel": {
|
"MinimumLevel": {
|
||||||
|
|||||||
Reference in New Issue
Block a user