Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions Maple2.Server.Core/Constants/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions Maple2.Server.Core/proto/world/world.proto
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ message GlobalPortalInfo {

message AddChannelRequest {
string game_ip = 1;
string grpc_game_ip = 2;
}

message AddChannelResponse {
Expand Down
1 change: 1 addition & 0 deletions Maple2.Server.DebugGame/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Maple2.Server.Game/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
var worldClient = new WorldClient(channel);
response = worldClient.AddChannel(new AddChannelRequest {
GameIp = Target.GameIp.ToString(),
GrpcGameIp = Target.GrpcGameIp.ToString()
Comment thread
AngeloTadeucci marked this conversation as resolved.
});

} catch (RpcException e) {
Expand Down
5 changes: 1 addition & 4 deletions Maple2.Server.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions Maple2.Server.World/Containers/ChannelClientLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public IEnumerable<int> 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() {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Maple2.Server.World/Service/WorldService.GamePorts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Maple2.Server.World.Service;

public partial class WorldService {
public override Task<AddChannelResponse> 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,
Expand Down