mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2024-12-25 14:15:47 +03:00
Added Dictionary<string, string> 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.
This commit is contained in:
parent
5991839c27
commit
e66a00d212
@ -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]
|
[TestMethod]
|
||||||
public void SendChatMessage()
|
public void SendChatMessage()
|
||||||
{
|
{
|
||||||
|
@ -8,23 +8,67 @@ public partial class LobbyList
|
|||||||
{
|
{
|
||||||
public class Lobby
|
public class Lobby
|
||||||
{
|
{
|
||||||
|
private Dictionary<string, string> m_lobbyData;
|
||||||
internal Client Client;
|
internal Client Client;
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public ulong LobbyID { get; private set; }
|
public ulong LobbyID { get; private set; }
|
||||||
public ulong Owner { get; private set; }
|
public ulong Owner { get; private set; }
|
||||||
public int MemberLimit{ get; private set; }
|
public int MemberLimit{ get; private set; }
|
||||||
public int NumMembers{ get; private set; }
|
public int NumMembers{ get; private set; }
|
||||||
|
public string LobbyType { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the lobby value for the specific key
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="k">The key to find</param>
|
||||||
|
/// <returns>The value at key</returns>
|
||||||
|
public string GetData(string k)
|
||||||
|
{
|
||||||
|
if (m_lobbyData.ContainsKey(k))
|
||||||
|
{
|
||||||
|
return m_lobbyData[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
return "ERROR: key not found";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a list of all the data in the Lobby
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Dictionary of all the key/value pairs in the data</returns>
|
||||||
|
public Dictionary<string, string> GetAllData()
|
||||||
|
{
|
||||||
|
Dictionary<string, string> returnData = new Dictionary<string, string>();
|
||||||
|
foreach (KeyValuePair<string, string> item in m_lobbyData)
|
||||||
|
{
|
||||||
|
returnData.Add(item.Key, item.Value);
|
||||||
|
}
|
||||||
|
return returnData;
|
||||||
|
}
|
||||||
|
|
||||||
internal static Lobby FromSteam(Client client, ulong lobby)
|
internal static Lobby FromSteam(Client client, ulong lobby)
|
||||||
{
|
{
|
||||||
|
Dictionary<string, string> lobbyData = new Dictionary<string, string>();
|
||||||
|
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()
|
return new Lobby()
|
||||||
{
|
{
|
||||||
Client = client,
|
Client = client,
|
||||||
LobbyID = lobby,
|
LobbyID = lobby,
|
||||||
Name = client.native.matchmaking.GetLobbyData(lobby, "name"),
|
Name = client.native.matchmaking.GetLobbyData(lobby, "name"),
|
||||||
|
LobbyType = client.native.matchmaking.GetLobbyData(lobby, "lobbytype"),
|
||||||
MemberLimit = client.native.matchmaking.GetLobbyMemberLimit(lobby),
|
MemberLimit = client.native.matchmaking.GetLobbyMemberLimit(lobby),
|
||||||
Owner = client.native.matchmaking.GetLobbyOwner(lobby),
|
Owner = client.native.matchmaking.GetLobbyOwner(lobby),
|
||||||
NumMembers = client.native.matchmaking.GetNumLobbyMembers(lobby)
|
NumMembers = client.native.matchmaking.GetNumLobbyMembers(lobby),
|
||||||
|
m_lobbyData = lobbyData
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user