From 1014178db6e6ad2befc966e501be737fbb0578a9 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 13 Jul 2016 15:56:55 +0100 Subject: [PATCH] Serialize etc --- Facepunch.Steamworks/Client/Inventory.cs | 54 ++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/Facepunch.Steamworks/Client/Inventory.cs b/Facepunch.Steamworks/Client/Inventory.cs index b097f57..576b456 100644 --- a/Facepunch.Steamworks/Client/Inventory.cs +++ b/Facepunch.Steamworks/Client/Inventory.cs @@ -36,10 +36,33 @@ internal Inventory( Client c ) client = c; LoadItemDefinitions(); - - } + /// + /// Call this at least every two minutes, every frame doesn't hurt. + /// You should call it when you consider it active play time. + /// IE - your player is alive, and playing. + /// Don't stress on it too much tho cuz it's super hijackable anyway. + /// + public void DropHeartbeat() + { + client._inventory.SendItemDropHeartbeat(); + } + + /// + /// Trigger an item drop. Call this when it's a good time to award + /// an item drop to a player. This won't automatically result in giving + /// an item to a player. Just call it every minute or so, or on launch. + /// ItemDefinition is usually a generator + /// + public void TriggerItemDrop( Definition definition ) + { + int result = 0; + client._inventory.TriggerItemDrop( ref result, definition.Id ); + client._inventory.DestroyResult( result ); + } + + /// /// Call this to retrieve the items. /// Note that if this has already been called it won't @@ -128,7 +151,18 @@ private void UpdateRequest() /// public Item[] Items; - private void RetrieveInventory() + /// + /// You can send this data to a server, or another player who can then deserialize it + /// and get a verified list of items. + /// + public byte[] SerializedItems; + + /// + /// Serialized data exprires after an hour. This is the time the value in SerializedItems will expire. + /// + public DateTime SerializedExpireTime; + + private unsafe void RetrieveInventory() { Valve.Steamworks.SteamItemDetails_t[] items = null; client._inventory.GetResultItems( updateRequest, out items ); @@ -146,6 +180,20 @@ private void RetrieveInventory() }; } ).ToArray(); + // + // Get a serialized version + // + uint size = 0; + client._inventory.SerializeResult( updateRequest, IntPtr.Zero, ref size ); + SerializedItems = new byte[size]; + + fixed( byte* b = SerializedItems ) + { + client._inventory.SerializeResult( updateRequest, (IntPtr) b, ref size ); + } + + SerializedExpireTime = DateTime.Now.Add( TimeSpan.FromMinutes( 60 ) ); + // // Tell everyone we've got new items! //