Merge branch 'analytics'

This commit is contained in:
Joonas Rikkonen
2018-07-11 10:37:33 +03:00
19 changed files with 198 additions and 18 deletions

View File

@@ -29,6 +29,8 @@
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
<ReleaseVersion>0.7.0.1</ReleaseVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
@@ -231,9 +233,15 @@
<Compile Include="Source\Utils\ToolBox.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="GameAnalytics.Mono, Version=1.0.6710.29255, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\lib\net45\GameAnalytics.Mono.dll</HintPath>
</Reference>
<Reference Condition="$(DefineConstants.Contains('WINDOWS'))" Include="MonoGame.Framework.WindowsDX">
<HintPath>..\..\Libraries\NuGet\MonoGame.Framework.WindowsDX.3.6.0.1625\lib\net40\MonoGame.Framework.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\NLog.4.3.8\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Condition="$(DefineConstants.Contains('WINDOWS'))" Include="PresentationCore" />
<Reference Condition="$(DefineConstants.Contains('WINDOWS'))" Include="SharpDX">
<SpecificVersion>False</SpecificVersion>
@@ -247,6 +255,9 @@
<HintPath>..\..\Libraries\NuGet\OpenTK.2.0.0\lib\net20\OpenTK.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data.SQLite, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
@@ -324,6 +335,13 @@
<ItemGroup />
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets" Condition="Exists('..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -198,7 +198,8 @@ namespace Barotrauma
private static bool QuitClicked(GUIButton button, object obj)
{
if (button.UserData as string == "save")
bool save = button.UserData as string == "save";
if (save)
{
SaveUtil.SaveGame(GameMain.GameSession.SavePath);
}
@@ -211,10 +212,15 @@ namespace Barotrauma
CoroutineManager.StopCoroutines("EndCinematic");
GameMain.GameSession = null;
if (GameMain.GameSession != null)
{
Mission mission = GameMain.GameSession.Mission;
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave"));
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed")));
GameMain.GameSession = null;
}
GameMain.MainMenuScreen.Select();
//Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main);
return true;
}

View File

@@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using GameAnalyticsSDK.Net;
namespace Barotrauma
{
@@ -144,7 +145,7 @@ namespace Barotrauma
Timing.Accumulator = 0.0f;
fixedTime = new GameTime();
World = new World(new Vector2(0, -9.82f));
FarseerPhysics.Settings.AllowSleep = true;
FarseerPhysics.Settings.ContinuousPhysics = false;
@@ -232,6 +233,31 @@ namespace Barotrauma
loadingCoroutine = CoroutineManager.StartCoroutine(Load());
}
private void InitUserStats()
{
if (GameSettings.ShowUserStatisticsPrompt)
{
var userStatsPrompt = new GUIMessageBox(
"Do you want to help us make Barotrauma better?",
"Do you allow Barotrauma to send usage statistics and error reports to the developers? The data is anonymous, " +
"does not contain any personal information and is only used to help us diagnose issues and improve Barotrauma.",
new string[] { "Yes", "No" });
userStatsPrompt.Buttons[0].OnClicked += (btn, userdata) =>
{
GameSettings.SendUserStatistics = true;
GameAnalyticsManager.Init();
return true;
};
userStatsPrompt.Buttons[0].OnClicked += userStatsPrompt.Close;
userStatsPrompt.Buttons[1].OnClicked += (btn, userdata) => { GameSettings.SendUserStatistics = false; return true; };
userStatsPrompt.Buttons[1].OnClicked += userStatsPrompt.Close;
}
else if (GameSettings.SendUserStatistics)
{
GameAnalyticsManager.Init();
}
}
private IEnumerable<object> Load()
{
if (GameSettings.VerboseLogging)
@@ -241,6 +267,8 @@ namespace Barotrauma
GUI.GraphicsDevice = base.GraphicsDevice;
GUI.Init(Content);
InitUserStats();
GUIComponent.Init(Window);
DebugConsole.Init(Window);
DebugConsole.Log(SelectedPackage == null ? "No content package selected" : "Content package \"" + SelectedPackage.Name + "\" selected");
@@ -472,7 +500,7 @@ namespace Barotrauma
protected override void OnExiting(object sender, EventArgs args)
{
if (NetworkMember != null) NetworkMember.Disconnect();
if (GameSettings.SendUserStatistics) GameAnalytics.OnStop();
base.OnExiting(sender, args);
}
}

View File

@@ -6,6 +6,7 @@ using System.Text;
#if WINDOWS
using System.Windows.Forms;
using GameAnalyticsSDK.Net;
using Microsoft.Xna.Framework.Graphics;
#endif
@@ -135,7 +136,6 @@ namespace Barotrauma
sb.AppendLine("Barotrauma Client crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("\n");
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
sb.AppendLine("\n");
#if DEBUG
sb.AppendLine("Game version " + GameMain.Version + " (debug build)");
@@ -192,14 +192,25 @@ namespace Barotrauma
{
sb.AppendLine("[" + DebugConsole.Messages[i].Time + "] " + DebugConsole.Messages[i].Text);
}
string crashReport = sb.ToString();
sw.WriteLine(sb.ToString());
sw.WriteLine(crashReport);
sw.Close();
if (GameSettings.SaveDebugConsoleLogs) DebugConsole.SaveLogs();
CrashMessageBox( "A crash report (\"crashreport.log\") was saved in the root folder of the game."+
" If you'd like to help fix this bug, please post the report on Barotrauma's GitHub issue tracker: https://github.com/Regalis11/Barotrauma/issues/");
if (GameSettings.SendUserStatistics)
{
CrashMessageBox( "A crash report (\"crashreport.log\") was saved in the root folder of the game and sent to the developers.");
GameAnalytics.AddErrorEvent(EGAErrorSeverity.Error, crashReport);
GameAnalytics.OnStop();
}
else
{
CrashMessageBox("A crash report (\"crashreport.log\") was saved in the root folder of the game. The error was not sent to the developers because user statistics have been disabled, but" +
" if you'd like to help fix this bug, you may post it on Barotrauma's GitHub issue tracker: https://github.com/Regalis11/Barotrauma/issues/");
}
}
}
#endif

