Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement hostname support for DCS interfaces. #857

Merged
merged 1 commit into from
Dec 22, 2024
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
6 changes: 3 additions & 3 deletions Helios/Interfaces/DCS/Common/DCSExportConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public class ModuleFormatInfo
private string _exportImpersonationModuleText = "";

/// <summary>
/// IP address to which Export.lua will send UDP updates
/// IP V4 address or Hostname to which Export.lua will send UDP updates
/// </summary>
private string _ipAddress;

Expand Down Expand Up @@ -390,7 +390,7 @@ public int ExportFrequency
/// IP address to which Export.lua will send UDP updates
/// This is a site-specific setting persisted in HeliosSettings instead of in the profile.
/// </summary>
public string IPAddress
public string NetworkAddress
{
get => _ipAddress;
set
Expand Down Expand Up @@ -1055,7 +1055,7 @@ private void UpdateExportScript()

_exportMain = exportMainRaw
// REVISIT: validate the IP address against allowable protocol versions and address types for this version of HeliosExport__.lua
.Replace("HELIOS_REPLACE_IPAddress", IPAddress)
.Replace("HELIOS_REPLACE_NETWORKADDRESS", NetworkAddress)
.Replace("HELIOS_REPLACE_Port", Port.ToString())
.Replace("HELIOS_REPLACE_ExportInterval", Math.Round(1d / Math.Max(4, ExportFrequency), 3).ToString(CultureInfo.InvariantCulture));
}
Expand Down
8 changes: 4 additions & 4 deletions Helios/Interfaces/DCS/Common/ExportConfigurationSection.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Content="IP Address"/>
<TextBox Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" Width="200"
MaxWidth="200" Text="{Binding Path=Configuration.IPAddress}"/>
<TextBlock Grid.Column="1" Grid.Row="1" Style="{StaticResource Documentation}" Text="IP Address to which Export script will send data. If you are running on the same machine 127.0.0.1 is recommended."/>
<Label Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Content="Network Address"/>
<TextBox Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Left" Width="250"
MaxWidth="250" Text="{Binding Path=Configuration.NetworkAddress}"/>
<TextBlock Grid.Column="1" Grid.Row="1" Style="{StaticResource Documentation}" Text="IP V4 Address or Hostname to which Export script will send data. If you are running on the same machine 127.0.0.1 is recommended."/>
<Label Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Content="Port"/>
<TextBox Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Left" Width="40"
MaxWidth="40" Text="{Binding Path=Configuration.Port}"/>
Expand Down
20 changes: 19 additions & 1 deletion Helios/Interfaces/DCS/Common/HeliosExport16.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ log.write("HELIOS.EXPORT", log.INFO, "initializing Helios Export script")
-- This section is configured by the DCS Interfaces in Helios Profile Editor

-- address to which we send
helios_private.host = "HELIOS_REPLACE_IPAddress"
helios_private.host = "HELIOS_REPLACE_NETWORKADDRESS"

-- UDP port to which we send
-- NOTE: our local port on which we listen is dynamic
Expand Down Expand Up @@ -367,6 +367,8 @@ function helios_impl.init()

log.write("HELIOS.EXPORT", log.DEBUG, "loaded")

helios_private.host = helios_private.resolveHostname(helios_private.host)

log.write(
"HELIOS.EXPORT",
log.INFO,
Expand Down Expand Up @@ -807,6 +809,22 @@ function helios_private.calculateNextUpdate(currentUpdate, updateInterval)
return nextUpdate
end

--- Resolve Hostname
function helios_private.resolveHostname(networkAddress)
local ipTest = {networkAddress:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
if(#ipTest ~= 4) then
local ipaddress = nil
ipaddress = socket.dns.toip(networkAddress) -- can be IP address or Hostname
if(ipaddress ~= nil ) then
log.write("HELIOS.EXPORT", log.INFO, string.format("Resolved address %s to %s",networkAddress, ipaddress))
return ipaddress
else
log.write("HELIOS.EXPORT", log.ERROR, string.format("Unable to resolve address %s",networkAddress))
end
end
return networkAddress
end

-- ========================= MODULE COMPATIBILITY LAYER ==========================
-- These functions make this script compatible with Capt Zeen Helios modules.
-- Simply place the modules in the Scripts/Helios/Mods folder and make sure they
Expand Down