Skip to content

Commit c37cedb

Browse files
authored
Merge branch 'Corona-Studio:main' into main
2 parents c19c66c + a4c6051 commit c37cedb

File tree

4 files changed

+16
-33
lines changed

4 files changed

+16
-33
lines changed

ConnectX.Client/ServerLinkHolder.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,6 @@ public ServerLinkHolder(
4242

4343
public event Action? OnServerLinkDisconnected;
4444

45-
public override async Task StartAsync(CancellationToken cancellationToken)
46-
{
47-
_logger.LogStartingServerLinkHolder();
48-
49-
await ConnectAsync(cancellationToken);
50-
await TaskHelper.WaitUntilAsync(() => IsConnected, cancellationToken);
51-
await base.StartAsync(cancellationToken);
52-
}
53-
54-
public override Task StopAsync(CancellationToken cancellationToken)
55-
{
56-
_logger.LogStoppingServerLinkHolder();
57-
return base.StopAsync(cancellationToken);
58-
}
59-
6045
private async Task CheckServerLivenessAsync(CancellationToken cancellationToken)
6146
{
6247
var endPoint = new IPEndPoint(_settingProvider.ServerAddress, _settingProvider.ServerPort);
@@ -205,12 +190,6 @@ internal static partial class ServerLinkHolderLoggers
205190
[LoggerMessage(LogLevel.Information, "[CLIENT] Successfully logged into server, assigned id: {id}")]
206191
public static partial void LogSuccessfullyLoggedIn(this ILogger logger, Guid id);
207192

208-
[LoggerMessage(LogLevel.Information, "[CLIENT] Starting server link holder...")]
209-
public static partial void LogStartingServerLinkHolder(this ILogger logger);
210-
211-
[LoggerMessage(LogLevel.Information, "[CLIENT] Stopping server link holder...")]
212-
public static partial void LogStoppingServerLinkHolder(this ILogger logger);
213-
214193
[LoggerMessage(LogLevel.Information, "[CLIENT] Connecting to server...")]
215194
public static partial void LogConnectingToServer(this ILogger logger);
216195

ConnectX.ClientConsole/ConsoleService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using Microsoft.Extensions.Hosting;
22
using System.CommandLine;
33
using System.CommandLine.Invocation;
4+
using ConnectX.Client.Interfaces;
45
using ConnectX.ClientConsole.Helpers;
6+
using ConnectX.Shared.Helpers;
57
using ConnectX.Shared.Messages.Group;
68
using Microsoft.Extensions.Logging;
79

@@ -50,12 +52,20 @@ public static class Kick
5052
}
5153

5254
public class ConsoleService(
55+
IServerLinkHolder serverLinkHolder,
5356
Client.Client client,
5457
ILogger<ConsoleService> logger)
5558
: BackgroundService
5659
{
5760
private GroupInfo? _lastGroupInfo;
5861

62+
public override async Task StartAsync(CancellationToken cancellationToken)
63+
{
64+
await serverLinkHolder.ConnectAsync(cancellationToken);
65+
await TaskHelper.WaitUntilAsync(() => serverLinkHolder.IsConnected, cancellationToken);
66+
await base.StartAsync(cancellationToken);
67+
}
68+
5969
private static string[] ParseArguments(string commandLine)
6070
{
6171
var paraChars = commandLine.ToCharArray();

ConnectX.Server/InterconnectServerLinkHolder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ private async Task EstablishLinkAsync(CancellationToken stoppingToken)
125125
{
126126
_logger.LogFailedToConnectToRemoteServer(endPoint);
127127
_pendingEstablishInterconnectServerLinks.Enqueue(endPoint);
128+
129+
await Task.Delay(5000, stoppingToken);
130+
128131
continue;
129132
}
130133

ConnectX.Server/JsonConverters/IPEndPointJsonConverter.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,9 @@ public class IPEndPointJsonConverter : JsonConverter<IPEndPoint>
1313
return null;
1414

1515
// Try parse IP:Port format
16-
var parts = endpointString.Split(':');
17-
if (parts.Length < 2)
18-
throw new JsonException($"Invalid IPEndPoint format: {endpointString}");
19-
20-
if (!int.TryParse(parts[^1], out var port))
21-
throw new JsonException($"Invalid port number: {parts[^1]}");
22-
23-
var ipPart = string.Join(":", parts[..^1]);
24-
if (!IPAddress.TryParse(ipPart, out var ip))
25-
throw new JsonException($"Invalid IP address: {ipPart}");
26-
27-
return new IPEndPoint(ip, port);
16+
if (IPEndPoint.TryParse(endpointString, out var endpoint))
17+
return endpoint;
18+
else throw new JsonException($"Invalid IPEndPoint format: {endpointString}");
2819
}
2920

3021
public override void Write(Utf8JsonWriter writer, IPEndPoint value, JsonSerializerOptions options)

0 commit comments

Comments
 (0)