View File

@@ -87,6 +87,9 @@ namespace Barotrauma
campaignUI.StartRound = StartRound;
campaignUI.OnLocationSelected = SelectLocation;
campaignUI.UpdateCharacterLists();
GameAnalyticsSDK.Net.GameAnalytics.SetCustomDimension01("singleplayer");
}
public override void AddToGUIUpdateList()

View File

@@ -142,6 +142,8 @@ namespace Barotrauma
campaignSetupUI.UpdateSubList();
SelectTab(null, 0);
GameAnalyticsSDK.Net.GameAnalytics.SetCustomDimension01("");
}
public bool SelectTab(GUIButton button, object obj)

View File

@@ -501,6 +501,8 @@ namespace Barotrauma
}
}
GameAnalyticsSDK.Net.GameAnalytics.SetCustomDimension01("multiplayer");
if (GameModePreset.list.Count > 0 && modeList.Selected == null) modeList.Select(0);
GameMain.Server.Voting.ResetVotes(GameMain.Server.ConnectedClients);

View File

@@ -348,6 +348,8 @@ namespace Barotrauma
}
cam.UpdateTransform();
GameAnalyticsSDK.Net.GameAnalytics.SetCustomDimension01("editor");
}
public override void Deselect()

View File

@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GameAnalytics.Mono.SDK" version="1.1.12" targetFramework="net45" />
<package id="MonoGame.Framework.DesktopGL" version="3.6.0.1625" targetFramework="net45" />
<package id="MonoGame.Framework.WindowsDX" version="3.6.0.1625" targetFramework="net45" />
<package id="NLog" version="4.3.8" targetFramework="net45" />
<package id="NVorbis" version="0.8.5.0" targetFramework="net45" />
<package id="OpenTK" version="2.0.0" targetFramework="net45" />
<package id="RestSharp" version="105.2.3" targetFramework="net45" />

View File

