v1.3.0.1 (Epic Store release)
This commit is contained in:
@@ -7,19 +7,20 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
static partial class SteamManager
|
||||
{
|
||||
private static Option<Steamworks.AuthTicket> currentMultiplayerTicket = Option.None;
|
||||
public static Option<Steamworks.AuthTicket> GetAuthSessionTicketForMultiplayer(Endpoint remoteHostEndpoint)
|
||||
#region Auth ticket for Steam host
|
||||
private static Option<Steamworks.AuthTicket> currentSteamHostAuthTicket = Option.None;
|
||||
public static Option<Steamworks.AuthTicket> GetAuthSessionTicketForSteamHost(Endpoint remoteHostEndpoint)
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
if (currentMultiplayerTicket.TryUnwrap(out var ticketToCancel))
|
||||
if (currentSteamHostAuthTicket.TryUnwrap(out var ticketToCancel))
|
||||
{
|
||||
ticketToCancel.Cancel();
|
||||
}
|
||||
currentMultiplayerTicket = Option.None;
|
||||
currentSteamHostAuthTicket = Option.None;
|
||||
|
||||
var netIdentity = remoteHostEndpoint switch
|
||||
{
|
||||
@@ -32,13 +33,42 @@ namespace Barotrauma.Steam
|
||||
};
|
||||
var newTicket = Steamworks.SteamUser.GetAuthSessionTicket(netIdentity);
|
||||
|
||||
currentMultiplayerTicket = newTicket != null
|
||||
currentSteamHostAuthTicket = newTicket != null
|
||||
? Option.Some(newTicket)
|
||||
: Option.None;
|
||||
|
||||
return currentMultiplayerTicket;
|
||||
return currentSteamHostAuthTicket;
|
||||
}
|
||||
#endregion Auth ticket for Steam host
|
||||
|
||||
#region Auth ticket for EOS host
|
||||
private const string EosHostAuthIdentity = "BarotraumaRemotePlayerAuth";
|
||||
|
||||
private static Option<Steamworks.AuthTicketForWebApi> currentEosHostAuthTicket = Option.None;
|
||||
public static async Task<Option<Steamworks.AuthTicketForWebApi>> GetAuthTicketForEosHostAuth()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
{
|
||||
return Option.None;
|
||||
}
|
||||
|
||||
if (currentEosHostAuthTicket.TryUnwrap(out var ticketToCancel))
|
||||
{
|
||||
ticketToCancel.Cancel();
|
||||
}
|
||||
currentEosHostAuthTicket = Option.None;
|
||||
|
||||
var newTicket = await Steamworks.SteamUser.GetAuthTicketForWebApi(identity: EosHostAuthIdentity);
|
||||
|
||||
currentEosHostAuthTicket = newTicket != null
|
||||
? Option.Some(newTicket)
|
||||
: Option.None;
|
||||
|
||||
return currentEosHostAuthTicket;
|
||||
}
|
||||
#endregion Auth ticket for EOS host
|
||||
|
||||
#region Auth ticket for GameAnalytics consent server
|
||||
private const string GameAnalyticsConsentIdentity = "BarotraumaGameAnalyticsConsent";
|
||||
|
||||
private static Option<Steamworks.AuthTicketForWebApi> currentGameAnalyticsConsentTicket = Option.None;
|
||||
@@ -63,5 +93,6 @@ namespace Barotrauma.Steam
|
||||
|
||||
return currentGameAnalyticsConsentTicket;
|
||||
}
|
||||
#endregion Auth ticket for GameAnalytics consent server
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Steamworks.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using Barotrauma.Networking;
|
||||
using Barotrauma.IO;
|
||||
|
||||
namespace Barotrauma.Steam
|
||||
{
|
||||
@@ -38,6 +40,15 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
}
|
||||
|
||||
public static bool SteamworksLibExists
|
||||
=> RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
||||
? File.Exists("steam_api64.dll")
|
||||
: RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
|
||||
? File.Exists("libsteam_api64.dylib")
|
||||
: RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
|
||||
? File.Exists("libsteam_api64.so")
|
||||
: false;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
InitializeProjectSpecific();
|
||||
@@ -53,6 +64,16 @@ namespace Barotrauma.Steam
|
||||
return Option<SteamId>.Some(new SteamId(Steamworks.SteamClient.SteamId));
|
||||
}
|
||||
|
||||
public static Option<SteamId> GetOwnerSteamId()
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid)
|
||||
{
|
||||
return Option<SteamId>.None();
|
||||
}
|
||||
|
||||
return Option<SteamId>.Some(new SteamId(Steamworks.SteamClient.SteamId));
|
||||
}
|
||||
|
||||
public static bool IsFamilyShared()
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return false; }
|
||||
@@ -112,42 +133,78 @@ namespace Barotrauma.Steam
|
||||
return unlocked;
|
||||
}
|
||||
|
||||
public static bool IncrementStat(Identifier statName, int increment)
|
||||
/// <summary>
|
||||
/// Increment multiple stats in bulk.
|
||||
/// Make sure to call StoreStats() after calling this method since it doesn't do it automatically.
|
||||
/// </summary>
|
||||
/// <param name="stats"></param>
|
||||
public static void IncrementStats(params (AchievementStat Identifier, float Increment)[] stats)
|
||||
=> Array.ForEach(stats, static s
|
||||
=> IncrementStat(s.Identifier, s.Increment, storeStats: false));
|
||||
|
||||
public static bool IncrementStat(AchievementStat statName, int increment, bool storeStats = true)
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return false; }
|
||||
DebugConsole.Log($"Incremented stat \"{statName}\" by " + increment);
|
||||
bool success = Steamworks.SteamUserStats.AddStat(statName.Value.ToLowerInvariant(), increment);
|
||||
bool success = Steamworks.SteamUserStats.AddStatInt(statName.ToIdentifier().Value.ToLowerInvariant(), increment);
|
||||
if (!success)
|
||||
{
|
||||
DebugConsole.Log("Failed to increment stat \"" + statName + "\".");
|
||||
}
|
||||
else
|
||||
else if (storeStats)
|
||||
{
|
||||
StoreStats();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public static bool IncrementStat(Identifier statName, float increment)
|
||||
public static bool IncrementStat(AchievementStat statName, float increment, bool storeStats = true)
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return false; }
|
||||
DebugConsole.Log($"Incremented stat \"{statName}\" by " + increment);
|
||||
bool success = Steamworks.SteamUserStats.AddStat(statName.Value.ToLowerInvariant(), increment);
|
||||
bool success = Steamworks.SteamUserStats.AddStatFloat(statName.ToIdentifier().Value.ToLowerInvariant(), increment);
|
||||
if (!success)
|
||||
{
|
||||
DebugConsole.Log("Failed to increment stat \"" + statName + "\".");
|
||||
}
|
||||
else
|
||||
else if (storeStats)
|
||||
{
|
||||
StoreStats();
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
public static int GetStatInt(Identifier statName)
|
||||
public static int GetStatInt(AchievementStat stat)
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return 0; }
|
||||
return Steamworks.SteamUserStats.GetStatInt(statName.Value.ToLowerInvariant());
|
||||
return Steamworks.SteamUserStats.GetStatInt(stat.ToString().ToLowerInvariant());
|
||||
}
|
||||
|
||||
public static float GetStatFloat(AchievementStat stat)
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return 0f; }
|
||||
return Steamworks.SteamUserStats.GetStatFloat(stat.ToString().ToLowerInvariant());
|
||||
}
|
||||
|
||||
public static ImmutableDictionary<AchievementStat, float> GetAllStats()
|
||||
{
|
||||
if (!IsInitialized || !Steamworks.SteamClient.IsValid) { return ImmutableDictionary<AchievementStat, float>.Empty; }
|
||||
|
||||
var builder = ImmutableDictionary.CreateBuilder<AchievementStat, float>();
|
||||
|
||||
foreach (AchievementStat stat in AchievementStatExtension.SteamStats)
|
||||
{
|
||||
if (stat.IsFloatStat())
|
||||
{
|
||||
builder.Add(stat, GetStatFloat(stat));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Add(stat, GetStatInt(stat));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
}
|
||||
|
||||
public static bool StoreStats()
|
||||
@@ -177,7 +234,7 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
//this should be run even if SteamManager is uninitialized
|
||||
//servers need to be able to notify clients of unlocked talents even if the server isn't connected to Steam
|
||||
SteamAchievementManager.Update(deltaTime);
|
||||
AchievementManager.Update(deltaTime);
|
||||
|
||||
if (!IsInitialized) { return; }
|
||||
|
||||
@@ -193,22 +250,6 @@ namespace Barotrauma.Steam
|
||||
if (Steamworks.SteamServer.IsValid) { Steamworks.SteamServer.Shutdown(); }
|
||||
}
|
||||
|
||||
public static IEnumerable<ulong> ParseWorkshopIds(string workshopIdData)
|
||||
{
|
||||
string[] workshopIds = workshopIdData.Split(',');
|
||||
foreach (string id in workshopIds)
|
||||
{
|
||||
if (ulong.TryParse(id, out ulong idCast))
|
||||
{
|
||||
yield return idCast;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<ulong> WorkshopUrlsToIds(IEnumerable<string> urls)
|
||||
{
|
||||
return urls.Select((u) =>
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Barotrauma.Steam
|
||||
return await queryTask;
|
||||
}
|
||||
|
||||
public static async Task<Steamworks.Ugc.Item?> MakeRequest(UInt64 id)
|
||||
public static async Task<Option<Steamworks.Ugc.Item>> MakeRequest(UInt64 id)
|
||||
{
|
||||
Task<WorkshopItemSet> ourTask;
|
||||
lock (mutex)
|
||||
@@ -155,7 +155,7 @@ namespace Barotrauma.Steam
|
||||
}
|
||||
|
||||
var items = await ourTask;
|
||||
var result = items.FirstOrNull(it => it.Id == id);
|
||||
var result = items.FirstOrNone(it => it.Id == id);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,7 @@ namespace Barotrauma.Steam
|
||||
/// The description of the returned item is truncated to save bandwidth.
|
||||
/// </summary>
|
||||
/// <param name="itemId">Workshop Item ID</param>
|
||||
public static Task<Steamworks.Ugc.Item?> GetItem(UInt64 itemId)
|
||||
public static Task<Option<Steamworks.Ugc.Item>> GetItem(UInt64 itemId)
|
||||
=> SingleItemRequestPool.MakeRequest(itemId);
|
||||
|
||||
/// <summary>
|
||||
@@ -176,15 +176,17 @@ namespace Barotrauma.Steam
|
||||
/// <param name="withLongDescription">
|
||||
/// If true, ask for the item's entire description, otherwise it'll be truncated.
|
||||
/// </param>
|
||||
public static async Task<Steamworks.Ugc.Item?> GetItemAsap(UInt64 itemId, bool withLongDescription = false)
|
||||
public static async Task<Option<Steamworks.Ugc.Item>> GetItemAsap(UInt64 itemId, bool withLongDescription = false)
|
||||
{
|
||||
if (!IsInitialized) { return null; }
|
||||
if (!IsInitialized) { return Option.None; }
|
||||
|
||||
var items = await GetWorkshopItems(
|
||||
Steamworks.Ugc.Query.All
|
||||
.WithFileId(itemId)
|
||||
.WithLongDescription(withLongDescription));
|
||||
return items.Any() ? items.First() : null;
|
||||
return items.Any()
|
||||
? Option.Some(items.First())
|
||||
: Option.None;
|
||||
}
|
||||
|
||||
public static async Task ForceRedownload(UInt64 itemId)
|
||||
@@ -379,7 +381,7 @@ namespace Barotrauma.Steam
|
||||
// made private. Players cannot download updates for these, so
|
||||
// we treat them as if they were deleted.
|
||||
allItems = (await Task.WhenAll(allItems.Select(it => GetItem(it.Id.Value))))
|
||||
.NotNull()
|
||||
.NotNone()
|
||||
.Where(it => it.ConsumerApp == AppID)
|
||||
.ToHashSet();
|
||||
|
||||
@@ -399,7 +401,7 @@ namespace Barotrauma.Steam
|
||||
|
||||
TaskPool.Add("DeleteUnsubscribedMods", GetPublishedAndSubscribedItems().WaitForLoadingScreen(), t =>
|
||||
{
|
||||
if (!t.TryGetResult(out ISet<Steamworks.Ugc.Item> items)) { return; }
|
||||
if (!t.TryGetResult(out ISet<Steamworks.Ugc.Item>? items)) { return; }
|
||||
var ids = items.Select(it => it.Id.Value).ToHashSet();
|
||||
var toUninstall = ContentPackageManager.WorkshopPackages
|
||||
.Where(pkg
|
||||
@@ -428,8 +430,8 @@ namespace Barotrauma.Steam
|
||||
{
|
||||
using var installCounter = await InstallTaskCounter.Create(id);
|
||||
|
||||
var itemNullable = await GetItem(id);
|
||||
if (!(itemNullable is { } item)) { return; }
|
||||
var itemOption = await GetItem(id);
|
||||
if (!itemOption.TryUnwrap(out var item)) { return; }
|
||||
await Task.Yield();
|
||||
|
||||
string itemTitle = item.Title?.Trim() ?? "";
|
||||
|
||||
Reference in New Issue
Block a user