static void LogCSV() { string exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string playerCsvPath = Path.Combine(exePath, "player.csv"); string matchCsvPath = Path.Combine(exePath, "match.csv"); StringBuilder csv = new StringBuilder(); if (!File.Exists(playerCsvPath)) { csv.AppendLine(PlayerStat.GetFieldNames()); } csv.AppendLine(playerStat.ToString()); File.AppendAllText(playerCsvPath, csv.ToString()); csv.Clear(); if (!File.Exists(matchCsvPath)) { csv.AppendLine(MatchStat.GetFieldNames()); } foreach (MatchStat m in friendlyList) { csv.AppendLine(m.ToString()); } foreach (MatchStat m in enemyList) { csv.AppendLine(m.ToString()); } File.AppendAllText(matchCsvPath, csv.ToString()); LoggedMatch lm = new LoggedMatch { MatchHash = "", FriendlyMatchStats = friendlyList, EnemyMatchStats = enemyList, AssociationName = "PUG", PublishingUserName = (playerNameSet) ? ((playerName == null | playerName == "") ? "UNKNOWN" : playerName) : "UNKNOWN" }; httpPostLoggedMatch(lm); }
public static void HandleLevelLoad(byte[] buffer) { string s = ASCIIEncoding.ASCII.GetString(buffer); if (s == "mechlab") { if (matchActive) { if (friendlyList == null || enemyList == null || friendlyList.Count == 0 || enemyList.Count == 0) { return; } matchActive = false; foreach (MatchStat m in friendlyList) { if (m.status == 0) { allFriendsKilled = false; break; } } foreach (MatchStat m in enemyList) { if (m.status == 0) { allEnemiesKilled = false; break; } } if (allEnemiesKilled || allFriendsKilled) { playerStat.victoryType = "destruction"; } else { playerStat.victoryType = "capture"; } playerStat.time = matchEndTime; playerStat.matchType = activeMatchType; playerStat.level = activeLevelName; foreach (MatchStat m in friendlyList) { if (m.name == playerName) { playerStat.mech = m.mech; playerStat.status = m.status; } m.time = matchEndTime; m.victory = playerStat.victory; m.victoryType = playerStat.victoryType; m.level = activeLevelName; m.matchType = activeMatchType; } foreach (MatchStat m in enemyList) { if (playerStat.victory == 2) { m.victory = 1; } else if (playerStat.victory == 1) { m.victory = 2; } else { m.victory = playerStat.victory; //can this happen? no idea } m.time = matchEndTime; m.victoryType = playerStat.victoryType; m.level = activeLevelName; m.matchType = activeMatchType; } LogCSV(); //reset all variables in preparation for next match matchEndTime = DateTime.MaxValue; activeLevelName = ""; playerStat = new PlayerStat(); friendlyList.Clear(); enemyList.Clear(); allEnemiesKilled = true; allFriendsKilled = true; } } else { matchActive = true; activeLevelName = s; playerStat.level = s; } }
public static void HandleLevelLoad(byte[] buffer) { string s = ASCIIEncoding.ASCII.GetString(buffer); if (s == "mechlab") { if (matchActive) { if (friendlyList == null || enemyList == null || friendlyList.Count == 0 || enemyList.Count == 0) { return; } matchActive = false; foreach (MatchStat m in friendlyList) { if (m.status == 0) { allFriendsKilled = false; break; } } foreach (MatchStat m in enemyList) { if (m.status == 0) { allEnemiesKilled = false; break; } } if (allEnemiesKilled || allFriendsKilled) { playerStat.victoryType = "destruction"; } else { playerStat.victoryType = "capture"; } playerStat.time = matchEndTime; playerStat.matchType = activeMatchType; playerStat.level = activeLevelName; foreach (MatchStat m in friendlyList) { if (m.name == playerName) { playerStat.mech = m.mech; playerStat.status = m.status; } m.time = matchEndTime; m.victory = playerStat.victory; m.victoryType = playerStat.victoryType; m.level = activeLevelName; m.matchType = activeMatchType; } foreach (MatchStat m in enemyList) { if (playerStat.victory == 2) { m.victory = 1; } else if (playerStat.victory == 1) { m.victory = 2; } else { m.victory = playerStat.victory; } m.time = matchEndTime; m.victoryType = playerStat.victoryType; m.level = activeLevelName; m.matchType = activeMatchType; } LogCSV(); var matchStatsCompletedArgs = new MatchStatsCompletedArgs(); matchStatsCompletedArgs.MatchStats = friendlyList.Concat(enemyList).ToList(); onMatchStatsCompleted(matchStatsCompletedArgs); //reset all variables in preparation for next match matchEndTime = DateTime.MaxValue; activeLevelName = ""; team1.Clear(); team2.Clear(); playerStat = new PlayerStat(); friendlyList.Clear(); enemyList.Clear(); allEnemiesKilled = true; allFriendsKilled = true; } } else { matchActive = true; activeLevelName = s; playerStat.level = s; } //Log.LogMessage(string.Format("Level loading: {0}", s)); }