private void playButton_Click(object sender, EventArgs e) { string[] param = this.addressBox.Text.Split(':'); UDPStream str = new UDPStream(System.Net.IPAddress.Any, System.Net.IPAddress.Parse(param[0]), int.Parse(param[1])); this.player = DSPlayer.PlayMPEG2_TS(str, this.videoBox.Checked, this.audioBox.Checked); this.playButton.Enabled = false; }
public override IEnumerable <object> Run() { if (this.service.DSWaitingSystem != null) { DSPlayer player = this.service.DSWaitingSystem.DSPlayerDict.TryGetValue <long, DSPlayer>(this.Operation.CID); if (player != null && this.Operation.Status == DSPlayerStatus.InShip) { player.EnterShip(); this.Finished = true; yield return((object)new OkMessage()); yield break; } } this.Finished = true; yield return((object)new FailMessage("[UpdateDSPlayerInfoProcessor] service.DSWaitingSystem")); }
public async Task <bool> GetAutoFile(string id, string myfile) { DSRestPlayer player = _context.DSRestPlayers.Include(p => p.Uploads).FirstOrDefault(f => f.Name == id); if (player == null) { return(false); } player.LastUpload = DateTime.UtcNow; string mypath = SharedDir + "/" + id; string mysum = SharedDir + "/sum/" + id + ".json"; if (!Directory.Exists(mypath)) { try { Directory.CreateDirectory(mypath); } catch (Exception e) { _logger.LogError("Could not create directory " + mypath + " " + e.Message); return(false); } } if (File.Exists(myfile)) { if (!File.Exists(mysum)) { File.Create(mysum).Dispose(); } string myjson = ""; return(await Task.Run(() => myjson = Decompress(new FileInfo(myfile), mypath, id, _logger)) .ContinueWith(task => { if (myjson == "") { return false; } if (File.Exists(myjson) && new FileInfo(myjson).Length > 0) { using (StreamWriter sw = File.AppendText(mysum)) { foreach (string line in File.ReadLines(myjson)) { if (!line.StartsWith(@"{")) { return false; } sw.WriteLine(line); dsreplay replay = null; try { replay = JsonSerializer.Deserialize <dsreplay>(line); if (replay != null) { DSReplay dsreplay = Map.Rep(replay); DSPlayer dsplayer = dsreplay.DSPlayer.FirstOrDefault(f => f.NAME == "player"); if (dsplayer != null) { dsplayer.NAME = id; } dsreplay.Upload = player.LastUpload; DSReplays.Add(dsreplay); player.Data++; } } catch (Exception e) { _logger.LogError("Could not Deserialize and map replay " + e.Message); } } } DSRestUpload upload = new DSRestUpload(); upload.Upload = player.LastUpload; upload.DSRestPlayer = player; _context.DSRestUploads.Add(upload); DSinfo info = Infos.FirstOrDefault(f => f.Key == id).Value; if (info != null) { DateTime LastRep = DateTime.MinValue; if (info.LastRep.Length == 14) { int year = int.Parse(info.LastRep.Substring(0, 4)); int month = int.Parse(info.LastRep.Substring(4, 2)); int day = int.Parse(info.LastRep.Substring(6, 2)); int hour = int.Parse(info.LastRep.Substring(8, 2)); int min = int.Parse(info.LastRep.Substring(10, 2)); int sec = int.Parse(info.LastRep.Substring(12, 2)); LastRep = new DateTime(year, month, day, hour, min, sec); } player.LastRep = LastRep; player.Json = info.Json; player.Total = info.Total; player.Version = info.Version; } lock (dblock) { _context.SaveChanges(); } InsertDSReplays(); return true; } else { return false; } })); } else { return(false); } }
public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring) { DbBreakpoint Bp = new DbBreakpoint(); Bp.Player = pl; Bp.Gas = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count(); Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15); DbStats statlast = null; foreach (DbStats stat in pl.Stats) { if (stat.Gameloop > bp) { break; } statlast = stat; } if (statlast != null) { Bp.Army = statlast.Army; Bp.Kills = statlast.MineralsKilledArmy; Bp.Upgrades = statlast.MineralsUsedCurrentTechnology; } List <DbUnit> dbUnits = null; foreach (var ent in pl.Spawns) { if (ent.Gameloop > bp) { break; } dbUnits = ent.Units.ToList(); } Bp.Units = new List <DSUnit>(); Bp.DbUnits = new List <DbUnit>(); if (dbUnits != null) { foreach (DbUnit unit in dbUnits) { DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name); if (dsUnit == null) { DSUnit newdsUnit = new DSUnit(); newdsUnit.Name = unit.Name; newdsUnit.BP = bpstring; newdsUnit.Breakpoint = Bp; newdsUnit.Count = 1; newdsUnit.DSPlayer = pl; Bp.Units.Add(newdsUnit); } else { dsUnit.Count++; } unit.Breakpoint = Bp; Bp.DbUnits.Add(unit); } } Bp.DbUpgrades = new List <DbUpgrade>(); foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp)) { upgrade.Breakpoint = Bp; Bp.DbUpgrades.Add(upgrade); } string dsUnitsString = ""; string dbUnitsString = ""; string dbUpgradesString = ""; foreach (DSUnit unit in Bp.Units) { string name = unit.Name; UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name); if (bunit != null) { name = bunit.ID.ToString(); } dsUnitsString += name + "," + unit.Count + "|"; } if (dsUnitsString.Any()) { dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1); } foreach (DbUnit unit in Bp.DbUnits) { string name = unit.Name; UnitModelBase bunit = DSdata.Units.FirstOrDefault(s => s.Race == pl.RACE && s.Name == unit.Name); if (bunit != null) { name = bunit.ID.ToString(); } dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|"; } if (dbUnitsString.Any()) { dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1); } foreach (DbUpgrade upgrade in Bp.DbUpgrades) { dbUpgradesString += upgrade.Upgrade + "|"; } if (dbUpgradesString.Any()) { dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1); } Bp.dsUnitsString = dsUnitsString; Bp.dbUnitsString = dbUnitsString; Bp.dbUpgradesString = dbUpgradesString; return(Bp); }
public static void Replay(DSReplay replay, bool GetDetails) { int maxleaver = 0; int maxkillsum = 0; int minkillsum = -1; int minarmy = -1; int minincome = -1; FixPos(replay); Dictionary <string, double> Breakpoints = new Dictionary <string, double>(DSdata.BreakpointMid); Breakpoints["ALL"] = replay.DURATION * 22.4; foreach (var ent in Breakpoints.Keys.ToArray()) { if (ent == "ALL") { continue; } if (Breakpoints[ent] >= Breakpoints["ALL"]) { Breakpoints.Remove(ent); } } foreach (DSPlayer pl in replay.DSPlayer) { int opppos = DBFunctions.GetOpp(pl.REALPOS); DSPlayer opp = replay.DSPlayer.SingleOrDefault(s => s.REALPOS == opppos); if (opp != null) { pl.OPPRACE = opp.RACE; } if (pl.TEAM == replay.WINNER) { pl.WIN = true; } if (pl.Stats.Any()) { pl.KILLSUM = pl.Stats.OrderBy(o => o.Gameloop).Last().MineralsKilledArmy; } else { pl.KILLSUM = 0; } pl.INCOME = (int)pl.Stats.Sum(s => s.MineralsCollectionRate / 9.15); foreach (DbRefinery r in pl.Refineries.ToArray()) { if (r.Gameloop == 0) { pl.Refineries.Remove(r); } } pl.GAS = (byte)pl.Refineries.Count(); int diff = replay.DURATION - pl.PDURATION; if (diff > maxleaver) { maxleaver = diff; } if (pl.KILLSUM > maxkillsum) { maxkillsum = pl.KILLSUM; } if (minkillsum == -1) { minkillsum = pl.KILLSUM; } else { if (pl.KILLSUM < minkillsum) { minkillsum = pl.KILLSUM; } } if (minarmy == -1) { minarmy = pl.ARMY; } else { if (pl.ARMY < minarmy) { minarmy = pl.ARMY; } } if (minincome == -1) { minincome = pl.INCOME; } else { if (pl.INCOME < minincome) { minincome = pl.INCOME; } } string urace = pl.RACE; if (pl.RACE == "Zagara" || pl.RACE == "Abathur" || pl.RACE == "Kerrigan") { urace = "Zerg"; } else if (pl.RACE == "Alarak" || pl.RACE == "Artanis" || pl.RACE == "Vorazun" || pl.RACE == "Fenix" || pl.RACE == "Karax") { urace = "Protoss"; } else if (pl.RACE == "Raynor" || pl.RACE == "Swann" || pl.RACE == "Nova" || pl.RACE == "Stukov") { urace = "Terran"; } HashSet <string> doubles = new HashSet <string>(); foreach (DbUpgrade upgrade in pl.Upgrades.OrderBy(o => o.Gameloop).ToList()) { if (doubles.Contains(upgrade.Upgrade)) { pl.Upgrades.Remove(upgrade); continue; } doubles.Add(upgrade.Upgrade); UnitModelBase dupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == pl.RACE); if (dupgrade != null) { upgrade.Upgrade = dupgrade.ID.ToString(); } else { UnitModelBase udupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == urace); if (udupgrade != null) { upgrade.Upgrade = udupgrade.ID.ToString(); } else if (upgrade.Upgrade.StartsWith("Tier4WeaponUpgradeLevel")) { UnitModelBase tudupgrade = DSdata.Upgrades.FirstOrDefault(s => s.Name == upgrade.Upgrade && s.Race == ""); if (tudupgrade != null) { upgrade.Upgrade = tudupgrade.ID.ToString(); } } } } pl.Breakpoints = new List <DbBreakpoint>(); foreach (var ent in Breakpoints) { DbBreakpoint bp = GenBreakpoint(pl, (int)ent.Value, ent.Key); bp.Breakpoint = ent.Key; pl.Breakpoints.Add(bp); } } replay.MAXLEAVER = maxleaver; replay.MAXKILLSUM = maxkillsum; replay.MINKILLSUM = minkillsum; replay.MINARMY = minarmy; replay.MININCOME = minincome; FixWinner(replay); replay.HASH = GenHash(replay); using (var md5 = MD5.Create()) { string dirHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetDirectoryName(replay.REPLAYPATH)))).Replace("-", "").ToLowerInvariant(); string fileHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetFileName(replay.REPLAYPATH)))).Replace("-", "").ToLowerInvariant(); replay.REPLAY = dirHash + fileHash; } if (GetDetails == false) { foreach (DSPlayer pl in replay.DSPlayer) { pl.Stats.Clear(); pl.Stats = null; pl.Spawns.Clear(); pl.Spawns = null; pl.decUnits.Clear(); pl.decUnits = null; pl.Refineries.Clear(); pl.Refineries = null; pl.Upgrades.Clear(); pl.Upgrades = null; foreach (DbBreakpoint bp in pl.Breakpoints) { bp.Units.Clear(); bp.Units = null; bp.DbUnits.Clear(); bp.DbUnits = null; bp.DbUpgrades.Clear(); bp.DbUpgrades = null; } } } }
public static DbBreakpoint GenBreakpoint(DSPlayer pl, int bp, string bpstring) { DbBreakpoint Bp = new DbBreakpoint(); Bp.Player = pl; Bp.Gas = pl.Refineries.Where(x => x.Gameloop > 0 && x.Gameloop <= bp).Count(); Bp.Income = (int)pl.Stats.Where(x => x.Gameloop <= bp).Sum(s => s.MineralsCollectionRate / 9.15); DbStats statlast = pl.Stats.Where(x => x.Gameloop <= bp).LastOrDefault(); if (statlast != null) { Bp.Army = statlast.Army; Bp.Kills = statlast.MineralsKilledArmy; Bp.Upgrades = statlast.MineralsUsedCurrentTechnology; } List <DbUnit> dbUnits = null; var spawnlast = pl.Spawns.Where(x => x.Gameloop <= bp).LastOrDefault(); if (spawnlast != null) { dbUnits = spawnlast.Units.ToList(); } Bp.Units = new List <DSUnit>(); Bp.DbUnits = new List <DbUnit>(); if (dbUnits != null) { foreach (DbUnit unit in dbUnits) { DSUnit dsUnit = Bp.Units.FirstOrDefault(s => s.Name == unit.Name); if (dsUnit == null) { Bp.Units.Add(new DSUnit() { Name = unit.Name, BP = bpstring, Breakpoint = Bp, Count = 1, DSPlayer = pl }); } else { dsUnit.Count++; } unit.Breakpoint = Bp; Bp.DbUnits.Add(unit); } } Bp.DbUpgrades = new List <DbUpgrade>(); foreach (DbUpgrade upgrade in pl.Upgrades.Where(x => x.Breakpoint == null && x.Gameloop < bp)) { upgrade.Breakpoint = Bp; Bp.DbUpgrades.Add(upgrade); } string dsUnitsString = ""; string dbUnitsString = ""; string dbUpgradesString = ""; foreach (DSUnit unit in Bp.Units) { string name = unit.Name; int id = NameService.GetUnitId(null, unit.Name); if (id >= 0) { name = id.ToString(); } dsUnitsString += name + "," + unit.Count + "|"; } if (dsUnitsString.Any()) { dsUnitsString = dsUnitsString.Remove(dsUnitsString.Length - 1); } foreach (DbUnit unit in Bp.DbUnits) { string name = unit.Name; int id = NameService.GetUnitId(null, unit.Name); if (id >= 0) { name = id.ToString(); } dbUnitsString += name + "," + unit.BornX + "," + unit.BornY + "|"; } if (dbUnitsString.Any()) { dbUnitsString = dbUnitsString.Remove(dbUnitsString.Length - 1); } foreach (DbUpgrade upgrade in Bp.DbUpgrades) { dbUpgradesString += upgrade.Upgrade + "|"; } if (dbUpgradesString.Any()) { dbUpgradesString = dbUpgradesString.Remove(dbUpgradesString.Length - 1); } Bp.dsUnitsString = dsUnitsString; Bp.dbUnitsString = dbUnitsString; Bp.dbUpgradesString = dbUpgradesString; return(Bp); }
public static DSReplay Get(dynamic trackerevents_dec, DSReplay replay) { bool isBrawl_set = false; //bool noStagingAreaNextSpawn = true; bool noStagingAreaNextSpawn = false; if (replay.GAMETIME < new DateTime(2019, 03, 24, 21, 46, 15)) // 20190324214615 { noStagingAreaNextSpawn = true; } HashSet <string> Mutation = new HashSet <string>(); List <DbMiddle> Middle = new List <DbMiddle>(); Middle.Add(new DbMiddle(0, 0, replay)); replay.Middle = Middle; List <StagingAreaNextSpawn> stagingAreaNextSpawns = new List <StagingAreaNextSpawn>(); Vector2 ObjectivePlanetaryFortress = Vector2.Zero; Vector2 ObjectiveNexus = Vector2.Zero; Vector2 ObjectiveBunker = Vector2.Zero; Vector2 ObjectivePhotonCannon = Vector2.Zero; Vector2 Center = Vector2.Zero; KeyValuePair <Vector2, Vector2> LineT1 = new KeyValuePair <Vector2, Vector2>(Vector2.Zero, Vector2.Zero); KeyValuePair <Vector2, Vector2> LineT2 = new KeyValuePair <Vector2, Vector2>(Vector2.Zero, Vector2.Zero); int UnitID = 0; int LastSpawn = 480; int Winner = 0; foreach (PythonDictionary pydic in trackerevents_dec) { if (pydic.ContainsKey("m_unitTypeName")) //11998 { if (pydic.ContainsKey("m_controlPlayerId")) { int playerid = (int)pydic["m_controlPlayerId"]; int gameloop = (int)pydic["_gameloop"]; // Game end if (pydic["m_unitTypeName"].ToString().StartsWith("DeathBurst")) { replay.DURATION = (int)(gameloop / 22.4); if (playerid == 13) { replay.WINNER = 1; } else if (playerid == 14) { replay.WINNER = 0; } break; } // Objectives init if (gameloop == 0 && pydic.ContainsKey("m_creatorAbilityName") && (pydic["m_creatorAbilityName"] == null || pydic["m_creatorAbilityName"].ToString() == "")) { if (pydic["m_unitTypeName"].ToString() == "ObjectivePlanetaryFortress") { ObjectivePlanetaryFortress = new Vector2((int)pydic["m_x"], (int)pydic["m_y"]); } else if (pydic["m_unitTypeName"].ToString() == "ObjectiveNexus") { ObjectiveNexus = new Vector2((int)pydic["m_x"], (int)pydic["m_y"]); } else if (pydic["m_unitTypeName"].ToString() == "ObjectiveBunker") { ObjectiveBunker = new Vector2((int)pydic["m_x"], (int)pydic["m_y"]); } else if (pydic["m_unitTypeName"].ToString() == "ObjectivePhotonCannon") { ObjectivePhotonCannon = new Vector2((int)pydic["m_x"], (int)pydic["m_y"]); } if (ObjectiveBunker != Vector2.Zero && ObjectivePhotonCannon != Vector2.Zero && ObjectivePlanetaryFortress != Vector2.Zero && ObjectiveNexus != Vector2.Zero) { float x1t1 = ObjectivePlanetaryFortress.X + MathF.Cos(135 * MathF.PI / 180) * 100; float y1t1 = ObjectivePlanetaryFortress.Y + MathF.Sin(135 * MathF.PI / 180) * 100; float x2t1 = ObjectivePlanetaryFortress.X + MathF.Cos(315 * MathF.PI / 180) * 100; float y2t1 = ObjectivePlanetaryFortress.Y + MathF.Sin(315 * MathF.PI / 180) * 100; LineT1 = new KeyValuePair <Vector2, Vector2>(new Vector2(x1t1, y1t1), new Vector2(x2t1, y2t1)); float x1t2 = ObjectiveNexus.X + MathF.Cos(135 * MathF.PI / 180) * 100; float y1t2 = ObjectiveNexus.Y + MathF.Sin(135 * MathF.PI / 180) * 100; float x2t2 = ObjectiveNexus.X + MathF.Cos(315 * MathF.PI / 180) * 100; float y2t2 = ObjectiveNexus.Y + MathF.Sin(315 * MathF.PI / 180) * 100; LineT2 = new KeyValuePair <Vector2, Vector2>(new Vector2(x1t2, y1t2), new Vector2(x2t2, y2t2)); Center = new Vector2((ObjectiveNexus.X + ObjectivePlanetaryFortress.X) / 2, (ObjectiveNexus.Y + ObjectivePlanetaryFortress.Y) / 2); Objective obj = DSdata.Objectives.FirstOrDefault(x => x.Center == Center); if (obj == null) { obj = new Objective(); obj.Center = Center; obj.LineT1 = LineT1; obj.LineT2 = LineT2; obj.ObjectiveBunker = ObjectiveBunker; obj.ObjectiveNexus = ObjectiveNexus; obj.ObjectivePhotonCannon = ObjectivePhotonCannon; obj.ObjectivePlanetaryFortress = ObjectivePlanetaryFortress; DSdata.Objectives.Add(obj); obj.ID = DSdata.Objectives.Count; } replay.OBJECTIVE = obj.ID; } } if (playerid == 0 || playerid > 12) { continue; } // Player DSPlayer pl = replay.DSPlayer.SingleOrDefault(s => s.POS == playerid); if (pl == null) { pl = replay.DSPlayer.SingleOrDefault(s => s.WORKINGSETSLOT == playerid - 1); if (pl == null) { continue; } else { pl.POS = (byte)playerid; } } ; // Race if (gameloop < 1440) { Match m = rx_race2.Match(pydic["m_unitTypeName"].ToString()); if (m.Success && m.Groups[1].Value.Length > 0) { pl.RACE = m.Groups[1].Value; } } if (pydic.ContainsKey("m_creatorAbilityName")) { if (pydic["m_creatorAbilityName"] == null || pydic["m_creatorAbilityName"].ToString() == "") { if (gameloop == 0) { if (pydic["_event"].ToString() == "NNet.Replay.Tracker.SUnitBornEvent") { // Refineries init if (pydic["m_unitTypeName"].ToString().StartsWith("MineralField")) { int index = (int)pydic["m_unitTagIndex"]; int recycle = (int)pydic["m_unitTagRecycle"]; pl.Refineries.Add(new DbRefinery(gameloop, index, recycle, pl)); continue; } } } if (gameloop < 480) { continue; } if (noStagingAreaNextSpawn == false) { if (gameloop - LastSpawn >= 9) { continue; } } if (pydic["_event"].ToString() == "NNet.Replay.Tracker.SUnitBornEvent") { string born_unit = pydic["m_unitTypeName"].ToString(); bool isSpawnUnit = (born_unit switch { "TrophyRiftPremium" => true, "MineralIncome" => true, "ParasiticBombRelayDummy" => true, "Biomass" => true, "PurifierAdeptShade" => true, "PurifierTalisShade" => true, "HornerReaperLD9ClusterCharges" => true, "Broodling" => true, "Raptorling" => true, "InfestedLiberatorViralSwarm" => true, "SplitterlingSpawn" => true, "GuardianShell" => true, "BroodlingStetmann" => true, _ => false });
public static DSReplay Get(string replay_file, dynamic details_dec) { DSReplay replay = new DSReplay(); List <DSPlayer> Players = new List <DSPlayer>(); replay.REPLAYPATH = replay_file; int failsafe_pos = 0; foreach (var player in details_dec["m_playerList"]) { if (player["m_observe"] > 0) { continue; } failsafe_pos++; string name = ""; Bytes bab = null; try { bab = player["m_name"]; } catch { } if (bab != null) { name = Encoding.UTF8.GetString(bab.ToByteArray()); } else { name = player["m_name"].ToString(); } Match m2 = rx_subname.Match(name); if (m2.Success) { name = m2.Groups[1].Value; } DSPlayer pl = new DSPlayer(); pl.NAME = name; pl.RACE = player["m_race"].ToString(); pl.RESULT = byte.Parse(player["m_result"].ToString()); pl.TEAM = byte.Parse(player["m_teamId"].ToString()); pl.POS = (byte)failsafe_pos; if (player["m_workingSetSlotId"] != null) { pl.WORKINGSETSLOT = byte.Parse(player["m_workingSetSlotId"].ToString()); } pl.Stats = new List <DbStats>(); pl.Spawns = new List <DbSpawn>(); pl.Refineries = new List <DbRefinery>(); pl.Upgrades = new List <DbUpgrade>(); pl.DSReplay = replay; Players.Add(pl); } replay.PLAYERCOUNT = (byte)Players.Count; //long offset = (long)details_dec["m_timeLocalOffset"]; long timeutc = (long)details_dec["m_timeUTC"]; long georgian = timeutc; replay.GAMETIME = DateTime.FromFileTime(georgian); replay.GAMETIME = new DateTime(replay.GAMETIME.Year, replay.GAMETIME.Month, replay.GAMETIME.Day, replay.GAMETIME.Hour, replay.GAMETIME.Minute, replay.GAMETIME.Second, 0, replay.GAMETIME.Kind); replay.DSPlayer = Players; return(replay); }
// WebDatabase Replay // LocalDatabase Replay // DecodedReplay // OldReplay public static DSReplay Rep(dsreplay rep, string id = "player") { DSReplay dbrep = new DSReplay(); dbrep.REPLAYPATH = rep.REPLAY; using (var md5 = MD5.Create()) { string dirHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetDirectoryName(rep.REPLAY)))).Replace("-", "").ToLowerInvariant(); string fileHash = BitConverter.ToString(md5.ComputeHash(Encoding.UTF8.GetBytes(Path.GetFileName(rep.REPLAY)))).Replace("-", "").ToLowerInvariant(); dbrep.REPLAY = dirHash + fileHash; } string gametime = rep.GAMETIME.ToString(); int year = int.Parse(gametime.Substring(0, 4)); int month = int.Parse(gametime.Substring(4, 2)); int day = int.Parse(gametime.Substring(6, 2)); int hour = int.Parse(gametime.Substring(8, 2)); int min = int.Parse(gametime.Substring(10, 2)); int sec = int.Parse(gametime.Substring(12, 2)); DateTime gtime = new DateTime(year, month, day, hour, min, sec); dbrep.GAMETIME = gtime; dbrep.WINNER = (sbyte)rep.WINNER; TimeSpan d = TimeSpan.FromSeconds(rep.DURATION / 22.4); dbrep.DURATION = (int)d.TotalSeconds; dbrep.MINKILLSUM = rep.MINKILLSUM; dbrep.MAXKILLSUM = rep.MAXKILLSUM; dbrep.MINARMY = rep.MINARMY; dbrep.MININCOME = (int)rep.MININCOME; dbrep.PLAYERCOUNT = (byte)rep.PLAYERCOUNT; dbrep.REPORTED = (byte)rep.REPORTED; dbrep.ISBRAWL = rep.ISBRAWL; dbrep.GAMEMODE = rep.GAMEMODE; dbrep.VERSION = rep.VERSION; dbrep.MAXLEAVER = 0; List <DSPlayer> pls = new List <DSPlayer>(); foreach (dsplayer pl in rep.PLAYERS) { DSPlayer dbpl = new DSPlayer(); dbpl.POS = (byte)pl.POS; dbpl.REALPOS = (byte)pl.REALPOS; if (pl.NAME == "player") { dbpl.NAME = id; } else { dbpl.NAME = pl.NAME; } dbpl.RACE = pl.RACE; if (pl.TEAM == rep.WINNER) { dbpl.WIN = true; } dbpl.TEAM = (byte)pl.TEAM; dbpl.KILLSUM = pl.KILLSUM; dbpl.INCOME = (int)pl.INCOME; dbpl.PDURATION = (int)TimeSpan.FromSeconds(pl.PDURATION / 22.4).TotalSeconds; dbpl.ARMY = pl.ARMY; dbpl.GAS = (byte)pl.GAS; dsplayer opp = rep.GetOpp(pl.REALPOS); if (opp != null) { dbpl.OPPRACE = opp.RACE; } int diff = dbrep.DURATION - dbpl.PDURATION; if (diff > dbrep.MAXLEAVER) { dbrep.MAXLEAVER = diff; } dbpl.DSReplay = dbrep; pls.Add(dbpl); List <DbBreakpoint> bps = new List <DbBreakpoint>(); foreach (var bp in pl.UNITS.Keys) { DbBreakpoint dbbp = new DbBreakpoint(); dbbp.Breakpoint = bp; dbbp.dsUnitsString = ""; foreach (var name in pl.UNITS[bp].Keys) { if (name == "Gas") { dbbp.Gas = pl.UNITS[bp][name]; } else if (name == "Upgrades") { dbbp.Upgrades = pl.UNITS[bp][name]; } else if (name == "Mid") { dbbp.Mid = pl.UNITS[bp][name]; } else { UnitModelBase unit = DSdata.Units.FirstOrDefault(f => f.Race == pl.RACE && f.Name == Fix.UnitName(name)); if (unit != null) { dbbp.dsUnitsString += unit.ID + "," + pl.UNITS[bp][name] + "|"; } else { dbbp.dsUnitsString += name + "," + pl.UNITS[bp][name] + "|"; } } } if (!String.IsNullOrEmpty(dbbp.dsUnitsString)) { dbbp.dsUnitsString = dbbp.dsUnitsString.Remove(dbbp.dsUnitsString.Length - 1); } bps.Add(dbbp); } dbpl.Breakpoints = bps; } dbrep.DSPlayer = pls as ICollection <DSPlayer>; dbrep.HASH = dbrep.GenHash(); dbrep.Upload = DateTime.UtcNow; return(dbrep); }
public static DSReplay Rep(Dsreplays rep) { DSReplay dbrep = new DSReplay(); dbrep.REPLAY = rep.Replay; dbrep.REPLAYPATH = String.Empty; dbrep.GAMETIME = rep.Gametime; dbrep.WINNER = (sbyte)rep.Winner; dbrep.DURATION = (int)rep.Duration; dbrep.MINKILLSUM = rep.Minkillsum; dbrep.MAXKILLSUM = rep.Maxkillsum; dbrep.MINARMY = rep.Minarmy; dbrep.MININCOME = (int)rep.Minincome; dbrep.PLAYERCOUNT = (byte)rep.Playercount; dbrep.REPORTED = (byte)rep.Reported; dbrep.ISBRAWL = rep.Isbrawl; dbrep.GAMEMODE = rep.Gamemode; dbrep.VERSION = rep.Version; dbrep.MAXLEAVER = 0; List <DSPlayer> pls = new List <DSPlayer>(); foreach (Dsplayers pl in rep.Dsplayers) { DSPlayer dbpl = new DSPlayer(); dbpl.POS = (byte)pl.Pos; dbpl.REALPOS = (byte)pl.Realpos; dbpl.NAME = pl.Name; dbpl.RACE = pl.Race; if (pl.Team == rep.Winner) { dbpl.WIN = true; } dbpl.TEAM = (byte)pl.Team; dbpl.KILLSUM = pl.Killsum; dbpl.INCOME = (int)pl.Income; dbpl.PDURATION = (int)pl.Pduration; dbpl.ARMY = pl.Army; dbpl.GAS = (byte)pl.Gas; Dsplayers opp = GetOpp(pl.Realpos, rep); if (opp != null) { dbpl.OPPRACE = opp.Race; } int diff = dbrep.DURATION - (int)pl.Pduration; if (diff > dbrep.MAXLEAVER) { dbrep.MAXLEAVER = diff; } dbpl.DSReplay = dbrep; pls.Add(dbpl); List <DbBreakpoint> bps = new List <DbBreakpoint>(); foreach (var bp in DSdata.s_breakpoints) { DbBreakpoint dbbp = new DbBreakpoint(); dbbp.Breakpoint = bp; dbbp.dsUnitsString = ""; foreach (var runit in pl.Dsunits.Where(x => x.Bp == bp)) { if (runit.Name == "Gas") { dbbp.Gas = runit.Count; } else if (runit.Name == "Upgrades") { dbbp.Upgrades = runit.Count; } else if (runit.Name == "Mid") { dbbp.Mid = runit.Count; } else { UnitModelBase unit = DSdata.Units.FirstOrDefault(f => f.Race == pl.Race && f.Name == Fix.UnitName(runit.Name)); if (unit != null) { dbbp.dsUnitsString += unit.ID + "," + runit.Count + "|"; } else { dbbp.dsUnitsString += runit.Name + "," + runit.Count + "|"; } } } if (!String.IsNullOrEmpty(dbbp.dsUnitsString)) { dbbp.dsUnitsString = dbbp.dsUnitsString.Remove(dbbp.dsUnitsString.Length - 1); } bps.Add(dbbp); } dbpl.Breakpoints = bps; } dbrep.DSPlayer = pls as ICollection <DSPlayer>; dbrep.HASH = dbrep.GenHash(); dbrep.Upload = DateTime.UtcNow; return(dbrep); }