Skip to content
Open
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
4 changes: 3 additions & 1 deletion SS14.Launcher/Assets/Locale/en-US/text.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,9 @@ tab-options-disable-signing-desc = { "[" }DEV ONLY] Disables verification of eng
tab-options-hub-settings = Hub Settings
tab-options-hub-settings-desc = Change what hub server or servers you would like to use to fetch the server list.
tab-options-desc-incompatible = This option is incompatible with your platform and has been disabled.

tab-options-desc-proxy-address = Proxy information for connecting to the server hub and authentication services. Supports http, https and socks5 proxies (requires launcher restart)
tab-options-desc-proxy-enable = Enable Proxy
tab-options-desc-proxy-tooltip = Supports http, https, and socks5 proxies. For socks5, replace https:// with socks5://
## For the language selection menu.

# Text on the button that opens the menu.
Expand Down
22 changes: 20 additions & 2 deletions SS14.Launcher/HappyEyeballsHttp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Threading;
using System.Threading.Tasks;
using Serilog;

namespace SS14.Launcher;

public static class HappyEyeballsHttp
Expand Down Expand Up @@ -39,15 +38,34 @@
// * Look I wanted to keep this simple OK?
// We don't do any fancy shit like statefulness or incremental sorting
// or incremental DNS updates who cares about that.
public static HttpClient CreateHttpClient(bool autoRedirect = true)
public static HttpClient CreateHttpClient(bool autoRedirect = true, string proxyUrl = "")
{
// Log.Verbose("PROXY_URL: ", proxyUrl);
var handler = new SocketsHttpHandler
{
ConnectCallback = OnConnect,
AutomaticDecompression = DecompressionMethods.All,
AllowAutoRedirect = autoRedirect,
// PooledConnectionLifetime = TimeSpan.FromSeconds(1)
};
if (!String.IsNullOrEmpty(proxyUrl)){ //Note: I'm VERY new to writing c#. This is heavily copied from koksnull's work in https://github.com/space-wizards/SS14.Launcher/pull/144 . I've just made some adjustments to make it work for the modern versions of .net
//I'm unsure of how to go about this, but having some way to sanity check the proxy before activating it (i.e. a test ping) would be great.
// Uri proxyURI = new Uri(proxyUrl.Trim('"'));
Uri proxyURI;
if (Uri.TryCreate(proxyUrl,uriKind: 0, out proxyURI)){ //Catches malformed URI, in the event of a malformed URI, the launcher will boot but will be unable to retrive servers.

Check warning on line 55 in SS14.Launcher/HappyEyeballsHttp.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 55 in SS14.Launcher/HappyEyeballsHttp.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
WebProxy clientProxy = new WebProxy(proxyUrl.Trim('"')); //No clue why .trim('"') is required. C# jank? Doesn't work otherwise.
clientProxy.BypassProxyOnLocal = true;
if (!string.IsNullOrWhiteSpace(proxyURI.UserInfo)){
string[] credentials = proxyURI.UserInfo.Split(new[] { ':' });
if (credentials.Length > 1){
NetworkCredential cred = new NetworkCredential(userName: credentials[0], password: credentials[1]);
clientProxy.Credentials = cred;
}
}
handler.UseProxy = true;
handler.Proxy = clientProxy;
}
}

return new HttpClient(handler);
}
Expand Down
2 changes: 1 addition & 1 deletion SS14.Launcher/HttpSelfTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async Task RunSingleTest(string name, Func<int, string, Task> test)

