public void AddScoresCallback()
        {
            using (var client = new Steamworks.Client(252490))
            {
                var board = client.GetLeaderboard("TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric);

                while (!board.IsValid)
                {
                    Thread.Sleep(10);
                    client.Update();
                }

                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();
                }
            }
        }
Esempio n. 2
0
 public void MissingKeyIsNull()
 {
     using (var client = new Steamworks.Client(252490))
     {
         var key = client.User.GetRichPresence("Missing Key");
         Assert.IsNull(key);
     }
 }
Esempio n. 3
0
 public void WriteText()
 {
     using (var client = new Steamworks.Client(252490))
     {
         var result = client.RemoteStorage.WriteString("test.txt", "Hello world!");
         Assert.IsTrue(result);
     }
 }
Esempio n. 4
0
        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!");
            }
        }
        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()));
                    }
                }
            }
        }
Esempio n. 6
0
        public void ReadBackSetKey()
        {
            using (var client = new Steamworks.Client(252490))
            {
                client.User.SetRichPresence("One", "Two");

                var value = client.User.GetRichPresence("One");
                Assert.IsNotNull(value);
                Assert.AreEqual(value, "Two");
            }
        }
Esempio n. 7
0
        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");
            }
        }
Esempio n. 8
0
        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);
            }
        }
Esempio n. 9
0
        public void ClearingKeys()
        {
            using (var client = new Steamworks.Client(252490))
            {
                var success = client.User.SetRichPresence("One", "Two");
                Assert.IsTrue(success);

                var value = client.User.GetRichPresence("One");
                Assert.IsNotNull(value);
                Assert.AreEqual(value, "Two");

                client.User.ClearRichPresence();

                value = client.User.GetRichPresence("One");
                Assert.IsNull(value);
            }
        }
Esempio n. 10
0
        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();
                }
            }
        }
Esempio n. 11
0
        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)
                {
                    Console.WriteLine($"- {file.FileName} ({file.SizeInBytes} bytes)");
                }
            }
        }
        public void GetLeaderboardCallback()
        {
            using (var client = new Steamworks.Client(252490))
            {
                var board = client.GetLeaderboard("TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric);

                while (!board.IsValid)
                {
                    Thread.Sleep(10);
                    client.Update();
                }

                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();
                }
            }
        }
Esempio n. 13
0
        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();
            }
        }
        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}");
                }
            }
        }
        public void AddScores()
        {
            using (var client = new Steamworks.Client(252490))
            {
                var board = client.GetLeaderboard("TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric);

                while (!board.IsValid)
                {
                    Thread.Sleep(10);
                    client.Update();
                }

                Assert.IsTrue(board.IsValid);
                Assert.IsFalse(board.IsError);


                board.AddScore(true, false, 1234);

                Thread.Sleep(10);
                client.Update();

                board.AddScore(true, true, 34566);

                Thread.Sleep(10);
                client.Update();

                board.AddScore(true, false, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6);

                Thread.Sleep(10);
                client.Update();

                board.AddScore(false, true, 86275309, 7, 8, 9, 7, 4, 7, 98, 24, 5, 76, 124, 6);

                Thread.Sleep(10);
                client.Update();
            }
        }
        public void AddFileAttachment()
        {
            using (var client = new Steamworks.Client(252490))
            {
                var board = client.GetLeaderboard("TestLeaderboard", Steamworks.Client.LeaderboardSortMethod.Ascending, Steamworks.Client.LeaderboardDisplayType.Numeric);

                while (!board.IsValid)
                {
                    Thread.Sleep(10);
                    client.Update();
                }

                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();
                }
            }
        }