v1.3.0.1 (Epic Store release)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using Barotrauma.Steam;
|
||||
using RestSharp;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -13,7 +14,7 @@ namespace Barotrauma
|
||||
/// The protocol used to communicate with the remote consent server may change.
|
||||
/// This number tells the server which version the game is using so we can implement backwards-compatibility.
|
||||
/// </summary>
|
||||
private const string RemoteRequestVersion = "2";
|
||||
private const string RemoteRequestVersion = "3";
|
||||
|
||||
public enum Consent
|
||||
{
|
||||
@@ -47,19 +48,66 @@ namespace Barotrauma
|
||||
|
||||
public static bool SendUserStatistics => UserConsented == Consent.Yes && loadedImplementation != null;
|
||||
|
||||
private static bool consentTextAvailable
|
||||
private static bool ConsentTextAvailable
|
||||
=> TextManager.ContainsTag("statisticsconsentheader")
|
||||
&& TextManager.ContainsTag("statisticsconsenttext");
|
||||
|
||||
private const string consentServerUrl = "https://barotraumagame.com/baromaster/";
|
||||
private const string consentServerFile = "consentserver.php";
|
||||
|
||||
private static async Task<string> GetAuthTicket()
|
||||
enum Platform
|
||||
{
|
||||
var ticketOption = await SteamManager.GetAuthTicketForGameAnalyticsConsent();
|
||||
if (!ticketOption.TryUnwrap(out var authTicket) || authTicket.Data is null) { return ""; }
|
||||
//convert byte array to hex
|
||||
return BitConverter.ToString(authTicket.Data).Replace("-", "");
|
||||
Steam,
|
||||
EOS,
|
||||
None
|
||||
}
|
||||
|
||||
private class AuthTicket
|
||||
{
|
||||
public readonly string Token;
|
||||
public readonly Platform Platform;
|
||||
|
||||
public AuthTicket(string token, Platform platform)
|
||||
{
|
||||
Token = token ?? string.Empty;
|
||||
Platform = platform;
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task<AuthTicket> GetAuthTicket()
|
||||
{
|
||||
if (SteamManager.IsInitialized)
|
||||
{
|
||||
return await GetSteamAuthTicket();
|
||||
}
|
||||
else if (EosInterface.IdQueries.IsLoggedIntoEosConnect)
|
||||
{
|
||||
return await GetEOSAuthTicket();
|
||||
}
|
||||
return new AuthTicket(string.Empty, Platform.None);
|
||||
}
|
||||
|
||||
private static async Task<AuthTicket> GetSteamAuthTicket()
|
||||
{
|
||||
var authTicket = await SteamManager.GetAuthTicketForGameAnalyticsConsent();
|
||||
return authTicket.TryUnwrap(out var ticketUnwrapped) && ticketUnwrapped.Data is { Length: > 0 }
|
||||
? new AuthTicket(ToolBoxCore.ByteArrayToHexString(ticketUnwrapped.Data), Platform.Steam) //convert byte array to hex
|
||||
: throw new Exception("Could not retrieve Steamworks authentication ticket for GameAnalytics");
|
||||
}
|
||||
|
||||
private static async Task<AuthTicket> GetEOSAuthTicket()
|
||||
{
|
||||
var puid = EosInterface.IdQueries.GetLoggedInPuids().First();
|
||||
var tokenResult = EosInterface.EosIdToken.FromProductUserId(puid);
|
||||
if (tokenResult.TryUnwrapFailure(out var error))
|
||||
{
|
||||
throw new Exception($"Could not retrieve EOS authentication ticket for GameAnalytics. {error}");
|
||||
}
|
||||
else if (tokenResult.TryUnwrapSuccess(out var token))
|
||||
{
|
||||
return new AuthTicket(token.JsonWebToken.ToString(), Platform.EOS);
|
||||
}
|
||||
throw new UnreachableCodeException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -92,7 +140,9 @@ namespace Barotrauma
|
||||
|
||||
if (consent == Consent.Ask)
|
||||
{
|
||||
CreateConsentPrompt();
|
||||
#if CLIENT
|
||||
GameMain.ExecuteAfterContentFinishedLoading(CreateConsentPrompt);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (consent != Consent.No && consent != Consent.Yes)
|
||||
@@ -129,20 +179,24 @@ namespace Barotrauma
|
||||
/// </summary>
|
||||
private static async Task<bool> SendAnswerToRemoteDatabase(Consent consent)
|
||||
{
|
||||
string authTicketStr;
|
||||
AuthTicket authTicket;
|
||||
try
|
||||
{
|
||||
authTicketStr = await GetAuthTicket();
|
||||
authTicket = await GetAuthTicket();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in GameAnalyticsManager.SetConsent. Could not get a Steam authentication ticket.", e);
|
||||
DebugConsole.ThrowError($"Error in {nameof(GameAnalyticsManager)}.{nameof(SendAnswerToRemoteDatabase)}. Could not get an authentication ticket.", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(authTicketStr))
|
||||
if (authTicket.Platform == Platform.None)
|
||||
{
|
||||
DebugConsole.ThrowError("Error in GameAnalyticsManager.SetContent. Steam authentication ticket was empty.");
|
||||
DebugConsole.AddWarning($"Error in {nameof(GameAnalyticsManager)}.{nameof(SendAnswerToRemoteDatabase)}. Not logged in to any platform.");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(authTicket.Token))
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in {nameof(GameAnalyticsManager)}.{nameof(SendAnswerToRemoteDatabase)}. {authTicket.Platform} authentication ticket was empty.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -152,10 +206,18 @@ namespace Barotrauma
|
||||
var client = new RestClient(consentServerUrl);
|
||||
|
||||
var request = new RestRequest(consentServerFile, Method.GET);
|
||||
request.AddParameter("authticket", authTicketStr);
|
||||
request.AddParameter("action", "setconsent");
|
||||
request.AddParameter("consent", consent == Consent.Yes ? 1 : 0);
|
||||
request.AddParameter("authticket", authTicket.Token);
|
||||
if (consent == Consent.Ask)
|
||||
{
|
||||
request.AddParameter("action", "resetconsent");
|
||||
}
|
||||
else
|
||||
{
|
||||
request.AddParameter("action", "setconsent");
|
||||
request.AddParameter("consent", consent == Consent.Yes ? 1 : 0);
|
||||
}
|
||||
request.AddParameter("request_version", RemoteRequestVersion);
|
||||
request.AddParameter("platform", authTicket.Platform);
|
||||
|
||||
response = await client.ExecuteAsync(request, Method.GET);
|
||||
}
|
||||
@@ -175,6 +237,18 @@ namespace Barotrauma
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void ResetConsent()
|
||||
{
|
||||
TaskPool.Add(
|
||||
"GameAnalyticsConsent.ResetConsentInternal",
|
||||
SendAnswerToRemoteDatabase(Consent.Ask),
|
||||
t =>
|
||||
{
|
||||
if (!t.TryGetResult(out bool success) || !success) { return; }
|
||||
DebugConsole.NewMessage("Reset GameAnalytics consent.");
|
||||
});
|
||||
}
|
||||
|
||||
static partial void CreateConsentPrompt();
|
||||
|
||||
public static void InitIfConsented()
|
||||
@@ -183,15 +257,15 @@ namespace Barotrauma
|
||||
return;
|
||||
#endif
|
||||
|
||||
if (!consentTextAvailable)
|
||||
if (!ConsentTextAvailable)
|
||||
{
|
||||
SetConsent(Consent.Unknown);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!SteamManager.IsInitialized)
|
||||
if (!SteamManager.IsInitialized && EosInterface.IdQueries.GetLoggedInPuids() is not { Length: > 0 })
|
||||
{
|
||||
DebugConsole.AddWarning("Error in GameAnalyticsManager.GetConsent: Could not get a Steam authentication ticket (not connected to Steam).");
|
||||
DebugConsole.AddWarning("Error in GameAnalyticsManager.GetConsent: Could not get a Steam or EOS authentication ticket (not connected to Steam or EOS).");
|
||||
SetConsent(Consent.Error);
|
||||
return;
|
||||
}
|
||||
@@ -208,20 +282,25 @@ namespace Barotrauma
|
||||
|
||||
private static async Task<Consent> RequestAnswerFromRemoteDatabase()
|
||||
{
|
||||
static void error(string reason, Exception exception)
|
||||
static void error(string reason, Exception? exception)
|
||||
{
|
||||
DebugConsole.ThrowError($"Error in GameAnalyticsManager.GetConsent: {reason}", exception);
|
||||
DebugConsole.ThrowError($"Error in {nameof(GameAnalyticsManager)}.{nameof(RequestAnswerFromRemoteDatabase)}: {reason}", exception);
|
||||
SetConsent(Consent.Error);
|
||||
}
|
||||
|
||||
string authTicketStr;
|
||||
AuthTicket authTicket;
|
||||
try
|
||||
{
|
||||
authTicketStr = await GetAuthTicket();
|
||||
authTicket = await GetAuthTicket();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
error("Could not get a Steam authentication ticket.", e);
|
||||
error("Could not get an authentication ticket.", e);
|
||||
return Consent.Error;
|
||||
}
|
||||
if (authTicket.Platform == Platform.None)
|
||||
{
|
||||
error($"Could not get an authentication ticket. Not logged in to any platform.", exception: null);
|
||||
return Consent.Error;
|
||||
}
|
||||
|
||||
@@ -237,9 +316,10 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
var request = new RestRequest(consentServerFile, Method.GET);
|
||||
request.AddParameter("authticket", authTicketStr);
|
||||
request.AddParameter("authticket", authTicket.Token);
|
||||
request.AddParameter("action", "getconsent");
|
||||
request.AddParameter("request_version", RemoteRequestVersion);
|
||||
request.AddParameter("platform", authTicket.Platform);
|
||||
|
||||
IRestResponse response;
|
||||
try
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Steam;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -51,6 +52,13 @@ namespace Barotrauma
|
||||
Difficulty90to100,
|
||||
}
|
||||
|
||||
public enum CustomDimensions03
|
||||
{
|
||||
UnknownPlatform,
|
||||
Steam,
|
||||
EGS
|
||||
}
|
||||
|
||||
public enum ResourceCurrency
|
||||
{
|
||||
Money
|
||||
@@ -149,6 +157,14 @@ namespace Barotrauma
|
||||
internal void ConfigureAvailableResourceCurrencies(params ResourceCurrency[] customDimensions)
|
||||
=> configureAvailableResourceCurrencies(customDimensions.Select(d => d.ToString()).ToArray());
|
||||
|
||||
private readonly Action<string[]> configureAvailableCustomDimensions03;
|
||||
internal void ConfigureAvailableCustomDimensions03(params CustomDimensions03[] customDimensions)
|
||||
=> configureAvailableCustomDimensions03(customDimensions.Select(d => d.ToString()).ToArray());
|
||||
|
||||
private readonly Action<string> setCustomDimension03;
|
||||
internal void SetCustomDimension03(string dimension03)
|
||||
=> setCustomDimension03(dimension03);
|
||||
|
||||
private readonly Action<string[]> configureAvailableResourceItemTypes;
|
||||
internal void ConfigureAvailableResourceItemTypes(params string[] resourceItemTypes)
|
||||
=> configureAvailableResourceItemTypes(resourceItemTypes);
|
||||
@@ -238,9 +254,9 @@ namespace Barotrauma
|
||||
{
|
||||
if (resolvingDependency) { return null; }
|
||||
resolvingDependency = true;
|
||||
Assembly dep = context.LoadFromAssemblyPath(GetAssemblyPath(dependencyName.Name ?? throw new Exception("Dependency name was null")));
|
||||
Assembly dependency = context.LoadFromAssemblyPath(GetAssemblyPath(dependencyName.Name ?? throw new Exception("Dependency name was null")));
|
||||
resolvingDependency = false;
|
||||
return dep;
|
||||
return dependency;
|
||||
}
|
||||
|
||||
internal Implementation()
|
||||
@@ -297,7 +313,10 @@ namespace Barotrauma
|
||||
new Type[] { typeof(string) }));
|
||||
configureAvailableCustomDimensions02 = Call<string[]>(getMethod(nameof(ConfigureAvailableCustomDimensions02),
|
||||
new Type[] { typeof(string[]) }));
|
||||
|
||||
configureAvailableCustomDimensions03 = Call<string[]>(getMethod(nameof(ConfigureAvailableCustomDimensions03),
|
||||
new Type[] { typeof(string[]) }));
|
||||
setCustomDimension03 = Call<string>(getMethod(nameof(SetCustomDimension03),
|
||||
new Type[] { typeof(string) }));
|
||||
configureAvailableResourceCurrencies = Call<string[]>(getMethod(nameof(ConfigureAvailableResourceCurrencies),
|
||||
new Type[] { typeof(string[]) }));
|
||||
configureAvailableResourceItemTypes = Call<string[]>(getMethod(nameof(ConfigureAvailableResourceItemTypes),
|
||||
@@ -424,6 +443,12 @@ namespace Barotrauma
|
||||
loadedImplementation?.SetCustomDimension01(dimension.ToString());
|
||||
}
|
||||
|
||||
public static void SetCustomDimension03(CustomDimensions03 dimension)
|
||||
{
|
||||
if (!SendUserStatistics) { return; }
|
||||
loadedImplementation?.SetCustomDimension03(dimension.ToString());
|
||||
}
|
||||
|
||||
public static void SetCurrentLevel(LevelData levelData)
|
||||
{
|
||||
if (!SendUserStatistics) { return; }
|
||||
@@ -509,6 +534,7 @@ namespace Barotrauma
|
||||
+ buildConfiguration);
|
||||
loadedImplementation?.ConfigureAvailableCustomDimensions01(Enum.GetValues(typeof(CustomDimensions01)).Cast<CustomDimensions01>().ToArray());
|
||||
loadedImplementation?.ConfigureAvailableCustomDimensions02(Enum.GetValues(typeof(CustomDimensions02)).Cast<CustomDimensions02>().ToArray());
|
||||
loadedImplementation?.ConfigureAvailableCustomDimensions03(Enum.GetValues(typeof(CustomDimensions03)).Cast<CustomDimensions03>().ToArray());
|
||||
loadedImplementation?.ConfigureAvailableResourceCurrencies(Enum.GetValues(typeof(ResourceCurrency)).Cast<ResourceCurrency>().ToArray());
|
||||
loadedImplementation?.ConfigureAvailableResourceItemTypes(
|
||||
Enum.GetValues(typeof(MoneySink)).Cast<MoneySink>().Select(s => s.ToString()).Union(Enum.GetValues(typeof(MoneySource)).Cast<MoneySource>().Select(s => s.ToString())).ToArray());
|
||||
@@ -521,6 +547,19 @@ namespace Barotrauma
|
||||
+ (exeHash?.ShortRepresentation ?? "Unknown") + ":"
|
||||
+ AssemblyInfo.GitRevision + ":"
|
||||
+ buildConfiguration);
|
||||
|
||||
SetCustomDimension01(ContentPackageManager.ModsEnabled ? CustomDimensions01.Modded : CustomDimensions01.Vanilla);
|
||||
|
||||
CustomDimensions03 platform = CustomDimensions03.UnknownPlatform;
|
||||
if (SteamManager.IsInitialized)
|
||||
{
|
||||
platform = CustomDimensions03.Steam;
|
||||
}
|
||||
else if (EosInterface.IdQueries.IsLoggedIntoEosConnect)
|
||||
{
|
||||
platform = CustomDimensions03.EGS;
|
||||
}
|
||||
SetCustomDimension03(platform);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user