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

refactor: abstract out Launcher > ILauncher/SqexLauncher #949

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ namespace XIVLauncher.Common.Game.Exceptions;

public class SteamLinkNeededException : Exception
{
public SteamLinkNeededException()
public string? Document { get; set; }

public SteamLinkNeededException(string document)
: base("No steam account linked.")
{
this.Document = Document;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace XIVLauncher.Common.Game.Exceptions;

public class VersionCheckLoginException : Exception
{
public LoginState State { get; }

public VersionCheckLoginException(LoginState state)
: base()
{
State = state;
}
}
5 changes: 3 additions & 2 deletions src/XIVLauncher.Common/Game/Headlines.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using XIVLauncher.Common.Game.Launcher;

namespace XIVLauncher.Common.Game
{
Expand Down Expand Up @@ -51,7 +52,7 @@ public class News

public partial class Headlines
{
public static async Task<Headlines> Get(Launcher game, ClientLanguage language)
public static async Task<Headlines> Get(ILauncher game, ClientLanguage language)
{
var unixTimestamp = Util.GetUnixMillis();
var langCode = language.GetLangCode();
Expand All @@ -75,4 +76,4 @@ internal static class Converter
}
};
}
}
}
115 changes: 115 additions & 0 deletions src/XIVLauncher.Common/Game/Launcher/ActozLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;

#if NET6_0_OR_GREATER && !WIN32
using System.Net.Security;
#endif

using System.Threading.Tasks;
using Serilog;
using XIVLauncher.Common.Game.Patch.PatchList;
using XIVLauncher.Common.PlatformAbstractions;

#nullable enable

namespace XIVLauncher.Common.Game.Launcher;

public class ActozLauncher : ILauncher
{
private readonly ISettings settings;
private readonly HttpClient client;

public ActozLauncher(ISettings settings)
{
this.settings = settings;

ServicePointManager.Expect100Continue = false;

#if NET6_0_OR_GREATER && !WIN32
var sslOptions = new SslClientAuthenticationOptions()
{
CipherSuitesPolicy = new CipherSuitesPolicy(new[] { TlsCipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 })
};

var handler = new SocketsHttpHandler
{
UseCookies = false,
SslOptions = sslOptions,
};
#else
var handler = new HttpClientHandler
{
UseCookies = false,
};
#endif

this.client = new HttpClient(handler);
}

// TODO(Ava): not 100% sure this is correct, don't quote me on it
private const string PATCHER_USER_AGENT = "FFXIV_Patch";
private const int CURRENT_EXPANSION_LEVEL = 4;

public async Task<LoginResult> Login(string userName, string password, string otp, bool useCache, DirectoryInfo gamePath, bool forceBaseVersion, bool isFreeTrial)
{
throw new NotImplementedException();
}

public object? LaunchGame(IGameRunner runner, string sessionId, int region, int expansionLevel,
string additionalArguments, DirectoryInfo gamePath, bool isDx11,
ClientLanguage language, bool encryptArguments, DpiAwareness dpiAwareness)
{
throw new NotImplementedException();
}

public async Task<PatchListEntry[]> CheckBootVersion(DirectoryInfo gamePath, bool forceBaseVersion = false)
{
return Array.Empty<PatchListEntry>();
}

public async Task<PatchListEntry[]> CheckGameVersion(DirectoryInfo gamePath, bool forceBaseVersion = false)
{
var request = new HttpRequestMessage(HttpMethod.Get,
$"http://gamever-live.ff14.co.kr/http/win32/actoz_release_ko_game/{(forceBaseVersion ? Constants.BASE_GAME_VERSION : Repository.Ffxiv.GetVer(gamePath))}/");

request.Headers.AddWithoutValidation("X-Hash-Check", "enabled");
request.Headers.AddWithoutValidation("User-Agent", PATCHER_USER_AGENT);

Util.EnsureVersionSanity(gamePath, CURRENT_EXPANSION_LEVEL);

var resp = await this.client.SendAsync(request);
var text = await resp.Content.ReadAsStringAsync();

if (string.IsNullOrEmpty(text))
return Array.Empty<PatchListEntry>();

Log.Verbose("Game Patching is needed... List:\n{PatchList}", text);

return PatchListParser.Parse(text);
}

public async Task<string> GenPatchToken(string patchUrl, string uniqueId)
{
// KR/CN don't require authentication for patches
return patchUrl;
}

public async Task<GateStatus> GetGateStatus(ClientLanguage language)
{
throw new NotImplementedException();
}

public async Task<bool> GetLoginStatus()
{
throw new NotImplementedException();
}

public async Task<byte[]> DownloadAsLauncher(string url, ClientLanguage language, string contentType = "")
{
throw new NotImplementedException();
}
}

