|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Runtime.Serialization; |
| 4 | +using UnityEngine; |
| 5 | + |
| 6 | +namespace REPOStats_Mod.Data |
| 7 | +{ |
| 8 | + public static class DanosStaticStore |
| 9 | + { |
| 10 | + public static long lastSentStats = 0; |
| 11 | + public static DanosStatsStore statsStore = new DanosStatsStore(); |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + public static void SendStatsToAPI() |
| 16 | + { |
| 17 | + if (CheckStatsStore()) |
| 18 | + { |
| 19 | + Debug.Log("Sending stats to API"); |
| 20 | + DanosStatSender.Instance.SendStats(statsStore); |
| 21 | + } |
| 22 | + |
| 23 | + Debug.Log("Resetting stats store"); |
| 24 | + ResetStatsStore(); |
| 25 | + lastSentStats = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); |
| 26 | + } |
| 27 | + |
| 28 | + public static bool CheckStatsStore() |
| 29 | + { |
| 30 | + if (statsStore == null) return false; |
| 31 | + if (statsStore.MySteamId <= 1000) return false; |
| 32 | + if (statsStore.RoundStarted <= 0) return false; |
| 33 | + if (statsStore.RoundEnded <= 0) return false; |
| 34 | + if (statsStore.RoundEnded < statsStore.RoundStarted) return false; |
| 35 | + |
| 36 | + return true; |
| 37 | + } |
| 38 | + |
| 39 | + public static void ResetStatsStore() |
| 40 | + { |
| 41 | + statsStore = new DanosStatsStore(); |
| 42 | + } |
| 43 | + |
| 44 | + public static void InitializeStatsStore() |
| 45 | + { |
| 46 | + ResetStatsStore(); |
| 47 | + string MySteamId = DanosUtils.GetMySteamID(); |
| 48 | + if (string.IsNullOrEmpty(MySteamId)) |
| 49 | + { |
| 50 | + Debug.LogError("Could not get my steam id"); |
| 51 | + return; |
| 52 | + } |
| 53 | + |
| 54 | + //Try parse the steam id as a long |
| 55 | + if (!long.TryParse(MySteamId, out long steamId)) |
| 56 | + { |
| 57 | + Debug.LogError("Could not parse steam id as long"); |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + //Do the same for the host id |
| 62 | + string HostSteamId = DanosUtils.GetHostSteamID(); |
| 63 | + Debug.Log("Host: " + HostSteamId); |
| 64 | + if (string.IsNullOrEmpty(HostSteamId)) |
| 65 | + { |
| 66 | + Debug.LogError("Could not get host steam id"); |
| 67 | + return; |
| 68 | + } |
| 69 | + |
| 70 | + if (!long.TryParse(HostSteamId, out long hostSteamId)) |
| 71 | + { |
| 72 | + Debug.LogError("Could not parse host steam id as long"); |
| 73 | + return; |
| 74 | + } |
| 75 | + |
| 76 | + statsStore.MySteamId = steamId; |
| 77 | + statsStore.LobbyHash = DanosUtils.GetLobbyHash(); |
| 78 | + statsStore.isHost = steamId == hostSteamId; |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + statsStore.RoundStarted = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); |
| 83 | + statsStore.Deaths = new List<DanosDeathContainer>(); |
| 84 | + statsStore.RunStats = new(); |
| 85 | + |
| 86 | + RunManager runManager = RunManager.instance; |
| 87 | + if (runManager != null) |
| 88 | + { |
| 89 | + statsStore.LevelName = runManager.levelCurrent.name; |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | +} |
0 commit comments