3 using System.Collections.Generic;
4 using System.Collections.Immutable;
5 using System.Threading.Tasks;
18 public override void Write(XElement element) { }
26 private object? queryRef =
null;
28 protected override void RetrieveServersImpl(Action<ServerInfo, ServerProvider> onServerDataReceived, Action onQueryCompleted)
30 if (!SteamManager.IsInitialized)
38 var selfQueryRef =
new object();
39 queryRef = selfQueryRef;
41 Steamworks.Data.LobbyQuery lobbyQuery = Steamworks.SteamMatchmaking.CreateLobbyQuery()
42 .FilterDistanceWorldwide()
48 #warning TODO: do something less horrible here?
51 HashSet<SteamId> retrieved =
new HashSet<SteamId>();
55 if (requestCount >= 10) {
return; }
57 TaskPool.Add($
"LobbyQuery.RequestAsync ({requestCount})", lobbyQuery.RequestAsync(), onRequestComplete);
60 void onRequestComplete(Task t)
63 if (!ReferenceEquals(selfQueryRef, queryRef)) {
return; }
65 if (!t.TryGetResult(out Steamworks.Data.Lobby[]? lobbies)
67 || lobbies.Length == 0)
73 foreach (var lobby
in lobbies)
75 string lobbyOwnerStr = lobby.GetData(
"lobbyowner") ??
"";
76 lobbyQuery = lobbyQuery.WithoutKeyValue(
"lobbyowner", lobbyOwnerStr);
78 string serverName = lobby.GetData(
"servername").FallbackNullOrEmpty(lobby.GetData(
"name")) ??
"";
79 if (
string.IsNullOrEmpty(serverName)) {
continue; }
81 var ownerId = SteamId.Parse(lobbyOwnerStr);
82 if (!ownerId.TryUnwrap(out var lobbyOwnerId)) {
continue; }
85 .
Parse(lobby.GetData(
"EosEndpoint") ??
"")
88 if (retrieved.Contains(lobbyOwnerId)) {
continue; }
89 retrieved.Add(lobbyOwnerId);
92 if (eosP2PEndpointOption.TryUnwrap(out var eosP2PEndpoint)) { endpoints.Add(eosP2PEndpoint); }
94 var serverInfo =
new ServerInfo(endpoints.ToImmutableArray())
96 ServerName = serverName,
99 serverInfo.UpdateInfo(key => lobby.GetData(key));
100 serverInfo.Checked =
true;
102 onServerDataReceived(serverInfo,
this);
DataSource(Steamworks.Data.Lobby lobby)
override void Write(XElement element)
readonly Steamworks.Data.Lobby Lobby
override void RetrieveServersImpl(Action< ServerInfo, ServerProvider > onServerDataReceived, Action onQueryCompleted)
static new Option< EosP2PEndpoint > Parse(string endpointStr)