From e66a00d212e106fa478f995d93f06b03fb9755eb Mon Sep 17 00:00:00 2001 From: AlexSSZ Date: Mon, 29 Jan 2018 06:29:43 -0500 Subject: [PATCH] Added Dictionary GetAllData(); Added string GetData(string k); Added string LobbyType { get; private set; } To LobbyList.Lobby With this you can list extra lobby parameters when displaying the Lobby List, such as current played map or game mode. --- Facepunch.Steamworks.Test/Client/LobbyTest.cs | 55 +++++++++++++++++++ .../Client/LobbyList.Lobby.cs | 46 +++++++++++++++- 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/Facepunch.Steamworks.Test/Client/LobbyTest.cs b/Facepunch.Steamworks.Test/Client/LobbyTest.cs index 156f795..17241a3 100644 --- a/Facepunch.Steamworks.Test/Client/LobbyTest.cs +++ b/Facepunch.Steamworks.Test/Client/LobbyTest.cs @@ -248,6 +248,61 @@ public void RefreshLobbyListWithFilter() } } + [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() { diff --git a/Facepunch.Steamworks/Client/LobbyList.Lobby.cs b/Facepunch.Steamworks/Client/LobbyList.Lobby.cs index e16dab2..1ba4930 100644 --- a/Facepunch.Steamworks/Client/LobbyList.Lobby.cs +++ b/Facepunch.Steamworks/Client/LobbyList.Lobby.cs @@ -8,23 +8,67 @@ public partial class LobbyList { public class Lobby { + private Dictionary m_lobbyData; internal Client Client; public string Name { get; private set; } public ulong LobbyID { get; private set; } public ulong Owner { get; private set; } public int MemberLimit{ get; private set; } public int NumMembers{ get; private set; } + public string LobbyType { get; private set; } + + /// + /// Get the lobby value for the specific key + /// + /// The key to find + /// The value at key + public string GetData(string k) + { + if (m_lobbyData.ContainsKey(k)) + { + return m_lobbyData[k]; + } + + return "ERROR: key not found"; + } + + /// + /// Get a list of all the data in the Lobby + /// + /// Dictionary of all the key/value pairs in the data + public Dictionary GetAllData() + { + Dictionary returnData = new Dictionary(); + foreach (KeyValuePair item in m_lobbyData) + { + returnData.Add(item.Key, item.Value); + } + return returnData; + } internal static Lobby FromSteam(Client client, ulong lobby) { + Dictionary lobbyData = new Dictionary(); + int dataCount = client.native.matchmaking.GetLobbyDataCount(lobby); + for (int i = 0; i < dataCount; i++) + { + string datakey = string.Empty; + string datavalue = string.Empty; + if (client.native.matchmaking.GetLobbyDataByIndex(lobby, i, out datakey, out datavalue)) + { + lobbyData.Add(datakey, datavalue); + } + } return new Lobby() { Client = client, LobbyID = lobby, Name = client.native.matchmaking.GetLobbyData(lobby, "name"), + LobbyType = client.native.matchmaking.GetLobbyData(lobby, "lobbytype"), MemberLimit = client.native.matchmaking.GetLobbyMemberLimit(lobby), Owner = client.native.matchmaking.GetLobbyOwner(lobby), - NumMembers = client.native.matchmaking.GetNumLobbyMembers(lobby) + NumMembers = client.native.matchmaking.GetNumLobbyMembers(lobby), + m_lobbyData = lobbyData }; }