private static DailySteamUserInfo GetTodayInfo(SteamUser user, CustomDate nowCustomDate) { DailySteamUserInfo today = user.DailyInfos.FirstOrDefault(k => k.CustomDate == nowCustomDate); if (today != null) { return(today); } user.DailyInfos.Add(new DailySteamUserInfo(nowCustomDate)); today = user.DailyInfos.First(k => k.CustomDate == nowCustomDate); return(today); }
//private void SetRate() //{ // string currentDate = GetCustomDate(DateTime.Now); // var nowDateInfo = GetDate(currentDate); // var dateInfo = GetDate(UserConfig.StartTime); // var offsetY = dateInfo.Year; // var offsetM = dateInfo.Month; // while (offsetY < nowDateInfo.Year || // offsetY == nowDateInfo.Year && offsetM <= nowDateInfo.Month) // { // string key = GetCustomDate(new DateInfo(offsetY, offsetM)); // double total = UserConfig.SteamUsers.Select(k => // (double)k.DailyInfos[key].SupportedYuan / k.DailyInfos[key].OnlineTime).Sum(); // foreach (var user in UserConfig.SteamUsers) // { // user.DailyInfos[key].Rate = // ((double)user.DailyInfos[key].SupportedYuan / user.DailyInfos[key].OnlineTime) / total; // } // offsetM++; // if (offsetM == 13) // { // offsetM = 1; // offsetY += 1; // } // } //} private static void UpdateDisconnectInfo(SteamUser user) { user.LastDisconnect = DateTime.Now; user.IsOnline = false; var date = new CustomDate(DateTime.Now); var time = user.LastDisconnect - user.LastConnect; if (time != null) { DailySteamUserInfo todayinfo = GetTodayInfo(user, date); todayinfo.OnlineTime += time.Value.TotalMinutes; } Console.WriteLine($"OFFLINE: {user.CurrentName} ({user.SteamUid}) {user.LastDisconnect}"); }
private bool DetectFriendlyFire(string source) { const string blackKey1 = ": [l4d_ff_tracker.smx] STEAM_"; const string blackKey2 = " => "; var blackI1 = source.IndexOf(blackKey1, StringComparison.Ordinal); if (blackI1 == -1) { return(false); } var blackI2 = source.IndexOf(blackKey2, StringComparison.Ordinal); if (blackI2 == -1) { return(false); } var steamUid = source.Substring(blackKey1.Length + blackI1 - 6, blackI2 - (blackKey1.Length + blackI1 - 6)); var user = UserConfig.SteamUsers.FirstOrDefault(k => k.SteamUid == steamUid && k.IsOnline); bool isValid = false; if (user == null) { return(false); } var info = source.Substring(blackI2 + 4); var infoArray = info.Split(" [").Select(k => k.Trim(']')).ToArray(); string botOrUid = infoArray[0]; string weapon = infoArray[1]; int damage = int.Parse(infoArray[2].Split(' ')[0]); bool isBot = botOrUid == "BOT"; SteamUser user2 = null; if (!isBot) { user2 = UserConfig.SteamUsers.FirstOrDefault(k => k.SteamUid == botOrUid && k.IsOnline); if (user2 != null) { isValid = true; } } else { Console.WriteLine($"FF: {user.CurrentName} =({weapon})> BOT [{damage} HP]"); } if (!isValid) { return(false); } var nowCustomDate = new CustomDate(DateTime.Now); DailySteamUserInfo user1Today = GetTodayInfo(user, nowCustomDate); //user1 today info (create if not exist) DailySteamUserInfo user2Today = GetTodayInfo(user2, nowCustomDate); //user2 today info GetWeapon(weapon, user1Today.WeaponInfos).Damage += damage; //1 damage (create if not exist) GetWeapon(weapon, user2Today.WeaponInfos).Hurt += damage; //2 hurt GetWeapon(weapon, user1Today.WeaponInfos).DamageTimes += 1; //1 damage count GetWeapon(weapon, user2Today.WeaponInfos).HurtTimes += 1; //2 hurt count Console.WriteLine($"FF: {user.CurrentName} =({weapon})> {user2.CurrentName} [{damage} HP]"); return(true); }