Skip to content

Commit 3e186ca

Browse files
Add ResolvedExternalIPAddress to API and Master Communication (#365)
* Feature: Add ResolvedExternalIPAddress to API and Master Communication This commit introduces the `ResolvedExternalIPAddress` property to enhance IP address reporting. 1. **Server API (`WebfrontCore/Controllers/API/Server.cs`):** The `ResolvedExternalIPAddress` property has been added to the JSON responses for the `/api/server` endpoints. This property is nullable and contains the IPv4 string value of the manager's external IP address if the server's resolved IP endpoint is an internal address. Otherwise, it is null. 2. **Master Server Communication (`MasterCommunication.cs` and `ApiServer.cs`):** - The `ApiServer` DTO (in `Application/API/Master/ApiServer.cs`) now includes the `ResolvedExternalIPAddress` property (serialized as `resolved_external_ip_address`). - The `UploadStatus` method in `Application/Misc/MasterCommunication.cs` now populates this property for each server being reported to the master server, using the same logic (external IP if server's own resolved IP is internal). This provides more comprehensive IP address information both through the web API and to the master server. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 604aba6 commit 3e186ca

4 files changed

Lines changed: 7 additions & 1 deletion

File tree

Application/API/Master/ApiServer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ public class ApiServer
2424
public int ClientNum { get; set; }
2525
[JsonPropertyName("maxclientnum")]
2626
public int MaxClientNum { get; set; }
27+
[JsonPropertyName("resolved_external_ip_address")]
28+
public string? ResolvedExternalIPAddress { get; set; }
2729
}
2830
}

Application/Misc/MasterCommunication.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ private async Task UploadStatus()
149149
MaxClientNum = s.MaxClients,
150150
Id = s.EndPoint,
151151
Port = (short)s.ListenPort,
152-
IPAddress = s.ListenAddress
152+
IPAddress = s.ListenAddress,
153+
ResolvedExternalIPAddress = s.ResolvedIpEndPoint.Address.IsInternal() ? _manager.ExternalIPAddress : null
153154
}).ToList(),
154155
WebfrontUrl = _appConfig.WebfrontUrl
155156
};

SharedLibraryCore/Dtos/ServerInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class ServerInfo
2525
public string IPAddress { get; set; }
2626
public string ExternalIPAddress { get; set; }
2727
public bool IsPasswordProtected { get; set; }
28+
public string? ResolvedExternalIPAddress { get; set; }
2829
public string Endpoint => $"{IPAddress}:{Port}";
2930

3031
public double? LobbyZScore

WebfrontCore/Controllers/API/Server.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public IActionResult Index()
3939
name = server.GametypeName
4040
},
4141
Parser = server.RconParser.Name,
42+
ResolvedExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Manager.ExternalIPAddress : null,
4243
}));
4344
}
4445

@@ -68,6 +69,7 @@ public IActionResult GetServerById(string id)
6869
name = foundServer.GametypeName
6970
},
7071
Parser = foundServer.RconParser.Name,
72+
ResolvedExternalIPAddress = foundServer.ResolvedIpEndPoint.Address.IsInternal() ? Manager.ExternalIPAddress : null
7173
});
7274
}
7375

0 commit comments

Comments
 (0)