using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Barotrauma.Extensions; using Barotrauma.Networking; namespace Barotrauma; public static partial class EosInterface { public static class Login { private static Implementation? LoadedImplementation => Core.LoadedImplementation; public enum CreateProductAccountError { EosNotInitialized, InvalidContinuanceToken, Timeout, UnhandledErrorCondition } public static async Task> CreateProductAccount( EosConnectContinuanceToken eosContinuanceToken) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.CreateProductAccount(eosContinuanceToken) : Result.Failure(CreateProductAccountError.EosNotInitialized); public enum LinkExternalAccountError { EosNotInitialized, InvalidContinuanceToken, Timeout, CannotLink, UnhandledErrorCondition } public static async Task> LinkExternalAccount(ProductUserId puid, EosConnectContinuanceToken eosContinuanceToken) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LinkExternalAccount(puid, eosContinuanceToken) : Result.Failure(LinkExternalAccountError.EosNotInitialized); public enum UnlinkExternalAccountError { EosNotInitialized, FailedToGetExternalAccounts, NotLoggedInToGivenAccount, Timeout, CannotLink, InvalidUser, UnhandledErrorCondition } public static async Task> UnlinkExternalAccount(ProductUserId puid) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.UnlinkExternalAccount(puid) : Result.Failure(UnlinkExternalAccountError.EosNotInitialized); public enum LoginError { EosNotInitialized, SteamNotLoggedIn, FailedToGetSteamSessionTicket, EgsLoginTimeout, EgsAccountNotFound, FailedToParseEgsId, FailedToGetEgsIdToken, AuthExchangeCodeNotFound, AuthRequiresOpeningBrowser, Timeout, InvalidUser, EgsAccessDenied, EosAccessDenied, UnexpectedContinuanceToken, UnhandledFailureCondition } [Flags] public enum LoginEpicFlags { None = 0x0, FailWithoutOpeningBrowser = 0x1 } public static async Task, LoginError>> LoginEpicWithLinkedSteamAccount(LoginEpicFlags flags) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LoginEpicWithLinkedSteamAccount(flags) : Result.Failure(LoginError.EosNotInitialized); public static async Task, LoginError>> LoginEpicExchangeCode(string exchangeCode) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LoginEpicExchangeCode(exchangeCode) : Result.Failure(LoginError.EosNotInitialized); public static async Task, LoginError>> LoginEpicIdToken(EgsIdToken token) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LoginEpicIdToken(token) : Result.Failure(LoginError.EosNotInitialized); public static async Task, LoginError>> LoginSteam() => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LoginSteam() : Result.Failure(LoginError.EosNotInitialized); public enum LinkExternalAccountToEpicAccountError { EosNotInitialized, TimedOut, FailedToParseEgsAccountId, UnhandledErrorCondition } public static async Task> LinkExternalAccountToEpicAccount(EgsAuthContinuanceToken continuanceToken) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LinkExternalAccountToEpicAccount(continuanceToken) : Result.Failure(LinkExternalAccountToEpicAccountError.EosNotInitialized); public enum LogoutEpicAccountError { EosNotInitialized, TimedOut, UnhandledErrorCondition } public static async Task> LogoutEpicAccount(EpicAccountId egsId) => LoadedImplementation.IsInitialized() ? await LoadedImplementation.LogoutEpicAccount(egsId) : Result.Failure(LogoutEpicAccountError.EosNotInitialized); /// /// This is essentially a function for logging out, except EOS has no EOS_Connect_Logout function /// so instead we have this to fake it. Once you use this, no methods should return this PUID /// until you log into it again. /// public static void MarkAsInaccessible(ProductUserId puid) { if (LoadedImplementation.IsInitialized()) { LoadedImplementation.MarkAsInaccessible(puid); } } public static Option ParseEgsExchangeCode(IReadOnlyList args) { if (args.Contains("-AUTH_TYPE=exchangecode", StringComparer.OrdinalIgnoreCase)) { return args.FirstOrNone(arg => arg.StartsWith("-AUTH_PASSWORD=", StringComparison.OrdinalIgnoreCase)) .Select(arg => arg["-AUTH_PASSWORD=".Length..]); } return Option.None; } public static void TestEosSessionTimeoutRecovery(ProductUserId puid) { if (LoadedImplementation.IsInitialized()) { LoadedImplementation.TestEosSessionTimeoutRecovery(puid); } } } internal abstract partial class Implementation { public abstract Task> CreateProductAccount( EosConnectContinuanceToken eosContinuanceToken); public abstract Task> LinkExternalAccount(ProductUserId puid, EosConnectContinuanceToken eosContinuanceToken); public abstract Task> UnlinkExternalAccount(ProductUserId puid); public abstract Task, Login.LoginError>> LoginEpicExchangeCode(string exchangeCode); public abstract Task, Login.LoginError>> LoginEpicWithLinkedSteamAccount(Login.LoginEpicFlags flags); public abstract Task, Login.LoginError>> LoginEpicIdToken(EgsIdToken token); public abstract Task, Login.LoginError>> LoginSteam(); public abstract Task> LinkExternalAccountToEpicAccount(EgsAuthContinuanceToken continuanceToken); public abstract Task> LogoutEpicAccount(EpicAccountId egsId); public abstract void MarkAsInaccessible(ProductUserId puid); public abstract void TestEosSessionTimeoutRecovery(ProductUserId puid); } }