@@ -28,6 +28,8 @@
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<ReleaseVersion>0.7.0.1</ReleaseVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>..\BarotraumaShared\Icon.ico</ApplicationIcon>
@@ -69,11 +71,20 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="GameAnalytics.Mono, Version=1.0.6710.29255, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\lib\net45\GameAnalytics.Mono.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\NLog.4.3.8\lib\net45\NLog.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Libraries\NuGet\RestSharp.105.2.3\lib\net45\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data.SQLite, Version=1.0.102.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
@@ -142,6 +153,13 @@
<ItemGroup />
<Import Project="..\BarotraumaShared\BarotraumaShared.projitems" Label="Shared" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets" Condition="Exists('..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\Libraries\NuGet\GameAnalytics.Mono.SDK.1.1.12\build\net45\GameAnalytics.Mono.SDK.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@@ -1,5 +1,6 @@
using Barotrauma.Networking;
using FarseerPhysics.Dynamics;
using GameAnalyticsSDK.Net;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
@@ -72,6 +73,11 @@ namespace Barotrauma
Config.Save("config.xml");
}
if (GameSettings.SendUserStatistics)
{
GameAnalyticsManager.Init();
}
GameScreen = new GameScreen();
}
@@ -118,6 +124,7 @@ namespace Barotrauma
public void CloseServer()
{
if (GameSettings.SendUserStatistics) GameAnalytics.OnStop();
Server.Disconnect();
Server = null;
}

View File

@@ -1,5 +1,6 @@
#region Using Statements
using GameAnalyticsSDK.Net;
using System;
using System.IO;
using System.Text;
@@ -46,7 +47,6 @@ namespace Barotrauma
sb.AppendLine("Barotrauma Dedicated Server crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("\n");
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
sb.AppendLine("\n");
sb.AppendLine("Game version " + GameMain.Version);
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
@@ -75,11 +75,24 @@ namespace Barotrauma
sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text);
}
string crashReport = sb.ToString();
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(sb.ToString());
Console.Write(crashReport);
sw.WriteLine(sb.ToString());
sw.Close();
sw.Close();
if (GameSettings.SendUserStatistics)
{
GameAnalytics.AddErrorEvent(EGAErrorSeverity.Error, crashReport);
GameAnalytics.OnStop();
Console.Write("A crash report (\"crashreport.log\") was saved in the root folder of the game and sent to the developers.");
}
else
{
Console.Write("A crash report(\"crashreport.log\") was saved in the root folder of the game. The error was not sent to the developers because user statistics have been disabled, but" +
" if you'd like to help fix this bug, you may post it on Barotrauma's GitHub issue tracker: https://github.com/Regalis11/Barotrauma/issues/");
}
}
}
}

View File

@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GameAnalytics.Mono.SDK" version="1.1.12" targetFramework="net45" />
<package id="NLog" version="4.3.8" targetFramework="net45" />
<package id="RestSharp" version="105.2.3" targetFramework="net45" />
</packages>

View File

@@ -1475,6 +1475,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\CharacterNetworking.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\DamageModifier.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Events\Missions\MissionPrefab.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\GameAnalyticsManager.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Items\Components\Signal\AdderComponent.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\StatusEffects\DelayedEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Source\Characters\HuskInfection.cs" />

View File

@@ -1948,8 +1948,19 @@ namespace Barotrauma
AnimController.Frozen = false;
GameServer.Log(LogName+" has died (Cause of death: "+causeOfDeath+")", ServerLog.MessageType.Attack);
GameServer.Log(LogName + " has died (Cause of death: " + causeOfDeath + ")", ServerLog.MessageType.Attack);
string characterType = "Unknown";
if (this == controlled)
characterType = "Player";
else if (IsRemotePlayer)
characterType = "RemotePlayer";
else if (AIController is EnemyAIController)
characterType = "Enemy";
else if (AIController is HumanAIController)
characterType = "AICrew";
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("Kill:" + characterType + ":" + SpeciesName + ":" + causeOfDeath);
if (OnDeath != null) OnDeath(this, causeOfDeath);
KillProjSpecific();

View File

@@ -0,0 +1,23 @@
using GameAnalyticsSDK.Net;
using System;
namespace Barotrauma
{
public static class GameAnalyticsManager
{
public static void Init()
{
GameAnalytics.SetEnabledInfoLog(true);
GameAnalytics.ConfigureBuild(GameMain.Version.ToString());
GameAnalytics.ConfigureAvailableCustomDimensions01("singleplayer", "multiplayer", "editor");
GameAnalytics.Initialize("a3a073c20982de7c15d21e840e149122", "9010ad9a671233b8d9610d76cec8c897d9ff3ba7");
string contentPackageName = GameMain.Config?.SelectedContentPackage?.Name;
if (!string.IsNullOrEmpty(contentPackageName))
{
GameAnalytics.AddDesignEvent("ContentPackage:" +
contentPackageName.Replace(":", "").Substring(0, Math.Min(32, contentPackageName.Length)));
}
}
}
}

