From d902f2e5ebfe8bdd716a7a3ed343768ef80e9300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Sat, 24 Aug 2024 22:50:08 +0000 Subject: [PATCH 1/2] stuff --- Maple2.Server.Web/Program.cs | 4 ++-- Maple2.Server.World/Containers/ChannelClientLookup.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Maple2.Server.Web/Program.cs b/Maple2.Server.Web/Program.cs index 488c2d14e..34cd7151f 100644 --- a/Maple2.Server.Web/Program.cs +++ b/Maple2.Server.Web/Program.cs @@ -32,8 +32,8 @@ .ReadFrom.Configuration(configRoot) .CreateLogger(); -IPAddress.TryParse(Environment.GetEnvironmentVariable("WEB_IP"), out IPAddress? webIp); -webIp ??= IPAddress.Any; +// IPAddress.TryParse(Environment.GetEnvironmentVariable("WEB_IP"), out IPAddress? webIp); +IPAddress webIp = IPAddress.Any; int.TryParse(Environment.GetEnvironmentVariable("WEB_PORT") ?? "4000", out int webPort); diff --git a/Maple2.Server.World/Containers/ChannelClientLookup.cs b/Maple2.Server.World/Containers/ChannelClientLookup.cs index 01a0b800e..d9b7a7858 100644 --- a/Maple2.Server.World/Containers/ChannelClientLookup.cs +++ b/Maple2.Server.World/Containers/ChannelClientLookup.cs @@ -99,7 +99,7 @@ public bool TryGetActiveEndpoint(int channel, [NotNullWhen(true)] out IPEndPoint IPAddress ipAddress = IPAddress.Parse(gameIp); var gameEndpoint = new IPEndPoint(ipAddress, newGamePort); - var grpcUri = new Uri($"http://{ipAddress}:{newGrpcChannelPort}"); + var grpcUri = new Uri($"http://{IPAddress.Loopback}:{newGrpcChannelPort}"); GrpcChannel grpcChannel = GrpcChannel.ForAddress(grpcUri); var client = new ChannelClient(grpcChannel); var healthClient = new Health.HealthClient(grpcChannel); From fab514d25ebf12e1a34ba73620f6532ab6d783c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=82ngelo=20Tadeucci?= Date: Sat, 24 Aug 2024 21:16:03 -0300 Subject: [PATCH 2/2] fix: GRPC game ip --- .env.example | 1 + Maple2.Server.Core/Constants/Target.cs | 6 ++++++ Maple2.Server.Core/proto/world/world.proto | 1 + Maple2.Server.DebugGame/Program.cs | 1 + Maple2.Server.Game/Program.cs | 1 + Maple2.Server.Web/Program.cs | 5 +---- Maple2.Server.World/Containers/ChannelClientLookup.cs | 9 +++++---- Maple2.Server.World/Service/WorldService.GamePorts.cs | 2 +- 8 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.env.example b/.env.example index ff332f8fa..b012516b2 100644 --- a/.env.example +++ b/.env.example @@ -18,6 +18,7 @@ GAME_DB_NAME=game-server GAME_IP=localhost LOGIN_IP=localhost +GRPC_GAME_IP=localhost GRPC_WORLD_IP=localhost GRPC_WORLD_PORT=21001 diff --git a/Maple2.Server.Core/Constants/Target.cs b/Maple2.Server.Core/Constants/Target.cs index 03593782a..8af7be573 100644 --- a/Maple2.Server.Core/Constants/Target.cs +++ b/Maple2.Server.Core/Constants/Target.cs @@ -13,6 +13,8 @@ public static class Target { public static readonly IPAddress GameIp = IPAddress.Loopback; public static readonly ushort BaseGamePort = 20002; + public static readonly IPAddress GrpcGameIp = IPAddress.Loopback; + public static readonly Uri WebUri = new("http://localhost"); public static readonly IPAddress GrpcWorldIp = IPAddress.Loopback; @@ -33,6 +35,10 @@ static Target() { GameIp = gameIpAddress; } + if (IPAddress.TryParse(Environment.GetEnvironmentVariable("GRPC_GAME_IP"), out IPAddress? grpcGameIpAddress)) { + GrpcGameIp = grpcGameIpAddress; + } + if (IPAddress.TryParse(Environment.GetEnvironmentVariable("GRPC_WORLD_IP"), out IPAddress? grpcWorldIpOverride)) { GrpcWorldIp = grpcWorldIpOverride; } diff --git a/Maple2.Server.Core/proto/world/world.proto b/Maple2.Server.Core/proto/world/world.proto index 502604281..882c897d0 100644 --- a/Maple2.Server.Core/proto/world/world.proto +++ b/Maple2.Server.Core/proto/world/world.proto @@ -463,6 +463,7 @@ message GlobalPortalInfo { message AddChannelRequest { string game_ip = 1; + string grpc_game_ip = 2; } message AddChannelResponse { diff --git a/Maple2.Server.DebugGame/Program.cs b/Maple2.Server.DebugGame/Program.cs index 871101b3b..ab1ebcc34 100644 --- a/Maple2.Server.DebugGame/Program.cs +++ b/Maple2.Server.DebugGame/Program.cs @@ -46,6 +46,7 @@ var worldClient = new WorldClient(channel); response = worldClient.AddChannel(new AddChannelRequest { GameIp = Target.GameIp.ToString(), + GrpcGameIp = Target.GrpcGameIp.ToString() }); } catch (RpcException e) { diff --git a/Maple2.Server.Game/Program.cs b/Maple2.Server.Game/Program.cs index 880ab04a0..e4f9abe5e 100644 --- a/Maple2.Server.Game/Program.cs +++ b/Maple2.Server.Game/Program.cs @@ -45,6 +45,7 @@ var worldClient = new WorldClient(channel); response = worldClient.AddChannel(new AddChannelRequest { GameIp = Target.GameIp.ToString(), + GrpcGameIp = Target.GrpcGameIp.ToString() }); } catch (RpcException e) { diff --git a/Maple2.Server.Web/Program.cs b/Maple2.Server.Web/Program.cs index 34cd7151f..0bcc7fa25 100644 --- a/Maple2.Server.Web/Program.cs +++ b/Maple2.Server.Web/Program.cs @@ -32,14 +32,11 @@ .ReadFrom.Configuration(configRoot) .CreateLogger(); -// IPAddress.TryParse(Environment.GetEnvironmentVariable("WEB_IP"), out IPAddress? webIp); -IPAddress webIp = IPAddress.Any; - int.TryParse(Environment.GetEnvironmentVariable("WEB_PORT") ?? "4000", out int webPort); WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.WebHost.UseKestrel(options => { - options.Listen(new IPEndPoint(webIp, webPort), listen => { + options.Listen(new IPEndPoint(IPAddress.Any, webPort), listen => { listen.Protocols = HttpProtocols.Http1; }); // Omitting for now since HTTPS requires a certificate diff --git a/Maple2.Server.World/Containers/ChannelClientLookup.cs b/Maple2.Server.World/Containers/ChannelClientLookup.cs index d9b7a7858..9e8a968c1 100644 --- a/Maple2.Server.World/Containers/ChannelClientLookup.cs +++ b/Maple2.Server.World/Containers/ChannelClientLookup.cs @@ -42,14 +42,14 @@ public IEnumerable Keys { } } - public (ushort gamePort, int grpcPort, int channel) FindOrCreateChannelByIp(string gameIp) { + public (ushort gamePort, int grpcPort, int channel) FindOrCreateChannelByIp(string gameIp, string grpcGameIp) { for (int i = 0; i < channels.Count; i++) { if (channels[i].Endpoint.Address.ToString() == gameIp && activeChannels[i] is ChannelStatus.Inactive) { return ((ushort) (Target.BaseGamePort + i + 1), Target.BaseGrpcChannelPort + i + 1, i + 1); } } - return AddChannel(gameIp); + return AddChannel(gameIp, grpcGameIp); } public int FirstChannel() { @@ -91,15 +91,16 @@ public bool TryGetActiveEndpoint(int channel, [NotNullWhen(true)] out IPEndPoint return true; } - private (ushort gamePort, int grpcPort, int channel) AddChannel(string gameIp) { + private (ushort gamePort, int grpcPort, int channel) AddChannel(string gameIp, string grpcGameIp) { int channel = channels.Count + 1; int newGamePort = Target.BaseGamePort + channel; int newGrpcChannelPort = Target.BaseGrpcChannelPort + channel; IPAddress ipAddress = IPAddress.Parse(gameIp); + IPAddress grpcIpAddress = IPAddress.Parse(grpcGameIp); var gameEndpoint = new IPEndPoint(ipAddress, newGamePort); - var grpcUri = new Uri($"http://{IPAddress.Loopback}:{newGrpcChannelPort}"); + var grpcUri = new Uri($"http://{grpcIpAddress}:{newGrpcChannelPort}"); GrpcChannel grpcChannel = GrpcChannel.ForAddress(grpcUri); var client = new ChannelClient(grpcChannel); var healthClient = new Health.HealthClient(grpcChannel); diff --git a/Maple2.Server.World/Service/WorldService.GamePorts.cs b/Maple2.Server.World/Service/WorldService.GamePorts.cs index 75029e307..21924e3cb 100644 --- a/Maple2.Server.World/Service/WorldService.GamePorts.cs +++ b/Maple2.Server.World/Service/WorldService.GamePorts.cs @@ -5,7 +5,7 @@ namespace Maple2.Server.World.Service; public partial class WorldService { public override Task AddChannel(AddChannelRequest request, ServerCallContext context) { - (ushort gamePort, int grpcPort, int channel) = channelClients.FindOrCreateChannelByIp(request.GameIp); + (ushort gamePort, int grpcPort, int channel) = channelClients.FindOrCreateChannelByIp(request.GameIp, request.GrpcGameIp); return Task.FromResult(new AddChannelResponse { GamePort = gamePort,