From ace358631e3ef847e54842a85a012c74c000da3d Mon Sep 17 00:00:00 2001 From: juanjp600 Date: Thu, 19 Dec 2019 17:41:49 -0300 Subject: [PATCH] (a3569b8) Updated Facepunch.Steamworks --- Libraries/Facepunch.Steamworks/Client.cs | 1 + .../Facepunch.Steamworks/Client/LobbyList.cs | 127 +++--------------- 2 files changed, 19 insertions(+), 109 deletions(-) diff --git a/Libraries/Facepunch.Steamworks/Client.cs b/Libraries/Facepunch.Steamworks/Client.cs index f97669255..62d167c14 100644 --- a/Libraries/Facepunch.Steamworks/Client.cs +++ b/Libraries/Facepunch.Steamworks/Client.cs @@ -151,6 +151,7 @@ namespace Facepunch.Steamworks return; RunCallbacks(); + LobbyList.Update(); Voice.Update(); Friends.Cycle(); diff --git a/Libraries/Facepunch.Steamworks/Client/LobbyList.cs b/Libraries/Facepunch.Steamworks/Client/LobbyList.cs index c161bf3b3..bd2bfe83a 100644 --- a/Libraries/Facepunch.Steamworks/Client/LobbyList.cs +++ b/Libraries/Facepunch.Steamworks/Client/LobbyList.cs @@ -11,47 +11,40 @@ namespace Facepunch.Steamworks { internal Client client; - //The list of retrieved lobbies - public List Lobbies { get; private set; } - - public Dictionary> ManualLobbyDataCallbacks { get; private set; } - - //True when all the possible lobbies have had their data updated - //if the number of lobbies is now equal to the initial request number, we've found all lobbies - public bool Finished { get; private set; } - - //The number of possible lobbies we can get data from - internal List requests; + public Action OnLobbyDataReceived; internal LobbyList(Client client) { client.RegisterCallback(OnLobbyDataUpdated); this.client = client; - Lobbies = new List(); - requests = new List(); + } - ManualLobbyDataCallbacks = new Dictionary>(); + List pendingCallbacks = new List(); + public void Update() + { + lock (pendingCallbacks) + { + foreach (ulong lobbyId in pendingCallbacks) + { + OnLobbyDataReceived?.Invoke(Lobby.FromSteam(client, lobbyId)); + } + pendingCallbacks.Clear(); + } } /// /// Refresh the List of Lobbies. If no filter is passed in, a default one is created that filters based on AppId ("appid"). /// /// - public void Refresh ( Filter filter = null) + public void Request(Filter filter = null) { //init out values - Lobbies.Clear(); - requests.Clear(); - Finished = false; - if (filter == null) { filter = new Filter(); filter.StringFilters.Add("appid", client.AppId.ToString()); filter.DistanceFilter = Filter.Distance.Worldwide; - //client.native.matchmaking.RequestLobbyList(OnLobbyList); - //return; } client.native.matchmaking.AddRequestLobbyListDistanceFilter((SteamNative.LobbyDistanceFilter)filter.DistanceFilter); @@ -74,11 +67,6 @@ namespace Facepunch.Steamworks { client.native.matchmaking.AddRequestLobbyListNearValueFilter(fil.Key, fil.Value); } - //foreach (KeyValuePair> fil in filter.NumericalFilters) - //{ - // client.native.matchmaking.AddRequestLobbyListNumericalFilter(fil.Key, fil.Value.Value, (SteamNative.LobbyComparison)fil.Value.Key); - //} - // this will never return lobbies that are full (via the actual api) client.native.matchmaking.RequestLobbyList(OnLobbyList); @@ -95,77 +83,25 @@ namespace Facepunch.Steamworks // lobbies are returned in order of closeness to the user, so add them to the list in that order for (int i = 0; i < lobbiesMatching; i++) { - //add the lobby to the list of requests + //request lobby data ulong lobby = client.native.matchmaking.GetLobbyByIndex(i); - if (requests.Contains(lobby)) { continue; } - - requests.Add(lobby); - - //cast to a LobbyList.Lobby - Lobby newLobby = Lobby.FromSteam(client, lobby); - if (newLobby.Name != "") - { - //if the lobby is valid add it to the valid return lobbies - Lobbies.Add(newLobby); - checkFinished(); - } - else - { - //else we need to get the info for the missing lobby - client.native.matchmaking.RequestLobbyData(lobby); - } + client.native.matchmaking.RequestLobbyData(lobby); } - - checkFinished(); - - if (OnLobbiesUpdated != null) { OnLobbiesUpdated(); } - } - - void checkFinished() - { - if (Lobbies.Count >= requests.Count) - { - Finished = true; - return; - } - Finished = false; } void OnLobbyDataUpdated(LobbyDataUpdate_t callback) { if (callback.Success == 1) //1 if success, 0 if failure { - if (ManualLobbyDataCallbacks.ContainsKey(callback.SteamIDLobby)) + lock (pendingCallbacks) { - ManualLobbyDataCallbacks[callback.SteamIDLobby]?.Invoke(Lobby.FromSteam(client, callback.SteamIDLobby)); - } - - //find the lobby that has been updated - Lobby lobby = Lobbies.Find(x => x != null && x.LobbyID == callback.SteamIDLobby); - - //if this lobby isn't yet in the list of lobbies, we know that we should add it - if (lobby == null) - { - if (requests.Contains(callback.SteamIDLobby)) - { - lobby = Lobby.FromSteam(client, callback.SteamIDLobby); - Lobbies.Add(lobby); - checkFinished(); - } - } - - //otherwise lobby data in general was updated and you should listen to see what changed - if (requests.Contains(callback.SteamIDLobby)) - { - OnLobbiesUpdated?.Invoke(); + pendingCallbacks.Add(callback.SteamIDLobby); } } } - public Action OnLobbiesUpdated; - public Lobby GetLobbyFromID(ulong lobbyId) { return Lobby.FromSteam(client, lobbyId); @@ -176,33 +112,6 @@ namespace Facepunch.Steamworks client.native.matchmaking.RequestLobbyData(lobby); } - public void SetManualLobbyDataCallback(ulong steamId, Action callback) - { - if (callback != null) - { - if (ManualLobbyDataCallbacks == null) - { - ManualLobbyDataCallbacks = new Dictionary>(); - } - if (!ManualLobbyDataCallbacks.ContainsKey(steamId)) - { - ManualLobbyDataCallbacks.Add(steamId, callback); - } - else - { - ManualLobbyDataCallbacks[steamId] = callback; - } - } - else - { - if (ManualLobbyDataCallbacks == null) { return; } - if (ManualLobbyDataCallbacks.ContainsKey(steamId)) - { - ManualLobbyDataCallbacks.Remove(steamId); - } - } - } - public void Dispose() { client = null;