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 488c2d14e..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); -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 01a0b800e..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}:{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,