// This parses a grid. Each game will be a column; each team will be a row. Each character in the grid is a letter // representing that team's colour in that game, or is a non-colour character if that team does not play in that game. public string[] Parse(string[] lines, FixtureTeams teams, DateTime?firstGame, TimeSpan?duration) { int minLength = int.MaxValue; for (int row = 0; row < lines.Length && row < teams.Count; row++) { int pos = lines[row].LastIndexOf('\t'); while (pos > -1) { lines[row] = lines[row].Remove(pos, 1); pos = lines[row].LastIndexOf('\t'); } minLength = Math.Min(minLength, lines[row].Length); } if (minLength < int.MaxValue) { for (int col = 0; col < minLength; col++) { var game = new FixtureGame(); for (int row = 0; row < lines.Length && row < teams.Count; row++) { Colour colour = ColourExtensions.ToColour(lines[row][col]); if (colour != Colour.None) { game.Teams.Add(teams[row], colour); } else if (colour == Colour.None && char.IsLetter(lines[row][col])) { game.Teams.Add(teams[row], Colour.None); } } if (firstGame != null) { game.Time = (DateTime)firstGame; firstGame += duration ?? TimeSpan.Zero; } Add(game); } } if (firstGame != null) { Sort(); } return(lines); }
public override void PopulateGame(ServerGame game) { if (!Connected) { return; } game.Players = new List <ServerPlayer>(); string sql = "SELECT MAT.colourTeam AS [Colour], MP.score, U.[desc] AS [Pack_Name], " + "cast(C.region as varchar) + '-' + cast(C.site as varchar) + '-' + cast(Member.id as varchar) as [Player_ID], " + "Member.codename AS [Alias], MAT.[desc] AS [Team] " + "FROM MissionPlayer MP " + "LEFT JOIN Unit U ON U.ref = MP.unit " + "LEFT JOIN Member ON Member.ref = MP.member " + "LEFT JOIN Centre C ON C.ref = Member.centre " + "LEFT JOIN Mission ON Mission.ref = MP.mission " + "LEFT JOIN MissionType MT ON MT.ref = Mission.type " + "LEFT JOIN MissionAlignmentTeam MAT ON MAT.alignment = MT.alignment AND MAT.seq = MP.team " + "WHERE Mission.ref = " + game.GameId.ToString() + " AND unitType = 0 " + "ORDER BY score DESC"; var cmd = new SqlCommand(sql, connection); SqlDataReader reader = cmd.ExecuteReader(); try { while (reader.Read()) { ServerPlayer player = new ServerPlayer { Colour = ColourExtensions.ToColour(reader.GetInt32(0)), Score = reader.GetInt32(1), Pack = reader.GetString(2) }; if (!reader.IsDBNull(3)) { player.PlayerId = reader.GetString(3); } if (!reader.IsDBNull(4)) { player.Alias = reader.GetString(4); } player.ServerPlayerId = player.Alias; game.Players.Add(player); } } finally { reader.Close(); } if (string.IsNullOrEmpty(LogFolder) || !Directory.Exists(LogFolder)) { return; } var files = new DirectoryInfo(LogFolder).GetFiles(game.Time.ToString("HHmm") + " - *.txt"); if (files.Length > 0) { var file = files[0].OpenText(); game.Events.Clear(); while (!file.EndOfStream) { // Line format: number of milliseconds elapsed in game [tab] event code [tab] teamcolour:playeralias [tab] event description [tab] teamcolour:playeralias var line = file.ReadLine().Split('\t'); var oneEvent = new Event { Time = game.Time.AddMilliseconds(int.Parse(line[0])) }; string eventType = line[1]; if (eventType.StartsWith("01")) { continue; } oneEvent.Event_Type = ParseEventType(line[1]); oneEvent.Score = EventToScore(oneEvent.Event_Type); SplitPlayer(line[2], out oneEvent.ServerTeamId, out oneEvent.ServerPlayerId); if (line.Length > 4) { SplitPlayer(line[4], out oneEvent.OtherTeam, out oneEvent.OtherPlayer); } if (eventType.StartsWith("0B")) { oneEvent.ShotsDenied = 1; } game.Events.Add(oneEvent); if (eventType.StartsWith("02")) // The event is a player hitting another player. Let's create a complementary event to record that same hit from the other player's perspective. { game.Events.Add(new Event { Time = oneEvent.Time, Event_Type = oneEvent.Event_Type + 14, Score = -40, ServerTeamId = oneEvent.OtherTeam, ServerPlayerId = oneEvent.OtherPlayer, OtherTeam = oneEvent.ServerTeamId, OtherPlayer = oneEvent.ServerPlayerId }); } } } }