public void StatsGet() { using (var server = new Facepunch.Steamworks.Server(252490, 0, 30003, 30004, 30005, true, "VersionString")) { Assert.IsTrue(server.IsValid); server.LogOnAnonymous(); ulong MySteamId = 76561197960279927; bool GotStats = false; server.Stats.Refresh(MySteamId, success => { GotStats = true; Assert.IsTrue(success); var deathsInCallback = server.Stats.GetInt(MySteamId, "deaths", -1); Console.WriteLine("deathsInCallback: {0}", deathsInCallback); Assert.IsTrue(deathsInCallback > 0); }); server.UpdateWhile(() => !GotStats); var deaths = server.Stats.GetInt(MySteamId, "deaths", -1); Console.WriteLine("deathsInCallback: {0}", deaths); Assert.IsTrue(deaths > 0); } }
public void PublicIp() { using (var server = new Facepunch.Steamworks.Server(252490, 0, 30003, 30004, 30005, false, "VersionString")) { server.LogOnAnonymous(); Assert.IsTrue(server.IsValid); while (true) { var ip = server.PublicIp; if (ip == null) { System.Threading.Thread.Sleep(100); server.Update(); continue; } Assert.IsNotNull(ip); Console.WriteLine(ip.ToString()); break; } } }
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); } } } }
public void Init() { var serverInit = new ServerInit("rust", "Rust"); serverInit.GamePort = 28015; serverInit.Secure = true; serverInit.QueryPort = 28016; using (var server = new Facepunch.Steamworks.Server(252490, serverInit)) { server.ServerName = "My Test Server"; server.LogOnAnonymous(); Assert.IsTrue(server.IsValid); } }
public void StatsGet() { using (var server = new Facepunch.Steamworks.Server(252490, 0, 30002, true, "VersionString")) { Assert.IsTrue(server.IsValid); server.LogOnAnonymous(); ulong MySteamId = 76561197960279927; server.Stats.Refresh(MySteamId); // TODO - Callback on complete Thread.Sleep(2000); var deaths = server.Stats.GetInt(MySteamId, "deaths", -1); Console.WriteLine("Deaths: {0}", deaths); Assert.IsTrue(deaths > 0); } }
public void InventoryDeserialize() { using (var client = new Facepunch.Steamworks.Client(252490)) { Assert.IsTrue(client.IsValid); Assert.IsNull(client.Inventory.SerializedItems); client.Inventory.Refresh(); // // Block until we have the items // while (client.Inventory.SerializedItems == null) { client.Update(); } Assert.IsNotNull(client.Inventory.SerializedItems); Assert.IsTrue(client.Inventory.SerializedItems.Length > 4); using (var server = new Facepunch.Steamworks.Server(252490, 0, 30002, true, "VersionString")) { server.LogOnAnonymous(); Assert.IsTrue(server.IsValid); var result = server.Inventory.Deserialize(client.Inventory.SerializedItems); Assert.IsTrue(result.Block()); 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); } } } }
public void Deserialize() { using (var client = new Facepunch.Steamworks.Client(252490)) { Assert.IsTrue(client.IsValid); client.Inventory.Refresh(); // // Block until we have the items // while (client.Inventory.SerializedItems == null) { client.Update(); } 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); server.UpdateWhile(() => result.IsPending); 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); } } } }
public override void OnAwake() { Instance = this; var init = new Facepunch.Steamworks.ServerInit(BuildingInformation.SteamworksModDir, BuildingInformation.SteamworksGameDesc) { GamePort = (ushort)Settings.GamePort, IpAddress = IPAddress.Parse(Settings.ServerIP), Secure = Settings.Secure, VersionString = Settings.GameVersion.ToString(), }; BaseSteamServer = new Facepunch.Steamworks.Server(BuildingInformation.SteamworksAppID, init); if (BaseSteamServer.IsValid) { BaseSteamServer.LogOnAnonymous(); Timer.SetInterval(OnUpdateServerInformation, 10f); } else { BaseSteamServer.Dispose(); BaseSteamServer = null; ConsoleSystem.LogWarning("[SteamworksManager]: Steamworks is not initialized!"); } }
public void AuthCallback() { using (var client = new Facepunch.Steamworks.Client(252490)) { Assert.IsTrue(client.IsValid); var ticket = client.Auth.GetAuthSessionTicket(); var ticketBinary = ticket.Data; using (var server = new Facepunch.Steamworks.Server(252490, 0, 30002, 30003, 30004, true, "VersionString")) { server.LogOnAnonymous(); Assert.IsTrue(server.IsValid); var auth = server.Auth; var Authed = false; server.Auth.OnAuthChange = (steamid, ownerid, status) => { Authed = status == ServerAuth.Status.OK; Assert.AreEqual(steamid, client.SteamId); Assert.AreEqual(steamid, ownerid); Console.WriteLine("steamid: {0}", steamid); Console.WriteLine("ownerid: {0}", ownerid); Console.WriteLine("status: {0}", status); }; for (int i = 0; i < 16; i++) { System.Threading.Thread.Sleep(10); GC.Collect(); server.Update(); GC.Collect(); client.Update(); GC.Collect(); } GC.Collect(); if (!server.Auth.StartSession(ticketBinary, client.SteamId)) { Assert.Fail("Start Session returned false"); } GC.Collect(); // // Server should receive a ServerAuth.Status.OK // message via the OnAuthChange callback // for (int i = 0; i < 100; i++) { GC.Collect(); System.Threading.Thread.Sleep(100); GC.Collect(); server.Update(); client.Update(); if (Authed) { break; } } Assert.IsTrue(Authed); // // Client cancels ticket // ticket.Cancel(); // // Server should receive a ticket cancelled message // for (int i = 0; i < 100; i++) { System.Threading.Thread.Sleep(100); server.Update(); client.Update(); if (!Authed) { break; } } Assert.IsTrue(!Authed); } } }