private static async Task TestHappyEyeballsHttp(int id, string url)
{
using var client = HappyEyeballsHttp.CreateHttpClient(false);
using var client = HappyEyeballsHttp.CreateHttpClient(false); //Note: It may be worth refactoring this to also allow the http checks to be done via proxy. Afaik it doesn't cause issues, and would require giving it a ref to DataManager but it could certainly be done.

using var resp = await client.GetAsync(url);

Expand Down
10 changes: 10 additions & 0 deletions SS14.Launcher/Models/Data/CVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ public static readonly CVarDef<bool> HasDismissedEarlyAccessWarning
/// Language the user selected. Null means it should be automatically selected based on system language.
/// </summary>
public static readonly CVarDef<string?> Language = CVarDef.Create<string?>("Language", null);

/// <summary>
/// Weather the proxy is enabled for HappyEyeballsHttp connections (ie auth server/build server/hub connections, not game server connections)
/// </summary>
public static readonly CVarDef<bool> ProxyEnable = CVarDef.Create("ProxyEnable", false);

/// <summary>
/// Url for proxy connections.
/// </summary>
public static readonly CVarDef<string> ProxyURL = CVarDef.Create("ProxyURL", "");
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion SS14.Launcher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private static AppBuilder BuildAvaloniaApp(DataManager cfg)
{
var locator = Locator.CurrentMutable;

var http = HappyEyeballsHttp.CreateHttpClient();
var http = (cfg.GetCVar(CVars.ProxyEnable)) ? HappyEyeballsHttp.CreateHttpClient(proxyUrl: cfg.GetCVar(CVars.ProxyURL)) : HappyEyeballsHttp.CreateHttpClient(); //Ternary for creating connection with or without proxy
http.DefaultRequestHeaders.UserAgent.Add(
new ProductInfoHeaderValue(LauncherVersion.Name, LauncherVersion.Version?.ToString()));
http.DefaultRequestHeaders.Add("SS14-Launcher-Fingerprint", cfg.Fingerprint.ToString());
Expand Down
20 changes: 20 additions & 0 deletions SS14.Launcher/ViewModels/MainWindowTabs/OptionsTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,26 @@ public void ClearEngines()
_engineManager.ClearAllEngines();
}

public bool ProxyEnable
{
get => Cfg.GetCVar(CVars.ProxyEnable);
set
{
Cfg.SetCVar(CVars.ProxyEnable, value);
Cfg.CommitConfig();
}
}

public string ProxyURL
{
get => Cfg.GetCVar(CVars.ProxyURL);
set
{
Cfg.SetCVar(CVars.ProxyURL, value);
Cfg.CommitConfig();
}
}

public void ClearServerContent()
{
_contentManager.ClearAll();
Expand Down
8 changes: 7 additions & 1 deletion SS14.Launcher/Views/MainWindowTabs/OptionsTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@
<TextBlock VerticalAlignment="Center" IsVisible="{Binding !HideDisableSigning}" TextWrapping="Wrap"
Text="{loc:Loc tab-options-disable-signing-desc}"
Margin="8" />

<Grid ColumnDefinitions="Auto,*">
<CheckBox VerticalAlignment="Center" Margin="4" IsChecked="{Binding ProxyEnable}" Content="{loc:Loc tab-options-desc-proxy-enable}" />
<TextBox Grid.Column="1" Watermark="http://optional-username:optional-password@example.com:80" Text="{Binding ProxyURL}" ToolTip.Tip="{loc:Loc tab-options-desc-proxy-tooltip}"/>
</Grid>
<TextBlock VerticalAlignment="Center" TextWrapping="Wrap"
Text="{loc:Loc tab-options-desc-proxy-address}"
Margin="8" />
Comment on lines +68 to +74
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have some form of error reporting for in case the URL is misformatted.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have some form of error reporting for in case the URL is misformatted.

How would I go about this? I'd need some way to run Uri.TryCreate and I'm not exactly sure how to do that in avalonia. Would I run it in the UI script and show/hide a line of text indicating it?

<Button Click="OpenHubSettings" Content="{loc:Loc tab-options-hub-settings}" Margin="4" HorizontalAlignment="Left" />
<TextBlock VerticalAlignment="Center" TextWrapping="Wrap"
Text="{loc:Loc tab-options-hub-settings-desc}"
Expand Down
Loading