summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs')
-rw-r--r--Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs300
1 files changed, 300 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs b/Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs
new file mode 100644
index 0000000..6d81ae0
--- /dev/null
+++ b/Client/Assembly-CSharp/Assets/CoreScripts/Telemetry.cs
@@ -0,0 +1,300 @@
+using System;
+using System.Collections.Generic;
+using InnerNet;
+using UnityEngine;
+using UnityEngine.Analytics;
+
+namespace Assets.CoreScripts
+{
+ public class Telemetry : DestroyableSingleton<Telemetry>
+ {
+ private static readonly string[] ColorNames = new string[]
+ {
+ "Red",
+ "Blue",
+ "Green",
+ "Pink",
+ "Orange",
+ "Yellow",
+ "Black",
+ "White",
+ "Purple",
+ "Brown"
+ };
+
+ private bool amHost;
+
+ private bool gameStarted;
+
+ private DateTime timeStarted;
+
+ public bool IsInitialized;
+
+ public Guid CurrentGuid;
+
+ public void Initialize()
+ {
+ this.Initialize(Guid.NewGuid());
+ }
+
+ public void Initialize(Guid gameGuid)
+ {
+ this.IsInitialized = true;
+ this.CurrentGuid = gameGuid;
+ }
+
+ public void StartGame(bool sendName, bool isHost, int playerCount, int impostorCount, GameModes gameMode, uint timesImpostor, uint gamesPlayed, uint crewStreak)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ this.gameStarted = true;
+ this.amHost = isHost;
+ this.timeStarted = DateTime.UtcNow;
+ Dictionary<string, object> dictionary = new Dictionary<string, object>
+ {
+ {
+ "Platform",
+ (byte)Application.platform
+ },
+ {
+ "TimesImpostor",
+ timesImpostor
+ },
+ {
+ "CrewStreak",
+ crewStreak
+ },
+ {
+ "GamesPlayed",
+ gamesPlayed
+ },
+ {
+ "GameMode",
+ gameMode
+ }
+ };
+ if (this.amHost)
+ {
+ dictionary.Add("PlayerCount", playerCount);
+ dictionary.Add("InfectedCount", impostorCount);
+ }
+ Analytics.CustomEvent("StartGame", dictionary);
+ }
+
+ public void WriteMeetingStarted(bool isEmergency)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.amHost)
+ {
+ return;
+ }
+ Analytics.CustomEvent("MeetingStarted", new Dictionary<string, object>
+ {
+ {
+ "IsEmergency",
+ isEmergency
+ }
+ });
+ }
+
+ public void WriteMeetingEnded(byte[] results, float duration)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.amHost)
+ {
+ return;
+ }
+ Analytics.CustomEvent("MeetingEnded", new Dictionary<string, object>
+ {
+ {
+ "IsEmergency",
+ duration
+ }
+ });
+ }
+
+ public void WritePosition(byte playerNum, Vector2 worldPos)
+ {
+ }
+
+ public void WriteMurder(byte sourcePlayerNum, byte targetPlayerNum, Vector3 worldPos)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("Murder");
+ }
+
+ public void WriteSabotageUsed(SystemTypes systemType)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("SabotageUsed", new Dictionary<string, object>
+ {
+ {
+ "SystemType",
+ systemType
+ }
+ });
+ }
+
+ public void WriteUse(byte playerNum, TaskTypes taskType, Vector3 worldPos)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("ConsoleUsed", new Dictionary<string, object>
+ {
+ {
+ "TaskType",
+ taskType
+ }
+ });
+ }
+
+ public void WriteCompleteTask(byte playerNum, TaskTypes taskType)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("TaskComplete", new Dictionary<string, object>
+ {
+ {
+ "TaskType",
+ taskType
+ }
+ });
+ }
+
+ internal void WriteDisconnect(DisconnectReasons reason)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("Disconnect", new Dictionary<string, object>
+ {
+ {
+ "Reason",
+ reason
+ }
+ });
+ }
+
+ public void EndGame(GameOverReason endReason)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Dictionary<string, object> dictionary = new Dictionary<string, object>
+ {
+ {
+ "Reason",
+ endReason
+ }
+ };
+ if (this.amHost)
+ {
+ dictionary.Add("DurationSec", (DateTime.UtcNow - this.timeStarted).TotalSeconds);
+ }
+ Analytics.CustomEvent("EndGame", dictionary);
+ }
+
+ public void SendWho()
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("SentWho");
+ }
+
+ public void SelectInfected(int colorId, uint hatId)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("SelectInfected", new Dictionary<string, object>
+ {
+ {
+ "Color",
+ Telemetry.ColorNames[colorId]
+ },
+ {
+ "Hat",
+ DestroyableSingleton<HatManager>.Instance.GetHatById(hatId).name
+ }
+ });
+ }
+
+ public void WonGame(int colorId, uint hatId)
+ {
+ if (!SaveManager.SendTelemetry)
+ {
+ return;
+ }
+ if (!this.gameStarted)
+ {
+ return;
+ }
+ Analytics.CustomEvent("WonGame", new Dictionary<string, object>
+ {
+ {
+ "Color",
+ Telemetry.ColorNames[colorId]
+ },
+ {
+ "Hat",
+ DestroyableSingleton<HatManager>.Instance.GetHatById(hatId).name
+ }
+ });
+ }
+ }
+}