diff --git a/Facepunch.Steamworks.Test/AchievementsTest.cs b/Facepunch.Steamworks.Test/AchievementsTest.cs
deleted file mode 100644
index 2bd4fc4..0000000
--- a/Facepunch.Steamworks.Test/AchievementsTest.cs
+++ /dev/null
@@ -1,92 +0,0 @@
-using System;
-using System.Text;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public class Achievements
- {
- [TestMethod]
- public void GetCount()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var gotStats = false;
- client.Achievements.OnUpdated += () => { gotStats = true; };
-
- while ( !gotStats )
- {
- client.Update();
- }
-
- Console.WriteLine( "Found " + client.Achievements.All.Length + " Achievements" );
-
- Assert.AreNotEqual( 0, client.Achievements.All.Length );
- }
- }
-
- [TestMethod]
- public void GetNames()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var gotStats = false;
- client.Achievements.OnUpdated += () => { gotStats = true; };
-
- while ( !gotStats )
- {
- client.Update();
- }
-
- foreach( var ach in client.Achievements.All )
- {
- Assert.IsNotNull( ach.Id );
-
- Console.WriteLine( " " + ach.Id );
- Console.WriteLine( " - - " + ach.Name );
- Console.WriteLine( " - - " + ach.Description );
- Console.WriteLine( " - - " + ach.State );
- Console.WriteLine( " - - " + ach.UnlockTime );
- Console.WriteLine( " - - " + ach.GlobalUnlockedPercentage );
-
- if ( ach.Icon != null )
- {
- Console.WriteLine( " - - " + ach.Icon.Width + " x " + ach.Icon.Height );
- }
-
- Console.WriteLine( "" );
- }
- }
- }
-
- [TestMethod]
- public void Trigger()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var gotStats = false;
- client.Achievements.OnUpdated += () => { gotStats = true; };
-
- while ( !gotStats )
- {
- client.Update();
- }
-
- foreach ( var ach in client.Achievements.All )
- {
- ach.Trigger();
- }
- }
- }
-
- }
-}
diff --git a/Facepunch.Steamworks.Test/ClientTest.cs b/Facepunch.Steamworks.Test/ClientTest.cs
deleted file mode 100644
index c83105a..0000000
--- a/Facepunch.Steamworks.Test/ClientTest.cs
+++ /dev/null
@@ -1,169 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.IO;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public partial class Client
- {
- [TestMethod]
- public void Init()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
- }
- }
-
- [TestMethod]
- public void Init_10()
- {
- for ( int i = 0; i < 10; i++ )
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
- }
-
- GC.Collect();
- }
- }
-
- [TestMethod]
- public void Name()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var username = client.Username;
- Console.WriteLine( username );
- Assert.IsNotNull( username );
- }
- }
-
- [TestMethod]
- public void SteamId()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var steamid = client.SteamId;
- Console.WriteLine( steamid );
- Assert.AreNotEqual( 0, steamid );
- }
- }
-
- [TestMethod]
- public void Update()
- {
- var sw = new Stopwatch();
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue(client.IsValid);
-
- for( int i=0; i<1024; i++ )
- {
- sw.Restart();
- client.Update();
- Console.WriteLine( $"{sw.Elapsed.TotalMilliseconds}ms" );
-
- }
- }
- }
-
- [TestMethod]
- public void Subscribed()
- {
- var sw = new Stopwatch();
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- Assert.IsTrue(client.IsSubscribed);
- }
- }
-
- [TestMethod]
- public void Owner()
- {
- var sw = new Stopwatch();
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- Assert.AreEqual(client.OwnerSteamId, client.SteamId);
- }
- }
-
- [TestMethod]
- public void InstallFolder()
- {
- var sw = new Stopwatch();
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- Assert.IsTrue(client.InstallFolder.Exists);
-
- Console.Write($"Install Folder: {client.InstallFolder}");
- }
- }
-
- [TestMethod]
- public void CurrentLanguage()
- {
- var sw = new Stopwatch();
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
- Assert.IsTrue( client.CurrentLanguage != null );
- Assert.IsTrue( client.CurrentLanguage.Length > 0 );
-
- Console.Write( $"CurrentLanguage: {client.CurrentLanguage}" );
- }
- }
-
- [TestMethod]
- public void AvailableLanguages()
- {
- var sw = new Stopwatch();
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
- Assert.IsTrue( client.AvailableLanguages != null );
- Assert.IsTrue( client.AvailableLanguages.Length > 0 );
-
- foreach ( var lang in client.AvailableLanguages )
- {
- Console.Write( $"AvailableLanguages: {lang}" );
- }
-
- }
- }
-
- [TestMethod]
- public void Cybercafe()
- {
- var sw = new Stopwatch();
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- Assert.IsFalse(client.IsCybercafe);
- }
- }
-
- [TestMethod]
- public void LowViolence()
- {
- var sw = new Stopwatch();
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- Assert.IsFalse(client.IsLowViolence);
- }
- }
- }
-}
diff --git a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj
index b02e7d7..821ee0f 100644
--- a/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj
+++ b/Facepunch.Steamworks.Test/Facepunch.Steamworks.Test.csproj
@@ -88,25 +88,15 @@
-
-
-
-
-
-
-
-
-
-
diff --git a/Facepunch.Steamworks.Test/FriendsTest.cs b/Facepunch.Steamworks.Test/FriendsTest.cs
deleted file mode 100644
index 8ea5245..0000000
--- a/Facepunch.Steamworks.Test/FriendsTest.cs
+++ /dev/null
@@ -1,173 +0,0 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Steamworks
-{
- [DeploymentItem( "steam_api64.dll" )]
- [TestClass]
- public class FriendsTest
- {
- [TestMethod]
- public void GetFriends()
- {
- foreach ( var friend in Friends.GetFriends() )
- {
- Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
- Console.WriteLine( $" {string.Join( ", ", friend.NameHistory)}" );
-
- // Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
- }
- }
-
- [TestMethod]
- public void GetBlocked()
- {
- foreach ( var friend in Friends.GetBlocked() )
- {
- Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
- Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
-
- // Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
- }
- }
-
- [TestMethod]
- public void GetPlayedWith()
- {
- foreach ( var friend in Friends.GetPlayedWith() )
- {
- Console.WriteLine( $"{friend.Id.Value}: {friend.Name} (Friend:{friend.IsFriend}) (Blocked:{friend.IsBlocked})" );
- Console.WriteLine( $" {string.Join( ", ", friend.NameHistory )}" );
-
- // Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
- }
- }
-
- [TestMethod]
- public async Task LargeAvatar()
- {
- ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
-
- var image = await Friends.GetLargeAvatarAsync( id );
- if ( !image.HasValue )
- return;
-
- Console.WriteLine( $"image.Width {image.Value.Width}" );
- Console.WriteLine( $"image.Height {image.Value.Height}" );
-
- DrawImage( image.Value );
- }
-
- [TestMethod]
- public async Task MediumAvatar()
- {
- ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
-
- Console.WriteLine( $"Steam: http://steamcommunity.com/profiles/{id}" );
-
- var image = await Friends.GetMediumAvatarAsync( id );
- if ( !image.HasValue )
- return;
-
- Console.WriteLine( $"image.Width {image.Value.Width}" );
- Console.WriteLine( $"image.Height {image.Value.Height}" );
-
- DrawImage( image.Value );
- }
-
- [TestMethod]
- public async Task SmallAvatar()
- {
- ulong id = (ulong)(76561197960279927 + (new Random().Next() % 10000));
-
- var image = await Friends.GetSmallAvatarAsync( id );
- if ( !image.HasValue )
- return;
-
- Console.WriteLine( $"image.Width {image.Value.Width}" );
- Console.WriteLine( $"image.Height {image.Value.Height}" );
-
- DrawImage( image.Value );
- }
-
- [TestMethod]
- public async Task GetFriendsAvatars()
- {
- foreach ( var friend in Friends.GetFriends() )
- {
- Console.WriteLine( $"{friend.Id.Value}: {friend.Name}" );
-
- var image = await friend.GetSmallAvatarAsync();
- if ( image.HasValue )
- {
- DrawImage( image.Value );
- }
-
- // Assert.IsNotNull( friend.GetAvatar( Steamworks.Friends.AvatarSize.Medium ) );
- }
- }
-
- /*
- [TestMethod]
- public void FriendListWithoutRefresh()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- foreach ( var friend in client.Friends.All )
- {
- Console.WriteLine( "{0}: {1} (Friend:{2}) (Blocked:{3})", friend.Id, friend.Name, friend.IsFriend, friend.IsBlocked );
- }
- }
- }
-
-
-
- [TestMethod]
- public void CachedAvatar()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- var friend = client.Friends.All.First();
-
- var image = client.Friends.GetCachedAvatar( Steamworks.Friends.AvatarSize.Medium, friend.Id );
-
- if (image != null)
- {
- Assert.AreEqual(image.Width, 64);
- Assert.AreEqual(image.Height, 64);
- Assert.AreEqual(image.Data.Length, image.Width * image.Height * 4);
- }
- }
- }
- */
- public static void DrawImage( Image img )
- {
- var grad = " -:+#";
-
- for ( int y = 0; y 3 ) c = 3;
- str += grad[c];
-
- }
-
- Console.WriteLine( str );
- }
- }
-
- }
-}
diff --git a/Facepunch.Steamworks.Test/GameServerTest.cs b/Facepunch.Steamworks.Test/GameServerTest.cs
index 8320534..9b507c5 100644
--- a/Facepunch.Steamworks.Test/GameServerTest.cs
+++ b/Facepunch.Steamworks.Test/GameServerTest.cs
@@ -1,7 +1,6 @@
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
-using SteamNative;
namespace Steamworks
{
@@ -41,6 +40,7 @@ namespace Steamworks
[TestMethod]
public async Task BeginAuthSession()
{
+ var stopwatch = System.Diagnostics.Stopwatch.StartNew();
bool finished = false;
AuthSessionResponse response = AuthSessionResponse.AuthTicketInvalidAlreadyUsed;
@@ -83,23 +83,35 @@ namespace Steamworks
// Wait for that to go through steam
//
while ( !finished )
+ {
+ if ( stopwatch.Elapsed.TotalSeconds > 5 )
+ throw new System.Exception( "Took too long waiting for AuthSessionResponse.OK" );
+
await Task.Delay( 10 );
+ }
Assert.AreEqual( response, AuthSessionResponse.OK );
finished = false;
+ stopwatch = System.Diagnostics.Stopwatch.StartNew();
//
// The client is leaving, and now wants to cancel the ticket
//
+ Assert.AreNotEqual( 0, clientTicket.Handle );
clientTicket.Cancel();
//
// We should get another callback
//
while ( !finished )
+ {
+ if ( stopwatch.Elapsed.TotalSeconds > 5 )
+ throw new System.Exception( "Took too long waiting for AuthSessionResponse.AuthTicketCanceled" );
+
await Task.Delay( 10 );
+ }
Assert.AreEqual( response, AuthSessionResponse.AuthTicketCanceled );
diff --git a/Facepunch.Steamworks.Test/InventoryTest.cs b/Facepunch.Steamworks.Test/InventoryTest.cs
deleted file mode 100644
index ebb3c63..0000000
--- a/Facepunch.Steamworks.Test/InventoryTest.cs
+++ /dev/null
@@ -1,295 +0,0 @@
-using System;
-using System.Diagnostics;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
-
-namespace Facepunch.Steamworks.Test
-{
- [DeploymentItem( "steam_api64.dll" )]
- [TestClass]
- public class Inventory
- {
- [TestMethod]
- public void InventoryDefinitions()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsNotNull( client.Inventory.Definitions );
- Assert.AreNotEqual( 0, client.Inventory.Definitions.Length );
-
- foreach ( var i in client.Inventory.Definitions.Where( x => x.PriceCategory != "" ) )
- {
- Console.WriteLine( "{0}: {1} ({2})", i.Id, i.Name, i.Type );
- Console.WriteLine( " itemshortname: {0}", i.GetStringProperty( "itemshortname" ) );
- Console.WriteLine( " workshopdownload: {0}", i.GetStringProperty( "workshopdownload" ) );
- Console.WriteLine( " IconUrl: {0}", i.IconUrl );
- Console.WriteLine( " IconLargeUrl: {0}", i.IconLargeUrl );
- Console.WriteLine( " PriceRaw: {0}", i.PriceCategory );
- Console.WriteLine( " PriceDollars: {0}", i.PriceDollars );
- }
- }
- }
-
- [TestMethod]
- public void InventoryDefinitionExchange()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsNotNull( client.Inventory.Definitions );
- Assert.AreNotEqual( 0, client.Inventory.Definitions.Length );
-
- foreach ( var i in client.Inventory.Definitions )
- {
- if ( i.Recipes == null ) continue;
-
- Console.WriteLine( "Ways To Create " + i.Name );
-
- foreach ( var r in i.Recipes )
- {
- Console.WriteLine( " " + string.Join( ", ", r.Ingredients.Select( x => x.Count + " x " + x.Definition.Name ) ) );
- }
- }
- }
- }
-
- [TestMethod]
- public void InventoryDefinitionIngredients()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsNotNull( client.Inventory.Definitions );
- Assert.AreNotEqual( 0, client.Inventory.Definitions.Length );
-
- foreach ( var i in client.Inventory.Definitions )
- {
- if ( i.IngredientFor == null ) continue;
-
- Console.WriteLine( i.Name + " Can Be Used to Make" );
-
- foreach ( var r in i.IngredientFor )
- {
- Console.WriteLine( " " + r.Result.Name );
- }
- }
- }
- }
-
- [TestMethod]
- public void InventoryItemList()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- bool CallbackCalled = false;
-
- // OnUpdate hsould be called when we receive a list of our items
- client.Inventory.OnUpdate += () => { CallbackCalled = true; };
-
- // tell steam to download the items
- client.Inventory.Refresh();
-
- // Wait for the items
- var timeout = Stopwatch.StartNew();
- while ( client.Inventory.Items == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 1000 );
-
- if ( timeout.Elapsed.TotalSeconds > 10 )
- break;
- }
-
- // make sure callback was called
- Assert.IsTrue( CallbackCalled );
-
- // Make sure items are valid
- foreach ( var item in client.Inventory.Items )
- {
- Assert.IsNotNull( item );
- Assert.IsNotNull( item.Definition );
-
- Console.WriteLine( item.Definition.Name + " - " + item.Id );
- }
- }
- }
-
- [TestMethod]
- public void InventoryItemProperties()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- while ( true )
- {
- client.Update();
-
- if (client.Inventory.Items == null) continue;
-
- foreach (var item in client.Inventory.Items)
- {
- Console.WriteLine($"{item.Id} ({item.Definition.Name})");
-
- foreach (var property in item.Properties)
- {
- Console.WriteLine($" {property.Key} = {property.Value}");
- }
-
- Console.WriteLine("");
- }
-
- return;
- }
- }
- }
-
- [TestMethod]
- public void Deserialize()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsTrue( client.IsValid );
- Assert.IsNotNull(client.Inventory.Definitions);
- Assert.AreNotEqual(0, client.Inventory.Definitions.Length);
-
- client.Inventory.Refresh();
-
- var stopwatch = Stopwatch.StartNew();
-
- //
- // Block until we have the items
- //
- while ( client.Inventory.SerializedItems == null )
- {
- client.Update();
-
- if (stopwatch.Elapsed.Seconds > 10)
- throw new System.Exception("Getting SerializedItems took too long");
- }
-
- Assert.IsNotNull( client.Inventory.SerializedItems );
- Assert.IsTrue( client.Inventory.SerializedItems.Length > 4 );
- /*
- using ( var server = new Facepunch.Steamworks.Server( 252490, new ServerInit( "rust", "Rust" ) ) )
- {
- server.LogOnAnonymous();
- Assert.IsTrue( server.IsValid );
-
- var result = server.Inventory.Deserialize( client.Inventory.SerializedItems );
-
- stopwatch = Stopwatch.StartNew();
-
- while (result.IsPending)
- {
- server.Update();
-
- if (stopwatch.Elapsed.Seconds > 10)
- throw new System.Exception("result took too long");
- }
-
- Assert.IsFalse( result.IsPending );
- Assert.IsNotNull( result.Items );
-
- foreach ( var item in result.Items )
- {
- Console.WriteLine( "Item: {0} ({1})", item.Id, item.DefinitionId );
- Console.WriteLine( "Item: {0} ({1})", item.Id, item.DefinitionId );
- }
- }
- */
- }
- }
-
- [TestMethod]
- public void PurchaseItems()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsNotNull(client.Inventory.Definitions);
- Assert.AreNotEqual(0, client.Inventory.Definitions.Length);
-
- while ( client.Inventory.Currency == null )
- {
- client.Update();
- }
-
- var shoppingList = client.Inventory.DefinitionsWithPrices.Take(2).ToArray();
- bool waitingForCallback = true;
-
- if ( !client.Inventory.StartPurchase(shoppingList, ( order, tran ) =>
- {
- Console.WriteLine($"Order: {order}, Transaction {tran}");
- waitingForCallback = false;
-
- } ) )
- {
- throw new Exception("Couldn't Buy!");
- }
-
- while ( waitingForCallback )
- {
- client.Update();
- }
- }
- }
-
- [TestMethod]
- public void ListPrices()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- while ( client.Inventory.Definitions == null )
- {
- client.Update();
- System.Threading.Thread.Sleep( 10 );
- }
-
- Assert.IsNotNull(client.Inventory.Definitions);
- Assert.AreNotEqual(0, client.Inventory.Definitions.Length);
-
- while (client.Inventory.Currency == null)
- {
- client.Update();
- }
-
- foreach ( var i in client.Inventory.Definitions.Where( x => x.LocalPrice > 0 ) )
- {
- Console.WriteLine( $" {i.Name} - {i.LocalPriceFormatted} ({client.Inventory.Currency})" );
- }
- }
- }
- }
-}
diff --git a/Facepunch.Steamworks.Test/LeaderboardTest.cs b/Facepunch.Steamworks.Test/LeaderboardTest.cs
deleted file mode 100644
index bc298d8..0000000
--- a/Facepunch.Steamworks.Test/LeaderboardTest.cs
+++ /dev/null
@@ -1,276 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Linq;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public class Leaderboard
- {
- [TestMethod]
- public void GetLeaderboard()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
-
- var time = Stopwatch.StartNew();
- while ( !board.IsValid )
- {
- Thread.Sleep( 10 );
- client.Update();
-
- if (time.Elapsed.TotalSeconds > 10 )
- {
- throw new Exception("board.IsValid took too long");
- }
- }
-
- Assert.IsTrue( board.IsValid );
- Assert.IsFalse( board.IsError );
- Assert.IsNotNull( board.Name );
-
- Console.WriteLine( $"Board name is \"{board.Name}\"" );
- Console.WriteLine( $"Board has \"{board.TotalEntries}\" entries" );
-
- board.AddScore( true, 86275309, 7, 8, 9 );
-
- board.FetchScores( Steamworks.Leaderboard.RequestType.Global, 0, 20 );
-
- time = Stopwatch.StartNew();
- while ( board.IsQuerying )
- {
- Thread.Sleep( 10 );
- client.Update();
-
- if (time.Elapsed.TotalSeconds > 10)
- {
- throw new Exception("board.IsQuerying took too long");
- }
- }
-
- Assert.IsFalse( board.IsError );
- Assert.IsNotNull( board.Results );
-
- foreach ( var entry in board.Results )
- {
- Console.WriteLine( $"{entry.GlobalRank}: {entry.SteamId} ({entry.Name}) with {entry.Score}" );
-
- if ( entry.SubScores != null )
- Console.WriteLine( " - " + string.Join( ";", entry.SubScores.Select( x => x.ToString() ).ToArray() ) );
- }
- }
- }
-
- [TestMethod]
- public void GetLeaderboardCallback()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
-
- var time = Stopwatch.StartNew();
- while ( !board.IsValid )
- {
- Thread.Sleep( 10 );
- client.Update();
-
- if (time.Elapsed.TotalSeconds > 10)
- {
- throw new Exception("board.IsValid took too long");
- }
- }
-
- Assert.IsTrue( board.IsValid );
- Assert.IsFalse( board.IsError );
- Assert.IsNotNull( board.Name );
-
- board.AddScore( true, 86275309, 7, 8, 9 );
-
- var done = false;
-
- board.FetchScores( Steamworks.Leaderboard.RequestType.Global, 0, 20, results =>
- {
- foreach ( var entry in results )
- {
- Console.WriteLine( $"{entry.GlobalRank}: {entry.SteamId} ({entry.Name}) with {entry.Score}" );
-
- if ( entry.SubScores != null )
- Console.WriteLine( " - " + string.Join( ";", entry.SubScores.Select( x => x.ToString() ).ToArray() ) );
- }
-
- done = true;
- }, error => Assert.Fail( error.ToString() ) );
-
- while ( !done )
- {
- Thread.Sleep( 10 );
- client.Update();
- }
- }
- }
-
- [TestMethod]
- public void AddScores()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
-
- var time = Stopwatch.StartNew();
- while (!board.IsValid)
- {
- Thread.Sleep(10);
- client.Update();
-
- if (time.Elapsed.TotalSeconds > 10)
- {
- throw new Exception("board.IsValid took too long");
- }
- }
-
- Assert.IsTrue( board.IsValid );
- Assert.IsFalse( board.IsError );
-
- board.AddScore( true, 1234 );
-
- Thread.Sleep( 10 );
- client.Update();
-
- board.AddScore( true, 34566 );
-
- Thread.Sleep( 10 );
- client.Update();
-
- board.AddScore( true, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6 );
-
- Thread.Sleep( 10 );
- client.Update();
-
- board.AddScore( false, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6 );
-
- Thread.Sleep( 10 );
- client.Update();
- }
- }
-
- [TestMethod]
- public void AddScoresCallback()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
-
- var time = Stopwatch.StartNew();
- while (!board.IsValid)
- {
- Thread.Sleep(10);
- client.Update();
-
- if ( board.IsError )
- {
- throw new Exception( "Board is Error" );
- }
-
- if (time.Elapsed.TotalSeconds > 10)
- {
- throw new Exception("board.IsValid took too long");
- }
- }
-
- Assert.IsTrue( board.IsValid );
- Assert.IsFalse( board.IsError );
-
- var done = false;
-
- const int score = 5678;
-
- board.AddScore( false, score, null, result =>
- {
- Assert.IsTrue( result.ScoreChanged );
- Assert.AreEqual( result.Score, score );
-
- done = true;
- }, error => Assert.Fail( error.ToString() ) );
-
- while ( !done )
- {
- Thread.Sleep( 10 );
- client.Update();
- }
- }
- }
-
- [TestMethod]
- public void AddFileAttachment()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var board = client.GetLeaderboard( "TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric );
-
- var time = Stopwatch.StartNew();
- while (!board.IsValid)
- {
- Thread.Sleep(10);
- client.Update();
-
- if (time.Elapsed.TotalSeconds > 10)
- {
- throw new Exception("board.IsValid took too long");
- }
- }
-
- Assert.IsTrue( board.IsValid );
- Assert.IsFalse( board.IsError );
-
- var done = false;
-
- const int score = 5678;
- const string attachment = "Hello world!";
-
- var file = client.RemoteStorage.CreateFile( "score/example.txt" );
- file.WriteAllText( attachment );
-
- Assert.IsTrue( board.AddScore( false, score, null, result =>
- {
- Assert.IsTrue( result.ScoreChanged );
-
- Assert.IsTrue( board.AttachRemoteFile( file, () =>
- {
- done = true;
- }, error => Assert.Fail( error.ToString() ) ) );
- }, error => Assert.Fail( error.ToString() ) ) );
-
- while ( !done )
- {
- Thread.Sleep( 10 );
- client.Update();
- }
-
- done = false;
-
- Assert.IsTrue( board.FetchScores( Steamworks.Leaderboard.RequestType.GlobalAroundUser, 0, 0, entries =>
- {
- Assert.AreEqual( 1, entries.Length );
- Assert.IsNotNull( entries[0].AttachedFile );
-
- Assert.IsTrue( entries[0].AttachedFile.Download( () =>
- {
- Assert.AreEqual( attachment, entries[0].AttachedFile.ReadAllText() );
-
- done = true;
- }, error => Assert.Fail( error.ToString() ) ) );
- }, error => Assert.Fail( error.ToString() ) ) );
-
- while ( !done )
- {
- Thread.Sleep( 10 );
- client.Update();
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Facepunch.Steamworks.Test/LobbyTest.cs b/Facepunch.Steamworks.Test/LobbyTest.cs
deleted file mode 100644
index 340cf4d..0000000
--- a/Facepunch.Steamworks.Test/LobbyTest.cs
+++ /dev/null
@@ -1,389 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using Facepunch.Steamworks;
-using System.Text;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem("steam_api64.dll")]
- public class Lobby
- {
- [TestMethod]
- public void CreateLobby()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- Console.WriteLine($"Owner: {client.Lobby.Owner}");
- Console.WriteLine($"Max Members: {client.Lobby.MaxMembers}");
- Console.WriteLine($"Num Members: {client.Lobby.NumMembers}");
- client.Lobby.Leave();
- };
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 3)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- }
- }
-
- [TestMethod]
- public void GetCreatedLobbyData()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- foreach (KeyValuePair data in client.Lobby.CurrentLobbyData.GetAllData())
- {
- if (data.Key == "appid")
- {
- Assert.IsTrue(data.Value == "252490");
- }
- Console.WriteLine($"{data.Key} {data.Value}");
- }
- client.Lobby.Leave();
- };
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 3)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- }
- }
-
- [TestMethod]
- public void UpdateLobbyData()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
-
- client.Lobby.Name = "My Updated Lobby Name";
- client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
- client.Lobby.LobbyType = Steamworks.Lobby.Type.Private;
- client.Lobby.MaxMembers = 5;
- client.Lobby.Joinable = false;
-
- foreach (KeyValuePair data in client.Lobby.CurrentLobbyData.GetAllData())
- {
- if (data.Key == "appid")
- {
- Assert.IsTrue(data.Value == "252490");
- }
-
- if (data.Key == "testkey")
- {
- Assert.IsTrue(data.Value == "testvalue");
- }
-
- if (data.Key == "lobbytype")
- {
- Assert.IsTrue(data.Value == Steamworks.Lobby.Type.Private.ToString());
- }
-
- Console.WriteLine($"{data.Key} {data.Value}");
- }
-
-
-
- };
-
-
- client.Lobby.OnLobbyDataUpdated = () =>
- {
- Console.WriteLine("lobby data updated");
- Console.WriteLine(client.Lobby.MaxMembers);
- Console.WriteLine(client.Lobby.Joinable);
- };
-
-
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 3)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- client.Lobby.Leave();
-
- }
- }
-
- [TestMethod]
- public void RefreshLobbyList()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- client.LobbyList.Refresh();
- };
-
- client.LobbyList.OnLobbiesUpdated = () =>
- {
- Console.WriteLine("lobbies updating");
- if (client.LobbyList.Finished)
- {
- Console.WriteLine("lobbies finished updating");
- Console.WriteLine($"found {client.LobbyList.Lobbies.Count} lobbies");
-
- foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
- {
- Console.WriteLine($"Found Lobby: {lobby.Name}");
- }
-
- client.Lobby.Leave();
-
- }
-
- };
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 3)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- }
- }
-
- [TestMethod]
- public void RefreshLobbyListWithFilter()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
- };
-
- client.Lobby.OnLobbyDataUpdated = () =>
- {
- var filter = new LobbyList.Filter();
- filter.StringFilters.Add("testkey", "testvalue");
- client.LobbyList.Refresh(filter);
- };
-
- client.LobbyList.OnLobbiesUpdated = () =>
- {
- Console.WriteLine("lobbies updating");
- if (client.LobbyList.Finished)
- {
- Console.WriteLine("lobbies finished updating");
- Console.WriteLine($"found {client.LobbyList.Lobbies.Count} lobbies");
-
- foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
- {
- Console.WriteLine($"Found Lobby: {lobby.Name}");
- }
-
- }
-
- };
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 5)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- client.Lobby.Leave();
-
- }
- }
-
- [TestMethod]
- public void RefreshLobbyListWithFilterAndGetLobbyDataFromListLobby()
- {
- using (var client = new Facepunch.Steamworks.Client(755870))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
- };
-
- client.Lobby.OnLobbyDataUpdated = () =>
- {
- var filter = new LobbyList.Filter();
- filter.StringFilters.Add("testkey", "testvalue");
- client.LobbyList.Refresh(filter);
- };
-
- client.LobbyList.OnLobbiesUpdated = () =>
- {
- Console.WriteLine("lobbies updating");
- if (client.LobbyList.Finished)
- {
- Console.WriteLine("lobbies finished updating");
- Console.WriteLine($"found {client.LobbyList.Lobbies.Count} lobbies");
-
- foreach (LobbyList.Lobby lobby in client.LobbyList.Lobbies)
- {
- foreach (var pair in lobby.GetAllData())
- {
- Console.WriteLine(string.Format("Key: {0,-36} Value: {1}", pair.Key, pair.Value));
- }
- }
- }
- };
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 5)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- client.Lobby.Leave();
-
- }
- }
-
- [TestMethod]
- public void SendChatMessage()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
- string testString = "Hello, World";
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- client.Lobby.CurrentLobbyData.SetData("testkey", "testvalue");
- client.Lobby.SendChatMessage(testString);
- };
-
- client.Lobby.OnChatMessageRecieved = (steamID, bytes, length) =>
- {
- string message = Encoding.UTF8.GetString(bytes, 0, length);
- Console.WriteLine("message recieved");
- Assert.IsTrue(message == testString);
- };
-
- client.Lobby.OnChatStringRecieved = (steamID, message) =>
- {
- Console.WriteLine("message recieved");
- Assert.IsTrue(message == testString);
- };
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 5)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- client.Lobby.Leave();
-
- }
- }
-
- [TestMethod]
- public void SetGetUserMetadata()
- {
- using (var client = new Facepunch.Steamworks.Client(252490))
- {
- Assert.IsTrue(client.IsValid);
-
- client.Lobby.OnLobbyCreated = (success) =>
- {
- Assert.IsTrue(success);
- Assert.IsTrue(client.Lobby.IsValid);
- Console.WriteLine("lobby created: " + client.Lobby.CurrentLobby);
- client.Lobby.SetMemberData("testkey", "testvalue");
- };
-
- client.Lobby.OnLobbyMemberDataUpdated = (steamID) =>
- {
- var friend = new global::Steamworks.Friend( steamID );
- Console.WriteLine( friend.Name + " updated data");
- Assert.IsTrue(client.Lobby.GetMemberData(steamID, "testkey") == "testvalue");
- Console.WriteLine("testkey is now: " + client.Lobby.GetMemberData(steamID, "testkey"));
- };
-
- client.Lobby.Create(Steamworks.Lobby.Type.Public, 10);
-
- var sw = Stopwatch.StartNew();
-
- while (sw.Elapsed.TotalSeconds < 5)
- {
- client.Update();
- System.Threading.Thread.Sleep(10);
- }
-
- client.Lobby.Leave();
-
- }
- }
-
- }
-}
diff --git a/Facepunch.Steamworks.Test/NetworkingTest.cs b/Facepunch.Steamworks.Test/NetworkingTest.cs
deleted file mode 100644
index e4013d0..0000000
--- a/Facepunch.Steamworks.Test/NetworkingTest.cs
+++ /dev/null
@@ -1,114 +0,0 @@
-using System;
-using System.Diagnostics;
-using System.Text;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public partial class Networking
- {
- [TestMethod]
- public void PeerToPeerSend()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var TestString = "This string will be transformed to bytes, sent over the Steam P2P network, then converted back to a string.";
- var OutputReceived = false;
- var data = Encoding.UTF8.GetBytes( TestString );
-
- //
- // Enable listening on this channel
- //
- client.Networking.SetListenChannel( 0, true );
-
- client.Networking.OnP2PData = ( steamid, bytes, length, channel ) =>
- {
- var str = Encoding.UTF8.GetString( bytes, 0, length );
- Assert.AreEqual( str, TestString );
- Assert.AreEqual( steamid, client.SteamId );
- OutputReceived = true;
-
- Console.WriteLine( "Got: " + str );
- };
-
- client.Networking.OnIncomingConnection = ( steamid ) =>
- {
- Console.WriteLine( "Incoming P2P Connection: " + steamid );
- return true;
- };
-
- client.Networking.OnConnectionFailed = ( steamid, error ) =>
- {
- Console.WriteLine( "Connection Error: " + steamid + " - " + error );
- };
-
- client.Networking.SendP2PPacket( client.SteamId, data, data.Length );
-
- while( true )
- {
- Thread.Sleep( 10 );
- client.Update();
-
- if ( OutputReceived )
- break;
- }
- }
- }
-
- [TestMethod]
- public void PeerToPeerFailure()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var TestString = "This string will be transformed to bytes, sent over the Steam P2P network, then converted back to a string.";
- var TimeoutReceived = false;
- var data = Encoding.UTF8.GetBytes( TestString );
-
- client.Networking.OnIncomingConnection = ( steamid ) =>
- {
- Console.WriteLine( "Incoming P2P Connection: " + steamid );
-
- return true;
- };
-
- client.Networking.OnConnectionFailed = ( steamid, error ) =>
- {
- Console.WriteLine( "Connection Error: " + steamid + " - " + error );
- TimeoutReceived = true;
- };
-
- ulong rand = (ulong) new Random().Next( 1024 * 16 );
-
- // Send to an invalid, not listening steamid
- if ( !client.Networking.SendP2PPacket( client.SteamId + rand, data, data.Length ) )
- {
- Console.WriteLine( "Couldn't send packet" );
- return;
- }
-
- var sw = Stopwatch.StartNew();
-
- while ( true )
- {
- Thread.Sleep( 10 );
- client.Update();
-
- //
- // Timout is usually around 15 seconds
- //
- if ( TimeoutReceived )
- break;
-
- if ( sw.Elapsed.TotalSeconds > 30 )
- {
- Assert.Fail( "Didn't time out" );
- }
- }
- }
- }
-
- }
-}
diff --git a/Facepunch.Steamworks.Test/RemoteStorageTest.cs b/Facepunch.Steamworks.Test/RemoteStorageTest.cs
deleted file mode 100644
index 31891d2..0000000
--- a/Facepunch.Steamworks.Test/RemoteStorageTest.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-using System;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public class RemoteStorage
- {
- [TestMethod]
- public void GetQuota()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- ulong total = client.RemoteStorage.QuotaTotal;
- var available = client.RemoteStorage.QuotaRemaining;
-
- Console.WriteLine( $"Total quota: {total} bytes" );
- Console.WriteLine( $"Available: {available} bytes" );
- }
- }
-
- [TestMethod]
- public void WriteFile()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var file = client.RemoteStorage.CreateFile( "test.txt" );
-
- const string text = "Hello world!";
-
- file.WriteAllText( text );
-
- Assert.IsTrue( file.Exists );
-
- var read = file.ReadAllText();
- Assert.AreEqual( text, read );
- }
- }
-
- [TestMethod]
- public void ReadText()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var text = client.RemoteStorage.ReadString( "test.txt" );
-
- Assert.IsNotNull( text );
- Assert.AreEqual( text, "Hello world!" );
- }
- }
-
- [TestMethod]
- public void WriteText()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- var result = client.RemoteStorage.WriteString( "test.txt", "Hello world!" );
- Assert.IsTrue( result );
- }
- }
-
- [TestMethod]
- public void WriteFiles()
- {
- using ( var client = new Steamworks.Client( 252490 ) )
- {
- for ( var i = 0; i < 10; ++i )
- {
- client.RemoteStorage
- .CreateFile( $"test_{i}/example.txt" )
- .WriteAllText( Guid.NewGuid().ToString() );
- }
-
- Console.WriteLine( $"File count: {client.RemoteStorage.FileCount}" );
-
- foreach ( var file in client.RemoteStorage.Files )
- {
- DateTime t = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(file.FileTimestamp);
- Console.WriteLine( $"- {file.FileName} ({file.SizeInBytes} bytes), modified {t:O}" );
- }
- }
- }
- }
-}
diff --git a/Facepunch.Steamworks.Test/ServerlistTest.cs b/Facepunch.Steamworks.Test/ServerlistTest.cs
index 1de984e..a6a1f97 100644
--- a/Facepunch.Steamworks.Test/ServerlistTest.cs
+++ b/Facepunch.Steamworks.Test/ServerlistTest.cs
@@ -19,9 +19,9 @@ namespace Steamworks
var ipstr = "185.38.150.40";
var ip = IPAddress.Parse( ipstr );
- var ip_int = Facepunch.Steamworks.Utility.IpToInt32( ip );
+ var ip_int = Utility.IpToInt32( ip );
- var ip_back = Facepunch.Steamworks.Utility.Int32ToIp( ip_int );
+ var ip_back = Utility.Int32ToIp( ip_int );
Console.WriteLine( "ipstr: " + ipstr );
Console.WriteLine( "ip: " + ip );
diff --git a/Facepunch.Steamworks.Test/StatsTest.cs b/Facepunch.Steamworks.Test/StatsTest.cs
deleted file mode 100644
index 7919f40..0000000
--- a/Facepunch.Steamworks.Test/StatsTest.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-using System;
-using System.Text;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public class Stats
- {
- [TestMethod]
- public void UpdateStats()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- client.Stats.UpdateStats();
- }
- }
-
- [TestMethod]
- public void UpdateSUpdateGlobalStatstats()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- client.Stats.UpdateGlobalStats( 1 );
- client.Stats.UpdateGlobalStats( 3 );
- client.Stats.UpdateGlobalStats( 7 );
- }
- }
-
- [TestMethod]
- public void GetClientFloat()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var v = client.Stats.GetFloat( "deaths" );
- Console.WriteLine( v );
- }
- }
-
- [TestMethod]
- public void GetClientInt()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var v = client.Stats.GetInt( "deaths" );
- Console.WriteLine( v );
- }
- }
-
- [TestMethod]
- public void GetGlobalFloat()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var v = client.Stats.GetGlobalFloat( "deaths" );
- Console.WriteLine( v );
- }
- }
-
- [TestMethod]
- public void GetGlobalInt()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- var v = client.Stats.GetGlobalInt( "deaths" );
- Console.WriteLine( v );
- }
- }
- }
-}
diff --git a/Facepunch.Steamworks.Test/UserTest.cs b/Facepunch.Steamworks.Test/UserTest.cs
index 64f2fdd..eebac6d 100644
--- a/Facepunch.Steamworks.Test/UserTest.cs
+++ b/Facepunch.Steamworks.Test/UserTest.cs
@@ -69,7 +69,7 @@ namespace Steamworks
var result = User.BeginAuthSession( ticket.Data, User.SteamId );
Console.WriteLine( $"result: { result }" );
- Assert.AreEqual( result, SteamNative.BeginAuthSessionResult.OK );
+ Assert.AreEqual( result, BeginAuthSessionResult.OK );
User.EndAuthSession( User.SteamId );
}
diff --git a/Facepunch.Steamworks.Test/WorkshopTest.cs b/Facepunch.Steamworks.Test/WorkshopTest.cs
deleted file mode 100644
index c3ca33a..0000000
--- a/Facepunch.Steamworks.Test/WorkshopTest.cs
+++ /dev/null
@@ -1,541 +0,0 @@
-using System;
-using System.Text;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using System.Linq;
-using System.Diagnostics;
-using Facepunch.Steamworks.Callbacks;
-
-namespace Facepunch.Steamworks.Test
-{
- [TestClass]
- [DeploymentItem( "steam_api64.dll" )]
- public class WorkshopTest
- {
- [TestMethod]
- public void Query()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var Query = client.Workshop.CreateQuery();
- Query.Order = Workshop.Order.RankedByTrend;
-
- Query.Run();
-
- // Block, wait for result
- // (don't do this in realtime)
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- // results
-
- Console.WriteLine( "Searching" );
-
- Query.Order = Workshop.Order.RankedByTextSearch;
- Query.QueryType = Workshop.QueryType.MicrotransactionItems;
- Query.SearchText = "black";
- Query.RequireTags.Add( "LongTShirt Skin" );
- Query.Run();
-
- // Block, wait for result
- // (don't do this in realtime)
- Query.Block();
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Console.WriteLine( "\t WebsiteViews: {0}", item.WebsiteViews );
- Console.WriteLine( "\t VotesUp: {0}", item.VotesUp );
- Console.WriteLine( "\t PreviewUrl: {0}", item.PreviewImageUrl );
-
- Assert.IsTrue( item.PreviewImageUrl.Contains( "http" ) );
- }
- }
- }
-
- [TestMethod]
- public void QueryMyFiles()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var Query = client.Workshop.CreateQuery();
-
- Query.UserId = client.SteamId;
- Query.UserQueryType = Workshop.UserQueryType.Published;
-
- Query.Run();
-
- // Block, wait for result
- // (don't do this in realtime)
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Console.WriteLine( "\t WebsiteViews: {0}", item.WebsiteViews );
- Console.WriteLine( "\t VotesUp: {0}", item.VotesUp );
- Console.WriteLine( "\t PreviewUrl: {0}", item.PreviewImageUrl );
- Console.WriteLine( "\t Directory: {0}", item.Directory );
-
- Assert.IsTrue( item.PreviewImageUrl.Contains( "http" ) );
- }
- }
- }
-
- [TestMethod]
- public void QueryTagRequire()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.RequireTags.Add( "LongTShirt Skin" );
- Query.Run();
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Console.WriteLine( "\t{0}", string.Join( ";", item.Tags ) );
-
- Assert.IsTrue( item.Tags.Contains( "longtshirt skin" ) );
- }
- }
- }
- }
-
- [TestMethod]
- public void QueryTagRequireMultiple()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.RequireTags.Add( "LongTShirt Skin" );
- Query.RequireTags.Add( "version2" );
- Query.RequireAllTags = true;
- Query.Run();
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Console.WriteLine( "\t{0}", string.Join( ";", item.Tags ) );
-
- Assert.IsTrue( item.Tags.Contains( "longtshirt skin" ) );
- Assert.IsTrue( item.Tags.Contains( "version2" ) );
- }
- }
- }
- }
-
- [TestMethod]
- public void QueryTagExclude()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.RequireTags.Add( "LongTShirt Skin" );
- Query.ExcludeTags.Add( "version2" );
- Query.Run();
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Console.WriteLine( "\t{0}", string.Join( ";", item.Tags ) );
-
- Assert.IsTrue( item.Tags.Contains( "longtshirt skin" ) );
- Assert.IsFalse( item.Tags.Contains( "version2" ) );
- }
- }
- }
- }
-
- [TestMethod]
- public void QueryFile()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.FileId.Add( 751993251 );
- Query.Run();
-
- Assert.IsTrue( Query.IsRunning );
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.AreEqual( Query.TotalResults, 1 );
- Assert.AreEqual( Query.Items.Length, 1 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.AreEqual( Query.Items[0].Id, 751993251 );
- }
- }
- }
-
- [TestMethod]
- public void QueryCallback()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- var gotCallback = false;
-
- Query.OnResult = ( q ) =>
- {
- Assert.AreEqual( q.Items.Length, 1 );
- Console.WriteLine( "Query.TotalResults: {0}", q.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", q.Items.Length );
-
- gotCallback = true;
- };
-
- Query.FileId.Add( 751993251 );
- Query.Run();
-
- Assert.IsTrue( Query.IsRunning );
-
- client.UpdateWhile( () => gotCallback == false );
-
- Assert.IsFalse( Query.IsRunning );
- Assert.AreEqual( Query.TotalResults, 1 );
-
- Assert.AreEqual( Query.Items[0].Id, 751993251 );
- }
- }
- }
-
- [TestMethod]
- public void QueryFiles()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.FileId.Add( 751993251 );
- Query.FileId.Add( 747266909 );
- Query.Run();
-
- Assert.IsTrue( Query.IsRunning );
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.AreEqual( Query.TotalResults, 2 );
- Assert.AreEqual( Query.Items.Length, 2 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- Assert.IsTrue( Query.Items.Any( x => x.Id == 751993251 ) );
- Assert.IsTrue( Query.Items.Any( x => x.Id == 747266909 ) );
- }
- }
- }
-
- [TestMethod]
- public void Query_255()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.PerPage = 255;
- Query.Run();
-
- Assert.IsTrue( Query.IsRunning );
-
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.AreEqual( Query.Items.Length, 255 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
- }
- }
- }
-
- [TestMethod]
- public void Query_28()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.PerPage = 28;
- Query.Run();
- Query.Block();
-
- var firstPage = Query.Items;
- Assert.AreEqual( firstPage.Length, 28 );
-
- Console.WriteLine( "Page 2" );
- Query.Page++;
- Query.Run();
- Query.Block();
-
-
- var secondPage = Query.Items;
- Assert.AreEqual( secondPage.Length, 28 );
-
- Console.WriteLine( "Page 3" );
- Query.Page++;
- Query.Run();
- Query.Block();
-
- var thirdPage = Query.Items;
- Assert.AreEqual( thirdPage.Length, 28 );
-
- foreach ( var i in firstPage )
- {
- Assert.IsFalse( secondPage.Any( x => x.Id == i.Id ) );
- Assert.IsFalse( thirdPage.Any( x => x.Id == i.Id ) );
- }
-
- foreach ( var i in secondPage )
- {
- Assert.IsFalse( firstPage.Any( x => x.Id == i.Id ) );
- Assert.IsFalse( thirdPage.Any( x => x.Id == i.Id ) );
- }
-
- foreach ( var i in thirdPage )
- {
- Assert.IsFalse( secondPage.Any( x => x.Id == i.Id ) );
- Assert.IsFalse( firstPage.Any( x => x.Id == i.Id ) );
- }
- }
- }
- }
-
- [TestMethod]
- public void DownloadFile()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var item = client.Workshop.GetItem( 844466101 );
-
- var time = Stopwatch.StartNew();
- if ( !item.Installed )
- {
- item.Download();
-
- while ( !item.Installed )
- {
- Thread.Sleep( 500 );
- client.Update();
- Console.WriteLine( "Download Progress: {0}", item.DownloadProgress );
-
- if (time.Elapsed.Seconds > 30)
- throw new Exception("item.Installed Took Too Long");
- }
- }
-
- Assert.IsNotNull( item.Directory );
- Assert.AreNotEqual( 0, item.Size );
-
- Console.WriteLine( "item.Installed: {0}", item.Installed );
- Console.WriteLine( "item.Downloading: {0}", item.Downloading );
- Console.WriteLine( "item.DownloadPending: {0}", item.DownloadPending );
- Console.WriteLine( "item.Directory: {0}", item.Directory );
- Console.WriteLine( "item.Size: {0}mb", (item.Size / 1024 / 1024) );
- }
- }
-
- [TestMethod]
- [TestCategory( "Run Manually" )]
- public void CreatePublish()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var item = client.Workshop.CreateItem( Workshop.ItemType.Microtransaction );
-
- item.Title = "Facepunch.Steamworks Unit test";
- item.Tags.Add( "Apple" );
- item.Tags.Add( "Banana" );
-
- // Make a folder
- var testFolder = new System.IO.DirectoryInfo("BlahBlah");
- if (!testFolder.Exists) testFolder.Create();
-
- item.Folder = testFolder.FullName;
-
- // Upload a file of random bytes
- var rand = new Random();
- var testFile = new byte[1024 * 1024 * 32];
- rand.NextBytes(testFile);
- System.IO.File.WriteAllBytes( testFolder.FullName + "/testfile1.bin", testFile);
-
-
- Console.WriteLine(item.Folder);
-
- item.OnChangesSubmitted += result =>
- {
- Console.WriteLine( "OnChangesSubmitted called: " + result );
- Assert.AreEqual( Result.OK, result );
- };
-
- try
- {
- item.Publish();
-
- while ( item.Publishing )
- {
- client.Update();
- Thread.Sleep( 10 );
-
- Console.WriteLine("Progress: " + item.Progress);
- Console.WriteLine("BytesUploaded: " + item.BytesUploaded);
- Console.WriteLine("BytesTotal: " + item.BytesTotal);
- }
-
- Assert.IsFalse( item.Publishing );
- Assert.AreNotEqual( 0, item.Id );
- Assert.IsNull( item.Error, item.Error );
-
- Console.WriteLine( "item.Id: {0}", item.Id );
-
- using ( var Query = client.Workshop.CreateQuery() )
- {
- Query.FileId.Add( item.Id );
- Query.Run();
-
- Query.Block();
-
- var itemInfo = Query.Items[0];
-
- Assert.AreEqual( itemInfo.Id, item.Id );
- Assert.AreEqual( itemInfo.OwnerId, client.SteamId );
- Assert.AreEqual( itemInfo.Title, item.Title );
- Assert.IsTrue( itemInfo.Tags.Contains( "apple" ), "Missing Tag" );
- Assert.IsTrue( itemInfo.Tags.Contains( "banana" ), "Missing Tag" );
- }
- }
- finally
- {
- Console.WriteLine( "Deleting: {0}", item.Id );
- item.Delete();
-
- System.IO.File.Delete(testFolder.FullName + "/testfile.bin");
- }
- }
- }
-
- [TestMethod]
- public void UserQuery()
- {
- using ( var client = new Facepunch.Steamworks.Client( 252490 ) )
- {
- Assert.IsTrue( client.IsValid );
-
- var Query = client.Workshop.CreateQuery();
-
- Query.UserId = 76561197960279927;
- Query.UserQueryType = Workshop.UserQueryType.Published;
-
- Query.Run();
-
- // Block, wait for result
- // (don't do this in realtime)
- Query.Block();
-
- Assert.IsFalse( Query.IsRunning );
- Assert.IsTrue( Query.TotalResults > 0 );
- Assert.IsTrue( Query.Items.Length > 0 );
-
- Console.WriteLine( "Query.TotalResults: {0}", Query.TotalResults );
- Console.WriteLine( "Query.Items.Length: {0}", Query.Items.Length );
-
- foreach ( var item in Query.Items )
- {
- Console.WriteLine( "{0}", item.Title );
- Assert.AreEqual( item.OwnerId, 76561197960279927 );
- }
- }
- }
-
- }
-}
diff --git a/Facepunch.Steamworks/Redux/Apps.cs b/Facepunch.Steamworks/Apps.cs
similarity index 94%
rename from Facepunch.Steamworks/Redux/Apps.cs
rename to Facepunch.Steamworks/Apps.cs
index 7c956c6..6e01eed 100644
--- a/Facepunch.Steamworks/Redux/Apps.cs
+++ b/Facepunch.Steamworks/Apps.cs
@@ -1,5 +1,4 @@
-using SteamNative;
-using System;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@@ -95,7 +94,7 @@ namespace Steamworks
///
/// Returns the time of the purchase of the app
///
- public static DateTime PurchaseTime( AppId appid ) => Facepunch.Steamworks.Utility.Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );
+ public static DateTime PurchaseTime( AppId appid ) => Utility.Epoch.ToDateTime( Internal.GetEarliestPurchaseUnixTime( appid.Value ) );
///
/// Checks if the user is subscribed to the current app through a free weekend
@@ -109,12 +108,12 @@ namespace Steamworks
///
public static IEnumerable DlcInformation()
{
- var appid = default( SteamNative.AppId_t );
+ var appid = default( AppId_t );
var available = false;
for ( int i = 0; i < Internal.GetDLCCount(); i++ )
{
- var sb = SteamNative.Helpers.TakeStringBuilder();
+ var sb = Helpers.TakeStringBuilder();
if ( !Internal.BGetDLCDataByIndex( i, ref appid, ref available, sb, sb.Capacity ) )
continue;
@@ -145,7 +144,7 @@ namespace Steamworks
{
get
{
- var sb = SteamNative.Helpers.TakeStringBuilder();
+ var sb = Helpers.TakeStringBuilder();
if ( !Internal.GetCurrentBetaName( sb, sb.Capacity ) )
return null;
@@ -167,7 +166,7 @@ namespace Steamworks
///
public static IEnumerable InstalledDepots( AppId appid )
{
- var depots = new SteamNative.DepotId_t[32];
+ var depots = new DepotId_t[32];
uint count = 0;
count = Internal.GetInstalledDepots( appid.Value, depots, (uint) depots.Length );
@@ -184,7 +183,7 @@ namespace Steamworks
///
public static string AppInstallDir( AppId appid )
{
- var sb = SteamNative.Helpers.TakeStringBuilder();
+ var sb = Helpers.TakeStringBuilder();
if ( Internal.GetAppInstallDir( appid.Value, sb, (uint) sb.Capacity ) == 0 )
return null;
@@ -246,7 +245,7 @@ namespace Steamworks
return new FileDetails
{
- Found = r.Value.Result == SteamNative.Result.OK,
+ Found = r.Value.Result == Result.OK,
SizeInBytes = r.Value.FileSize,
Flags = r.Value.Flags,
Sha1 = string.Join( "", r.Value.FileSHA.Select( x => x.ToString( "x" ) ) )
@@ -265,7 +264,7 @@ namespace Steamworks
{
get
{
- var sb = SteamNative.Helpers.TakeStringBuilder();
+ var sb = Helpers.TakeStringBuilder();
var len = Internal.GetLaunchCommandLine( sb, sb.Capacity );
return sb.ToString();
}
diff --git a/Facepunch.Steamworks/BaseSteamworks.cs b/Facepunch.Steamworks/BaseSteamworks.cs
deleted file mode 100644
index 6c6e719..0000000
--- a/Facepunch.Steamworks/BaseSteamworks.cs
+++ /dev/null
@@ -1,215 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Facepunch.Steamworks.Interop;
-
-namespace Facepunch.Steamworks
-{
- ///
- /// Implements shared functionality between Steamworks.Client and Steamworks.Server
- ///
- public class BaseSteamworks : IDisposable
- {
- ///
- /// Current running program's AppId
- ///
- public uint AppId { get; internal set; }
-
- public Networking Networking { get; internal set; }
- public Inventory Inventory { get; internal set; }
- public Workshop Workshop { get; internal set; }
-
- internal event Action OnUpdate;
-
- internal Interop.NativeInterface native;
-
- private List CallbackHandles = new List();
- private List CallResults = new List();
- protected bool disposed = false;
-
-
- protected BaseSteamworks( uint appId )
- {
- if ( IntPtr.Size == 4 )
- throw new System.Exception( "Sorry - 32bit processes aren't supported. It's 2019 or later, come on!" );
-
- AppId = appId;
-
- //
- // No need for the "steam_appid.txt" file any more
- //
- System.Environment.SetEnvironmentVariable("SteamAppId", AppId.ToString());
- System.Environment.SetEnvironmentVariable("SteamGameId", AppId.ToString());
- }
-
- ~BaseSteamworks()
- {
- Dispose();
- }
-
- public virtual void Dispose()
- {
- if ( disposed ) return;
-
- Callbacks.Clear();
-
- foreach ( var h in CallbackHandles )
- {
- h.Dispose();
- }
- CallbackHandles.Clear();
-
- foreach ( var h in CallResults )
- {
- h.Dispose();
- }
- CallResults.Clear();
-
- if ( Workshop != null )
- {
- Workshop.Dispose();
- Workshop = null;
- }
-
- if ( Inventory != null )
- {
- Inventory.Dispose();
- Inventory = null;
- }
-
- if ( Networking != null )
- {
- Networking.Dispose();
- Networking = null;
- }
-
- if ( native != null )
- {
- native.Dispose();
- native = null;
- }
-
- System.Environment.SetEnvironmentVariable("SteamAppId", null );
- System.Environment.SetEnvironmentVariable("SteamGameId", null );
- disposed = true;
- }
-
- protected void SetupCommonInterfaces()
- {
- Networking = new Steamworks.Networking( this, native.networking );
- Inventory = new Steamworks.Inventory( this, native.inventory, IsGameServer );
- Workshop = new Steamworks.Workshop( this, native.ugc, native.remoteStorage );
- }
-
- ///
- /// Returns true if this instance has initialized properly.
- /// If this returns false you should Dispose and throw an error.
- ///
- public bool IsValid
- {
- get { return native != null; }
- }
-
-
- internal virtual bool IsGameServer { get { return false; } }
-
- internal void RegisterCallbackHandle( SteamNative.CallbackHandle handle )
- {
- CallbackHandles.Add( handle );
- }
-
- internal void RegisterCallResult( SteamNative.CallResult handle )
- {
- CallResults.Add( handle );
- }
-
- internal void UnregisterCallResult( SteamNative.CallResult handle )
- {
- CallResults.Remove( handle );
- }
-
- public virtual void Update()
- {
- Networking.Update();
-
- RunUpdateCallbacks();
- }
-
- ///
- /// This gets called automatically in Update. Only call it manually if you know why you're doing it.
- ///
- public void RunUpdateCallbacks()
- {
- if ( OnUpdate != null )
- OnUpdate();
-
- for( int i=0; i < CallResults.Count; i++ )
- {
- CallResults[i].Try();
- }
- }
-
- ///
- /// Run Update until func returns false.
- /// This will cause your program to lock up until it finishes.
- /// This is useful for things like tests or command line utilities etc.
- ///
- public void UpdateWhile( Func func )
- {
- const int sleepMs = 1;
-
- while ( func() )
- {
- Update();
-#if NET_CORE
- System.Threading.Tasks.Task.Delay( sleepMs ).Wait();
-#else
- System.Threading.Thread.Sleep( sleepMs );
-#endif
- }
- }
-
- ///
- /// Debug function, called for every callback. Only really used to confirm that callbacks are working properly.
- ///
- public Action