#nullable restore
28 changes: 28 additions & 0 deletions src/XIVLauncher.Common/Game/Launcher/ILauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using System.Threading.Tasks;
using XIVLauncher.Common.Game.Patch.PatchList;
using XIVLauncher.Common.PlatformAbstractions;

namespace XIVLauncher.Common.Game.Launcher;

public interface ILauncher
{
public Task<PatchListEntry[]> CheckBootVersion(DirectoryInfo gamePath, bool forceBaseVersion = false);

public Task<PatchListEntry[]> CheckGameVersion(DirectoryInfo gamePath, bool forceBaseVersion = false);

// TODO(Ava): KR/CN probably don't need isFreeTrial, figure out how to abstract this better
public Task<LoginResult> Login(string userName, string password, string otp, bool useCache, DirectoryInfo gamePath, bool forceBaseVersion, bool isFreeTrial);

public object? LaunchGame(IGameRunner runner, string sessionId, int region, int expansionLevel,
string additionalArguments, DirectoryInfo gamePath, bool isDx11,
ClientLanguage language, bool encryptArguments, DpiAwareness dpiAwareness);

public Task<GateStatus> GetGateStatus(ClientLanguage language);

public Task<bool> GetLoginStatus();

public Task<string> GenPatchToken(string patchUrl, string uniqueId);

public Task<byte[]> DownloadAsLauncher(string url, ClientLanguage language, string contentType = "");
}
115 changes: 115 additions & 0 deletions src/XIVLauncher.Common/Game/Launcher/ShandaLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;

#if NET6_0_OR_GREATER && !WIN32
using System.Net.Security;
#endif

using System.Threading.Tasks;
using Serilog;
using XIVLauncher.Common.Game.Patch.PatchList;
using XIVLauncher.Common.PlatformAbstractions;

#nullable enable

namespace XIVLauncher.Common.Game.Launcher;

public class ShandaLauncher : ILauncher
{
private readonly ISettings settings;
private readonly HttpClient client;

public ShandaLauncher(ISettings settings)
{
this.settings = settings;

ServicePointManager.Expect100Continue = false;

#if NET6_0_OR_GREATER && !WIN32
var sslOptions = new SslClientAuthenticationOptions()
{
CipherSuitesPolicy = new CipherSuitesPolicy(new[] { TlsCipherSuite.TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 })
};

var handler = new SocketsHttpHandler
{
UseCookies = false,
SslOptions = sslOptions,
};
#else
var handler = new HttpClientHandler
{
UseCookies = false,
};
#endif

this.client = new HttpClient(handler);
}

// TODO(Ava): not 100% sure this is correct, don't quote me on it
private const string PATCHER_USER_AGENT = "FFXIV_Patch";
private const int CURRENT_EXPANSION_LEVEL = 4;

public async Task<LoginResult> Login(string userName, string password, string otp, bool useCache, DirectoryInfo gamePath, bool forceBaseVersion, bool isFreeTrial)
{
throw new NotImplementedException();
}

public object? LaunchGame(IGameRunner runner, string sessionId, int region, int expansionLevel,
string additionalArguments, DirectoryInfo gamePath, bool isDx11,
ClientLanguage language, bool encryptArguments, DpiAwareness dpiAwareness)
{
throw new NotImplementedException();
}

public async Task<PatchListEntry[]> CheckBootVersion(DirectoryInfo gamePath, bool forceBaseVersion = false)
{
return Array.Empty<PatchListEntry>();
}

public async Task<PatchListEntry[]> CheckGameVersion(DirectoryInfo gamePath, bool forceBaseVersion = false)
{
var request = new HttpRequestMessage(HttpMethod.Get,
$"http://ffxivpatch01.ff14.sdo.com/http/win32/shanda_release_chs_game/{(forceBaseVersion ? Constants.BASE_GAME_VERSION : Repository.Ffxiv.GetVer(gamePath))}/");

request.Headers.AddWithoutValidation("X-Hash-Check", "enabled");
request.Headers.AddWithoutValidation("User-Agent", PATCHER_USER_AGENT);

Util.EnsureVersionSanity(gamePath, CURRENT_EXPANSION_LEVEL);

var resp = await this.client.SendAsync(request);
var text = await resp.Content.ReadAsStringAsync();

if (string.IsNullOrEmpty(text))
return Array.Empty<PatchListEntry>();

Log.Verbose("Game Patching is needed... List:\n{PatchList}", text);

return PatchListParser.Parse(text);
}

public async Task<string> GenPatchToken(string patchUrl, string uniqueId)
{
// KR/CN don't require authentication for patches
return patchUrl;
}

public async Task<GateStatus> GetGateStatus(ClientLanguage language)
{
throw new NotImplementedException();
}

public async Task<bool> GetLoginStatus()
{
throw new NotImplementedException();
}

public async Task<byte[]> DownloadAsLauncher(string url, ClientLanguage language, string contentType = "")
{
throw new NotImplementedException();
}
}

#nullable restore
Loading