private static ServerInformationComplete PrepareLoadedDirectly(ServerInformationComplete result, string ip) { if (result.Ip != ip) { // because, loaded directly, IP might different from global IP result.Ip = ip; } result.LoadedDirectly = true; if (result.Durations != null && result.SessionTypes != null) { for (var i = 0; i < result.Durations.Length; i++) { if ((Game.SessionType?)result.SessionTypes.ArrayElementAtOrDefault(i) != Game.SessionType.Race) { if (result.Durations[i] < 6000 /* usual value from the original launcher is 60, but it’s not enough */) { result.Durations[i] *= 60; } } else { if (result.Timed) { result.Durations[i] *= 60; } } } } return(result); }
public static ServerInformationComplete[] TryToGetList(IProgress <int> progress = null, CancellationToken cancellation = default) { if (SteamIdHelper.Instance.Value == null) { throw new InformativeException(ToolsStrings.Common_SteamIdIsMissing); } if (SettingsHolder.Online.CachingServerAvailable && SettingsHolder.Online.UseCachingServer) { try { var watch = Stopwatch.StartNew(); var ret = LoadList(InternalUtils.GetKunosServerCompressedProxyUri(), OptionWebRequestTimeout, cancellation, stream => { using (var deflateStream = new GZipStream(stream, CompressionMode.Decompress)) { return(ServerInformationComplete.Deserialize(deflateStream)); } }); /*var ret = LoadList(InternalUtils.GetKunosServerProxyUri(), OptionWebRequestTimeout, cancellation, * ServerInformationComplete.Deserialize);*/ Logging.Write($"Fast loading with proxy lobby server: {watch.Elapsed.TotalMilliseconds:F1} ms"); return(ret); } catch (Exception e) { Logging.Warning(e); } } if (cancellation.IsCancellationRequested) { throw new UserCancelledException(); } for (var i = 0; i < ServersNumber && ServerUri != null; i++) { if (progress != null) { var j = i; ActionExtension.InvokeInMainThread(() => progress.Report(j)); } var uri = ServerUri; var requestUri = $@"http://{uri}/lobby.ashx/list?guid={SteamIdHelper.Instance.Value}"; ServerInformationComplete[] parsed; try { var watch = Stopwatch.StartNew(); parsed = LoadList(requestUri, OptionWebRequestTimeout, cancellation, ServerInformationComplete.Deserialize); if (cancellation.IsCancellationRequested) { throw new UserCancelledException(); } Logging.Write($"Regular loading with main lobby server: {watch.Elapsed.TotalMilliseconds:F1} ms"); } catch (Exception e) { Logging.Warning(e); NextServer(); continue; } if (parsed.Length == 0) { return(parsed); } var ip = parsed[0].Ip; if (!ip.StartsWith(@"192")) { SettingsHolder.Online.CachingServerAvailable = true; return(parsed); } for (var j = parsed.Length - 1; j >= 0; j--) { var p = parsed[j]; if (p.Ip != ip) { SettingsHolder.Online.CachingServerAvailable = true; return(parsed); } } throw new InformativeException("Kunos server returned gibberish instead of list of servers", "Could it be that you’re using Steam ID without AC linked to it?"); } return(null); }