From 55f98f635071507210c35261ab5852c8c000e1b1 Mon Sep 17 00:00:00 2001 From: James King Date: Sat, 14 Sep 2019 14:21:35 +0200 Subject: [PATCH] Cache age / metadata for workshop queries --- Facepunch.Steamworks/Interfaces/Workshop.Editor.cs | 6 +++--- Facepunch.Steamworks/Interfaces/Workshop.Item.cs | 1 + Facepunch.Steamworks/Interfaces/Workshop.Query.cs | 14 +++++++++++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs index 36bcb33..6ffa475 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Editor.cs @@ -26,7 +26,7 @@ public class Editor public string Error { get; internal set; } = null; public string ChangeNote { get; set; } = ""; public uint WorkshopUploadAppId { get; set; } - public string MetaData { get; set; } = null; + public string Metadata { get; set; } = null; public Dictionary KeyValues { get; set; } = new Dictionary(); public enum VisibilityType : int @@ -182,9 +182,9 @@ private void PublishChanges() workshop.ugc.SetItemPreview( UpdateHandle, PreviewImage ); } - if ( MetaData != null ) + if ( Metadata != null ) { - workshop.ugc.SetItemMetadata( UpdateHandle, MetaData ); + workshop.ugc.SetItemMetadata( UpdateHandle, Metadata ); } if ( KeyValues != null ) diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs index 0435a49..0a55aea 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Item.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Item.cs @@ -229,6 +229,7 @@ public Editor Edit() public int WebsiteViews { get; internal set; } public int ReportScore { get; internal set; } public string PreviewImageUrl { get; internal set; } + public string Metadata { get; internal set; } string _ownerName = null; diff --git a/Facepunch.Steamworks/Interfaces/Workshop.Query.cs b/Facepunch.Steamworks/Interfaces/Workshop.Query.cs index b521a26..995f21f 100644 --- a/Facepunch.Steamworks/Interfaces/Workshop.Query.cs +++ b/Facepunch.Steamworks/Interfaces/Workshop.Query.cs @@ -35,8 +35,12 @@ public class Query : IDisposable public ulong? UserId { get; set; } + public TimeSpan? MaxCacheAge { get; set; } + public bool ReturnKeyValueTags { get; set; } + public bool ReturnMetadata { get; set; } + /// /// If order is RankedByTrend, this value represents how many days to take /// into account. @@ -123,6 +127,10 @@ void RunInternal() workshop.ugc.AddExcludedTag( Handle, tag ); workshop.ugc.SetReturnKeyValueTags( Handle, ReturnKeyValueTags ); + workshop.ugc.SetReturnMetadata( Handle, ReturnMetadata ); + + if ( MaxCacheAge.HasValue ) + workshop.ugc.SetAllowCachedResponse( Handle, (uint) MaxCacheAge.Value.TotalSeconds ); Callback = workshop.ugc.SendQueryUGCRequest( Handle, ResultCallback ); } @@ -160,10 +168,14 @@ void ResultCallback( SteamNative.SteamUGCQueryCompleted_t data, bool bFailed ) if ( ReturnKeyValueTags ) item.ReadKeyValueTags( data, (uint)i ); - string url = null; + string url; if ( workshop.ugc.GetQueryUGCPreviewURL( data.Handle, (uint)i, out url ) ) item.PreviewImageUrl = url; + string metadata; + if ( workshop.ugc.GetQueryUGCMetadata( data.Handle, (uint)i, out metadata ) ) + item.Metadata = metadata; + _results.Add( item ); _resultsRemain--;