View File

@@ -228,6 +228,10 @@ namespace Barotrauma
if (GameMode != null) GameMode.MsgBox();
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("Submarine:" + submarine.Name);
GameAnalyticsSDK.Net.GameAnalytics.AddProgressionEvent(GameAnalyticsSDK.Net.EGAProgressionStatus.Start,
GameMode.Name, (Mission == null ? "None" : Mission.GetType().ToString()));
#if CLIENT
roundSummary = new RoundSummary(this);
@@ -239,6 +243,9 @@ namespace Barotrauma
public void EndRound(string endMessage)
{
if (Mission != null) Mission.End();
GameAnalyticsSDK.Net.GameAnalytics.AddProgressionEvent((Mission == null || Mission.Completed) ? GameAnalyticsSDK.Net.EGAProgressionStatus.Complete : GameAnalyticsSDK.Net.EGAProgressionStatus.Fail,
GameMode.Name, (Mission == null ? "None" : Mission.GetType().ToString()));
#if CLIENT
if (roundSummary != null)

View File

@@ -125,6 +125,18 @@ namespace Barotrauma
public static bool VerboseLogging { get; set; }
public static bool SaveDebugConsoleLogs { get; set; }
private static bool sendUserStatistics;
public static bool SendUserStatistics
{
get { return sendUserStatistics; }
set
{
sendUserStatistics = value;
GameMain.Config.Save("config.xml");
}
}
public static bool ShowUserStatisticsPrompt { get; private set; }
public GameSettings(string filePath)
{
ContentPackage.LoadAll(ContentPackage.Folder);
@@ -143,6 +155,14 @@ namespace Barotrauma
VerboseLogging = doc.Root.GetAttributeBool("verboselogging", false);
SaveDebugConsoleLogs = doc.Root.GetAttributeBool("savedebugconsolelogs", false);
if (doc.Root.Attribute("senduserstatistics") == null)
{
ShowUserStatisticsPrompt = true;
}
else
{
sendUserStatistics = doc.Root.GetAttributeBool("senduserstatistics", true);
}
if (doc == null)
{
@@ -259,10 +279,8 @@ namespace Barotrauma
{
case "contentpackage":
string path = subElement.GetAttributeString("path", "");
SelectedContentPackage = ContentPackage.list.Find(cp => cp.Path == path);
if (SelectedContentPackage == null) SelectedContentPackage = new ContentPackage(path);
break;
}
@@ -287,7 +305,8 @@ namespace Barotrauma
new XAttribute("soundvolume", soundVolume),
new XAttribute("verboselogging", VerboseLogging),
new XAttribute("savedebugconsolelogs", SaveDebugConsoleLogs),
new XAttribute("enablesplashscreen", EnableSplashScreen));
new XAttribute("enablesplashscreen", EnableSplashScreen),
new XAttribute("senduserstatistics", sendUserStatistics));
if (WasGameUpdated)
{

View File

@@ -208,6 +208,8 @@ namespace Barotrauma.Networking
GameMain.NetLobbyScreen.Select();
GameMain.NetLobbyScreen.RandomizeSettings();
started = true;
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("GameServer:Start");
yield return CoroutineStatus.Success;
}
@@ -1357,6 +1359,8 @@ namespace Barotrauma.Networking
}
}
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("Traitors:" + (TraitorManager == null ? "Disabled" : "Enabled"));
SendStartMessage(roundStartSeed, Submarine.MainSub, GameMain.GameSession.GameMode.Preset, connectedClients);
yield return CoroutineStatus.Running;
@@ -2249,7 +2253,8 @@ namespace Barotrauma.Networking
Log("Shutting down the server...", ServerLog.MessageType.ServerMessage);
log.Save();
}
GameAnalyticsSDK.Net.GameAnalytics.AddDesignEvent("GameServer:ShutDown");
server.Shutdown("The server has been shut down");
}
}