private async Task ResolveServerList() { DebugWrite("Resolving server list"); IEnumerable <ServerRecord> serverList = await configuration.ServerListProvider.FetchServerListAsync().ConfigureAwait(false); IReadOnlyCollection <ServerRecord> endpointList = serverList.ToList(); if (endpointList.Count == 0 && configuration.AllowDirectoryFetch) { DebugWrite("Server list provider had no entries, will query SteamDirectory"); endpointList = await SteamDirectory.LoadAsync(configuration).ConfigureAwait(false); } if (endpointList.Count == 0 && configuration.AllowDirectoryFetch) { DebugWrite("Could not query SteamDirectory, falling back to cm0"); var cm0 = await Dns.GetHostAddressesAsync("cm0.steampowered.com").ConfigureAwait(false); endpointList = cm0.Select(ipaddr => ServerRecord.CreateSocketServer(new IPEndPoint(ipaddr, 27015))).ToList(); } DebugWrite("Resolved {0} servers", endpointList.Count); ReplaceList(endpointList); }
void AddCore(ServerRecord endPoint) { foreach (var protocolType in endPoint.ProtocolTypes.GetFlags()) { var info = new ServerInfo(endPoint, protocolType); servers.Add(info); } }
/// <summary> /// Creates a Socket server given an IP endpoint. /// </summary> /// <param name="address">The IP address and port of the server, as a string.</param> /// <param name="serverRecord">A new <see cref="ServerRecord"/>, if the address was able to be parsed. <c>null</c> otherwise.</param> /// <returns><c>true</c> if the address was able to be parsed, <c>false</c> otherwise.</returns> public static bool TryCreateSocketServer(string address, [NotNullWhen(true)] out ServerRecord?serverRecord) { if (!NetHelpers.TryParseIPEndPoint(address, out var endPoint)) { serverRecord = default(ServerRecord); return(false); } serverRecord = new ServerRecord(endPoint, ProtocolTypes.Tcp | ProtocolTypes.Udp); return(true); }
/// <summary> /// Read the stored list of servers from IsolatedStore /// </summary> /// <returns>List of servers if persisted, otherwise an empty list</returns> public Task <IEnumerable <ServerRecord> > FetchServerListAsync() { return(Task.Run(() => { try { using (var fileStream = isolatedStorage.OpenFile(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { return Serializer.DeserializeItems <BasicServerListProto>(fileStream, PrefixStyle.Base128, 1) .Select(item => ServerRecord.CreateServer(item.Address, item.Port, item.Protocols)) .ToList(); } } catch (IOException ex) { DebugLog.WriteLine("IsolatedStorageServerListProvider", "Failed to read file {0}: {1}", FileName, ex.Message); return Enumerable.Empty <ServerRecord>(); } })); }
public ServerInfo(ServerRecord record, ProtocolTypes protocolType) { Record = record; Protocol = protocolType; }