private static void TelemetryManagerCustomContentInfo(int buildingsCount, int propsCount, int treeCount, int vehicleCount)
        {
            UpdateActiveModCount();

            try
            {
                Telemetry        telemetry = new Telemetry();
                Telemetry.Pair[] infoPair  = new Telemetry.Pair[] { new Telemetry.Pair("buildings", buildingsCount), new Telemetry.Pair("props", propsCount), new Telemetry.Pair("trees", treeCount), new Telemetry.Pair("vehicles", vehicleCount) };
                telemetry.AddEvent("custom_content", infoPair);
                DebugUtils.Log("Sending telemetry with " + m_ActiveModCount + " mods active");
                Telemetry.Pair[] pairArray2 = new Telemetry.Pair[] { new Telemetry.Pair("enabledModCount", m_ActiveModCount), new Telemetry.Pair("modCount", Singleton <PluginManager> .instance.modCount) };
                telemetry.AddEvent("custom_mods", pairArray2);
                telemetry.Push();
                IEnumerator <PluginManager.PluginInfo> enumerator = Singleton <PluginManager> .instance.GetPluginsInfo().GetEnumerator();

                try
                {
                    while (enumerator.MoveNext())
                    {
                        PluginManager.PluginInfo current = enumerator.Current;
                        if (current.isEnabled)
                        {
                            Telemetry        telemetry2 = new Telemetry();
                            Telemetry.Pair[] pairArray3 = new Telemetry.Pair[] { new Telemetry.Pair("modName", current.name), new Telemetry.Pair("modWorkshopID", !(current.publishedFileID != PublishedFileId.invalid) ? "none" : current.publishedFileID.ToString()), new Telemetry.Pair("assemblyInfo", current.assembliesString) };
                            telemetry2.AddEvent("mod_used", pairArray3);
                            telemetry2.Push();
                        }
                    }
                }
                finally
                {
                    if (enumerator == null)
                    {
                    }
                    enumerator.Dispose();
                }
            }
            catch (Exception ex)
            {
                DebugUtils.Log(ex.Message);
                //CODebugBase<LogChannel>.Warn(LogChannel.HTTP, exception.GetType() + ": Telemetry event failed " + exception.Message);
            }
        }
Exemple #2
0
        public void Push()
        {
            if (Mod.DEBUG_LOG_LEVEL > 1)
            {
                Helper.dbgLog("Push triggered. " + DateTime.Now.ToString());
            }
            Hashtable hashtables = new Hashtable();

            if (Account.currentAccount == null)
            {
                hashtables.Add("userid", PlatformService.userID.ToString());
                if (PlatformService.apiBackend == APIBackend.Steam)
                {
                    hashtables.Add("universe", "steam");
                }
                else if (PlatformService.apiBackend == APIBackend.Rail)
                {
                    if (PlatformService.platformType == PlatformType.TGP)
                    {
                        hashtables.Add("universe", "tgp");
                    }
                    else if (PlatformService.platformType == PlatformType.QQGame)
                    {
                        hashtables.Add("universe", "qq");
                    }
                }
            }
            else
            {
                hashtables.Add("userid", Account.currentAccount.id);
                hashtables.Add("universe", "accounts");
            }

            hashtables.Add("game", DataLocation.productName.ToLower());
            hashtables.Add("steamid", PlatformService.userID.ToString());
            ArrayList arrayLists = new ArrayList();

            foreach (KeyValuePair <string, List <Telemetry.Pair> > mDatum in this.m_Data)
            {
                int       num  = (this.IsStandardTelemetry(mDatum.Key) ? 3 : 6);
                Hashtable item = null;
                if (mDatum.Value.Count != 0)
                {
                    for (int i = 0; i < mDatum.Value.Count; i++)
                    {
                        if (i % num == 0)
                        {
                            item = new Hashtable()
                            {
                                { "event", mDatum.Key }
                            };
                            DateTime universalTime = DateTime.Now.ToUniversalTime();
                            item.Add("timestamp", universalTime.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
                            arrayLists.Add(item);
                        }
                        Telemetry.Pair pair = mDatum.Value[i];
                        item[pair.key] = mDatum.Value[i].@value;
                    }
                }
                else
                {
                    item = new Hashtable()
                    {
                        { "event", mDatum.Key }
                    };
                    DateTime dateTime = DateTime.Now.ToUniversalTime();
                    item.Add("timestamp", dateTime.ToString("yyyy-MM-ddTHH:mm:ss.fff"));
                    arrayLists.Add(item);
                }
            }
            hashtables.Add("data", arrayLists);



            if (Helper.HasTelemFlag(Mod.config.TelemetryLevel, Helper.TelemOption.DisableAll) ||
                Helper.HasTelemFlag(Mod.config.TelemetryLevel, Helper.TelemOption.NoOpThePush))
            {
                if (Mod.DEBUG_LOG_ON)
                {
                    Helper.dbgLog("NoOp'd the Push and clearing the hashtables.  \r\n" + JSON.JsonEncode(hashtables));
                }

                this.Clear();
                return;
            }

            if (Telemetry.debug || Helper.HasTelemFlag(Mod.config.TelemetryLevel, Helper.TelemOption.EnableAllButLogToFileInstead))
            {
                if (Mod.DEBUG_LOG_ON)
                {
                    Helper.dbgLog("Dumping telemetry to log enabled:");
                }
                Helper.dbgLog("logging data that would be pushed:\n" + JSON.JsonEncode(hashtables));
                this.Clear();
                return;
            }
            if (Mod.DEBUG_LOG_ON)
            {
                Helper.dbgLog("debug mode, Pushing data.  :\r\n" + JSON.JsonEncode(hashtables));
            }
            Request request2 = new Request("post", Telemetry.paradoxApiURL, hashtables);

            request2.Send(delegate(Request request)
            {
                this.Clear();
            });
        }