This commit is contained in:
Garry Newman 2018-02-01 19:16:44 +00:00
parent f0e4c63267
commit d134c5e6ff

View File

@ -8,7 +8,7 @@ public partial class LobbyList
{ {
public class Lobby public class Lobby
{ {
private Dictionary<string, string> m_lobbyData; private Dictionary<string, string> 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; }
@ -24,12 +24,10 @@ public class Lobby
/// <returns>The value at key</returns> /// <returns>The value at key</returns>
public string GetData(string k) public string GetData(string k)
{ {
if (m_lobbyData.ContainsKey(k)) if (lobbyData.TryGetValue(k, out var v))
{ return v;
return m_lobbyData[k];
}
return "ERROR: key not found"; return string.Empty;
} }
/// <summary> /// <summary>
@ -38,27 +36,29 @@ public string GetData(string k)
/// <returns>Dictionary of all the key/value pairs in the data</returns> /// <returns>Dictionary of all the key/value pairs in the data</returns>
public Dictionary<string, string> GetAllData() public Dictionary<string, string> GetAllData()
{ {
Dictionary<string, string> returnData = new Dictionary<string, string>(); var returnData = new Dictionary<string, string>();
foreach (KeyValuePair<string, string> item in m_lobbyData)
foreach ( var item in lobbyData)
{ {
returnData.Add(item.Key, item.Value); returnData.Add(item.Key, item.Value);
} }
return returnData; 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>(); var lobbyData = new Dictionary<string, string>();
int dataCount = client.native.matchmaking.GetLobbyDataCount(lobby); int dataCount = client.native.matchmaking.GetLobbyDataCount(lobby);
for (int i = 0; i < dataCount; i++) for (int i = 0; i < dataCount; i++)
{ {
string datakey = string.Empty; if (client.native.matchmaking.GetLobbyDataByIndex(lobby, i, out var datakey, out var datavalue))
string datavalue = string.Empty;
if (client.native.matchmaking.GetLobbyDataByIndex(lobby, i, out datakey, out datavalue))
{ {
lobbyData.Add(datakey, datavalue); lobbyData.Add(datakey, datavalue);
} }
} }
return new Lobby() return new Lobby()
{ {
Client = client, Client = client,
@ -68,7 +68,7 @@ internal static Lobby FromSteam(Client client, ulong lobby)
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 lobbyData = lobbyData
}; };
} }