コード例 #1
0
        public void DownloadFile()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);

                var item = client.Workshop.GetItem(787387588);

                if (!item.Installed)
                {
                    item.Download();

                    while (item.Downloading)
                    {
                        Thread.Sleep(500);
                        client.Update();
                        Console.WriteLine("Download Progress: {0}", item.DownloadProgress);
                    }
                }

                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));
            }
        }
コード例 #2
0
ファイル: Stats.cs プロジェクト: zook111/Facepunch.Steamworks
 public void UpdateStats()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         client.Stats.UpdateStats();
     }
 }
コード例 #3
0
        public void HistoryList()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                var query = client.ServerList.History();

                while (true)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(2);

                    if (query.Finished)
                    {
                        break;
                    }
                }

                Console.WriteLine("Responded: " + query.Responded.Count.ToString());
                Console.WriteLine("Unresponsive: " + query.Unresponsive.Count.ToString());

                foreach (var x in query.Responded)
                {
                    Console.WriteLine(x.Map);
                }

                query.Dispose();

                for (int i = 0; i < 100; i++)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(1);
                }
            }
        }
コード例 #4
0
        public void Filters()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                var filter = new Facepunch.Steamworks.ServerList.Filter();
                filter.Add("map", "barren");


                var query = client.ServerList.Internet(filter);

                while (true)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(2);

                    if (query.Finished)
                    {
                        break;
                    }
                }

                foreach (var x in query.Responded)
                {
                    Assert.AreEqual(x.Map.ToLower(), "barren");
                }

                query.Dispose();

                for (int i = 0; i < 100; i++)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(1);
                }
            }
        }
コード例 #5
0
        public void UnCompressedOnly()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                int unCompressed = 0;

                client.Voice.OnUncompressedData = (ptr, length) =>
                {
                    unCompressed += length;
                };

                client.Voice.WantsRecording = true;

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                Assert.AreNotEqual(unCompressed, 0);

                // Should really be > 0 if the mic was getting audio
                Console.WriteLine("unCompressed: {0}", unCompressed);
            }
        }
コード例 #6
0
        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));
                }
            }
        }
コード例 #7
0
        public RichPresence BuildLobbyPresence(ulong lobbyID, Facepunch.Steamworks.Client client)
        {
            RichPresence presence = new RichPresence()
            {
                State   = "In Lobby",
                Details = "Preparing",
                Assets  = new DiscordRPC.Assets()
                {
                    LargeImageKey  = "lobby",
                    LargeImageText = "Join!",
                },
                Party = new Party()
                {
                    ID   = client.Username,
                    Max  = client.Lobby.MaxMembers,
                    Size = client.Lobby.NumMembers
                }
            };

            if (currentPrivacyLevel == PrivacyLevel.Join)
            {
                presence.Secrets = new Secrets()
                {
                    JoinSecret = lobbyID.ToString()
                };
            }

            return(presence);
        }
コード例 #8
0
 public void Init()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         Assert.IsTrue(client.IsValid);
     }
 }
コード例 #9
0
        public void CompressedOnly()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                int compressed = 0;

                client.Voice.OnCompressedData = (buffer, length) =>
                {
                    compressed += length;
                };

                client.Voice.WantsRecording = true;

                var sw = Stopwatch.StartNew();

                while (sw.Elapsed.TotalSeconds < 3)
                {
                    client.Update();
                    System.Threading.Thread.Sleep(10);
                }

                Assert.AreNotEqual(compressed, 0);
                Console.WriteLine("compressed: {0}", compressed);
            }
        }
コード例 #10
0
        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("");
                }
            }
        }
コード例 #11
0
        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);
                    }
                }
            }
        }
コード例 #12
0
        private void Awake()
        {
            Instance = this;

            // keep us around until the game closes
            DontDestroyOnLoad(gameObject);

            if (AppId == 0)
            {
                throw new System.Exception("You need to set the AppId to your game");
            }

            //
            // Configure us for this unity platform
            //
            Facepunch.Steamworks.Config.ForUnity(Application.platform.ToString());

            // Create the client
            Client = new Facepunch.Steamworks.Client(AppId);

            if (!Client.IsValid)
            {
                Client = null;
                return;
            }

            Debug.Log("Steam Initialized: " + Client.Username + " / " + Client.SteamId);
        }
コード例 #13
0
        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)));
                    }
                }
            }
        }
コード例 #14
0
        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;
                }
            }
        }
コード例 #15
0
        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);
                }
            }
        }
コード例 #16
0
        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"));
                    }
                }
            }
        }
コード例 #17
0
        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 <ulong>(item.OwnerId, 76561197960279927);
                }
            }
        }
コード例 #18
0
 public void AppName()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         var name = client.App.GetName(4000);
         Console.WriteLine(name);
     }
 }
コード例 #19
0
 public void VoiceOptimalSampleRate()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         var rate = client.Voice.OptimalSampleRate;
         Assert.AreNotEqual(rate, 0);
     }
 }
コード例 #20
0
 public void GetGlobalInt()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         var v = client.Stats.GetGlobalInt("deaths");
         Console.WriteLine(v);
     }
 }
コード例 #21
0
        public void Deserialize()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                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);
                    }
                }
            }
        }
コード例 #22
0
 public void UpdateSUpdateGlobalStatstats()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         client.Stats.UpdateGlobalStats(1);
         client.Stats.UpdateGlobalStats(3);
         client.Stats.UpdateGlobalStats(7);
     }
 }
コード例 #23
0
        public void Subscribed()
        {
            var sw = new Stopwatch();

            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);
                Assert.IsTrue(client.IsSubscribed);
            }
        }
コード例 #24
0
        public void LowViolence()
        {
            var sw = new Stopwatch();

            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Assert.IsTrue(client.IsValid);
                Assert.IsFalse(client.IsLowViolence);
            }
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
0
 public void Update()
 {
     using (var client = new Facepunch.Steamworks.Client(252490))
     {
         for (int i = 0; i < 1024; i++)
         {
             client.Update();
         }
     }
 }
コード例 #27
0
ファイル: App.cs プロジェクト: zaura777/Facepunch.Steamworks
        public void IsInstalled()
        {
            using (var client = new Facepunch.Steamworks.Client(252490))
            {
                Console.WriteLine("This test assumes you have Garry's Mod installed but not Charles III of Spain and the antiquity");

                Assert.IsTrue(client.App.IsInstalled(4000));
                Assert.IsFalse(client.App.IsInstalled(590440));
            }
        }
コード例 #28
0
        private void OnDestroy()
        {
            if (Client != null)
            {
                Client.Dispose();
                Client = null;
            }

            Destroy(gameObject);
        }
コード例 #29
0
        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);
            }
        }
コード例 #30
0
        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);
            }
        }