mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Initial .NET Core 2.0 port
This commit is contained in:
@@ -37,9 +37,7 @@ namespace ArchiSteamFarm {
|
||||
private const byte MinHeartBeatTTL = 10; // Minimum amount of minutes we must wait before sending next HeartBeat
|
||||
private const byte MinPersonaStateTTL = 8; // Minimum amount of hours we must wait before requesting persona state update
|
||||
|
||||
private static readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1);
|
||||
|
||||
private static string _URL;
|
||||
private const string URL = "https://" + SharedInfo.StatisticsServer;
|
||||
|
||||
private readonly Bot Bot;
|
||||
private readonly SemaphoreSlim Semaphore = new SemaphoreSlim(1);
|
||||
@@ -70,7 +68,7 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
string request = await GetURL().ConfigureAwait(false) + "/api/HeartBeat";
|
||||
const string request = URL + "/api/HeartBeat";
|
||||
Dictionary<string, string> data = new Dictionary<string, string>(2) {
|
||||
{ "SteamID", Bot.SteamID.ToString() },
|
||||
{ "Guid", Program.GlobalDatabase.Guid.ToString("N") }
|
||||
@@ -139,7 +137,7 @@ namespace ArchiSteamFarm {
|
||||
return;
|
||||
}
|
||||
|
||||
string request = await GetURL().ConfigureAwait(false) + "/api/Announce";
|
||||
const string request = URL + "/api/Announce";
|
||||
Dictionary<string, string> data = new Dictionary<string, string>(7) {
|
||||
{ "SteamID", Bot.SteamID.ToString() },
|
||||
{ "Guid", Program.GlobalDatabase.Guid.ToString("N") },
|
||||
@@ -159,49 +157,5 @@ namespace ArchiSteamFarm {
|
||||
Semaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<string> GetURL() {
|
||||
if (!string.IsNullOrEmpty(_URL)) {
|
||||
return _URL;
|
||||
}
|
||||
|
||||
// Our statistics server is using TLS 1.2 encryption method, which is not supported e.g. by older versions of Mono
|
||||
// That's not a problem, as we support HTTP too, but of course we prefer more secure HTTPS if possible
|
||||
// Because of that, this function is responsible for finding which URL should be used for accessing the server
|
||||
|
||||
// If our runtime doesn't require TLS 1.2 tests, skip the rest entirely, just use HTTPS
|
||||
const string httpsURL = "https://" + SharedInfo.StatisticsServer;
|
||||
if (!Runtime.RequiresTls12Testing) {
|
||||
_URL = httpsURL;
|
||||
return _URL;
|
||||
}
|
||||
|
||||
await InitializationSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
|
||||
try {
|
||||
if (!string.IsNullOrEmpty(_URL)) {
|
||||
return _URL;
|
||||
}
|
||||
|
||||
// If we connect using HTTPS, use HTTPS as default version
|
||||
if (await Program.WebBrowser.UrlPost(httpsURL + "/api/ConnectionTest").ConfigureAwait(false)) {
|
||||
_URL = httpsURL;
|
||||
return _URL;
|
||||
}
|
||||
|
||||
// If we connect using HTTP, use HTTP as default version instead
|
||||
const string httpURL = "http://" + SharedInfo.StatisticsServer;
|
||||
if (await Program.WebBrowser.UrlPost(httpURL + "/api/ConnectionTest").ConfigureAwait(false)) {
|
||||
_URL = httpURL;
|
||||
return _URL;
|
||||
}
|
||||
} finally {
|
||||
InitializationSemaphore.Release();
|
||||
}
|
||||
|
||||
// If we didn't manage to establish connection through any of the above, return HTTPS, but don't record it
|
||||
// We might need to re-run this function in the future
|
||||
return httpsURL;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user