3 using System.Threading.Tasks;
8 static partial class SteamManager
10 #region Auth ticket for Steam host
11 private static Option<Steamworks.AuthTicket> currentSteamHostAuthTicket = Option.None;
12 public static Option<Steamworks.AuthTicket> GetAuthSessionTicketForSteamHost(
Endpoint remoteHostEndpoint)
19 if (currentSteamHostAuthTicket.TryUnwrap(out var ticketToCancel))
21 ticketToCancel.Cancel();
23 currentSteamHostAuthTicket = Option.None;
25 var netIdentity = remoteHostEndpoint
switch
27 LidgrenEndpoint { Address: LidgrenAddress { NetAddress: var ipAddr }, Port: var ipPort }
28 => (Steamworks.Data.NetIdentity)Steamworks.Data.NetAddress.From(ipAddr, (ushort)ipPort),
30 => (Steamworks.Data.NetIdentity)(Steamworks.SteamId)steamId.Value,
32 =>
throw new ArgumentOutOfRangeException(nameof(remoteHostEndpoint))
34 var newTicket = Steamworks.SteamUser.GetAuthSessionTicket(netIdentity);
36 currentSteamHostAuthTicket = newTicket !=
null
37 ? Option.Some(newTicket)
40 return currentSteamHostAuthTicket;
42 #endregion Auth ticket for Steam host
44 #region Auth ticket for EOS host
45 private const string EosHostAuthIdentity =
"BarotraumaRemotePlayerAuth";
47 private static Option<Steamworks.AuthTicketForWebApi> currentEosHostAuthTicket = Option.None;
48 public static async Task<Option<Steamworks.AuthTicketForWebApi>> GetAuthTicketForEosHostAuth()
55 if (currentEosHostAuthTicket.TryUnwrap(out var ticketToCancel))
57 ticketToCancel.Cancel();
59 currentEosHostAuthTicket = Option.None;
61 var newTicket = await Steamworks.SteamUser.GetAuthTicketForWebApi(identity: EosHostAuthIdentity);
63 currentEosHostAuthTicket = newTicket !=
null
64 ? Option.Some(newTicket)
67 return currentEosHostAuthTicket;
69 #endregion Auth ticket for EOS host
71 #region Auth ticket for GameAnalytics consent server
72 private const string GameAnalyticsConsentIdentity =
"BarotraumaGameAnalyticsConsent";
74 private static Option<Steamworks.AuthTicketForWebApi> currentGameAnalyticsConsentTicket = Option.None;
75 public static async Task<Option<Steamworks.AuthTicketForWebApi>> GetAuthTicketForGameAnalyticsConsent()
82 if (currentGameAnalyticsConsentTicket.TryUnwrap(out var ticketToCancel))
84 ticketToCancel.Cancel();
86 currentGameAnalyticsConsentTicket = Option.None;
88 var newTicket = await Steamworks.SteamUser.GetAuthTicketForWebApi(identity: GameAnalyticsConsentIdentity);
90 currentGameAnalyticsConsentTicket = newTicket !=
null
91 ? Option.Some(newTicket)
94 return currentGameAnalyticsConsentTicket;
96 #endregion Auth ticket for GameAnalytics consent server