Unstable 1.1.14.0
This commit is contained in:
@@ -1,18 +1,67 @@
|
||||
namespace Barotrauma.Steam
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Barotrauma.Networking;
|
||||
|
||||
namespace Barotrauma.Steam
|
||||
{
|
||||
static partial class SteamManager
|
||||
{
|
||||
private static Steamworks.AuthTicket currentTicket = null;
|
||||
public static Steamworks.AuthTicket GetAuthSessionTicket()
|
||||
private static Option<Steamworks.AuthTicket> currentMultiplayerTicket = Option.None;
|
||||
public static Option<Steamworks.AuthTicket> GetAuthSessionTicketForMultiplayer(Endpoint remoteHostEndpoint)
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
return null;
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
currentTicket?.Cancel();
|
||||
currentTicket = Steamworks.SteamUser.GetAuthSessionTicket();
|
||||
return currentTicket;
|
||||
if (currentMultiplayerTicket.TryUnwrap(out var ticketToCancel))
|
||||
{
|
||||
ticketToCancel.Cancel();
|
||||
}
|
||||
currentMultiplayerTicket = Option.None;
|
||||
|
||||
var netIdentity = remoteHostEndpoint switch
|
||||
{
|
||||
LidgrenEndpoint { Address: LidgrenAddress { NetAddress: var ipAddr }, Port: var ipPort }
|
||||
=> (Steamworks.Data.NetIdentity)Steamworks.Data.NetAddress.From(ipAddr, (ushort)ipPort),
|
||||
SteamP2PEndpoint { SteamId: var steamId }
|
||||
=> (Steamworks.Data.NetIdentity)(Steamworks.SteamId)steamId.Value,
|
||||
_
|
||||
=> throw new ArgumentOutOfRangeException(nameof(remoteHostEndpoint))
|
||||
};
|
||||
var newTicket = Steamworks.SteamUser.GetAuthSessionTicket(netIdentity);
|
||||
|
||||
currentMultiplayerTicket = newTicket != null
|
||||
? Option.Some(newTicket)
|
||||
: Option.None;
|
||||
|
||||
return currentMultiplayerTicket;
|
||||
}
|
||||
|
||||
private const string GameAnalyticsConsentIdentity = "BarotraumaGameAnalyticsConsent";
|
||||
|
||||
private static Option<Steamworks.AuthTicketForWebApi> currentGameAnalyticsConsentTicket = Option.None;
|
||||
public static async Task<Option<Steamworks.AuthTicketForWebApi>> GetAuthTicketForGameAnalyticsConsent()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
if (currentGameAnalyticsConsentTicket.TryUnwrap(out var ticketToCancel))
|
||||
{
|
||||
ticketToCancel.Cancel();
|
||||
}
|
||||
currentGameAnalyticsConsentTicket = Option.None;
|
||||
|
||||
var newTicket = await Steamworks.SteamUser.GetAuthTicketForWebApi(identity: GameAnalyticsConsentIdentity);
|
||||
|
||||
currentGameAnalyticsConsentTicket = newTicket != null
|
||||
? Option.Some(newTicket)
|
||||
: Option.None;
|
||||
|
||||
return currentGameAnalyticsConsentTicket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user