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