public async Task <BasePlayer> LetmePlay(SEplayer sepl) { if (sepl != null) { if (!MMplayers.ContainsKey(sepl.Name)) { MMplayer mm = new MMplayer(sepl); MMplayers.TryAdd(sepl.Name, mm); } else { ExitQ(sepl.Name); MMplayers[sepl.Name].Mode = sepl.Mode; MMplayers[sepl.Name].Mode2 = sepl.Mode2; MMplayers[sepl.Name].Server = sepl.Server; MMplayers[sepl.Name].Random = sepl.Random; } lock (QMMplayers) { QMMplayers.Add(MMplayers[sepl.Name]); } Save(); return(new BasePlayer(MMplayers[sepl.Name])); } else { return(null); } }
public async Task <string> Deleteme(string name) { ExitQ(name); if (MMplayers.ContainsKey(name)) { MMplayer mm = new MMplayer(); MMplayers.TryRemove(name, out mm); Save(); } return("Ok."); }
public async Task <string> Random(string name) { if (MMplayers.ContainsKey(name)) { MMplayers[name].Random = !MMplayers[name].Random; if (MMplayers[name].Random == true) { MMplayers[name].Ticks = 0; } } return("Ok."); }
public async Task <string> ExitQ(string name) { if (MMplayers.ContainsKey(name)) { if (QMMplayers.Contains(MMplayers[name])) { if (MMplayers[name].Lobby.ContainsKey(MMplayers[name])) { foreach (var pl in MMplayers[name].Lobby.Keys) { lock (MMplayers[pl.Name]) { byte zero = 0; MMplayers[pl.Name].Lobby.TryRemove(MMplayers[name], out zero); } } } lock (QMMplayers) { QMMplayers.Remove(MMplayers[name]); } } ResetMMplayer(name); } // fail safe foreach (var lobby in Lobby.Values) { lock (lobby) { foreach (var pl in lobby) { if (pl.Key.Name == name) { byte zero = 0; lobby.TryRemove(MMplayers[name], out zero); } } } } return("Ok"); }
public StartUp(DbContextOptions <MMdb> mmdb) { _mmdb = mmdb; _db = new MMdb(_mmdb); foreach (string cmdr in DSdata.s_races) { MMraces.TryAdd(cmdr, new MMplayerNG(cmdr)); } /** * using (var db = new MMdb(_mmdb)) * { * foreach (var ent in db.MMdbPlayers) * db.MMdbPlayers.Remove(ent); * foreach (var ent in db.MMdbRatings) * db.MMdbRatings.Remove(ent); * foreach (var ent in db.MMdbRaceRatings) * db.MMdbRaceRatings.Remove(ent); * * db.SaveChanges(); * } **/ // /** using (var db = new MMdb(_mmdb)) { foreach (var ent in db.MMdbPlayers) { MMplayers[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRaces) { MMraces[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRatings.OrderBy(o => o.Games)) { if (MMplayers.ContainsKey(ent.MMdbPlayer.Name)) { if (MMplayers[ent.MMdbPlayer.Name].AuthName == ent.MMdbPlayer.AuthName) { MMplayers[ent.MMdbPlayer.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } foreach (var ent in db.MMdbRaceRatings.OrderBy(o => o.Games)) { if (MMraces.ContainsKey(ent.MMdbRace.Name)) { MMraces[ent.MMdbRace.Name].Rating[ent.Lobby].Add(new MMPlRating(ent)); } } } // **/ foreach (string name in MMplayers.Keys) { if (MMplayers[name].AuthName != null && MMplayers[name].AuthName != "") { Players.Add(MMplayers[name].Name); Auth.Add(MMplayers[name].AuthName, MMplayers[name].Name); } } if (!File.Exists(Program.myJson_file)) { File.Create(Program.myJson_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myJson_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { //rep.Init(); repHash.Add(rep.HASH); if (!replays.ContainsKey(rep.ID)) { replays[rep.ID] = new List <dsreplay>(); } replays[rep.ID].Add(rep); } } if (!File.Exists(Program.myReplays_file)) { File.Create(Program.myReplays_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myReplays_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { MyReplays.Add(rep); } } string exedir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); Exedir = exedir; foreach (var file in Directory.EnumerateFiles(Program.replaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var file in Directory.EnumerateFiles(Program.myreplaydir)) { string dest = exedir + "/replays/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } foreach (var dir in Directory.EnumerateDirectories(Program.workdir + "/tournaments")) { string tourny = Path.GetFileName(dir); if (File.Exists(dir + "/treplays.json")) { TournamentReplays.Add(tourny, new List <dsreplay>()); foreach (var line in File.ReadAllLines(dir + "/treplays.json")) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { TournamentReplays[tourny].Add(rep); } } if (!Directory.Exists(Exedir + "/treplays/" + tourny)) { Directory.CreateDirectory(Exedir + "/treplays/" + tourny); } foreach (var file in Directory.EnumerateFiles(dir + "/replays")) { string dest = Exedir + "/treplays/" + tourny + "/" + Path.GetFileName(file); if (!File.Exists(dest)) { File.Copy(file, dest); } } } if (File.Exists(dir + "/info.json")) { TournamentInfo t = JsonSerializer.Deserialize <TournamentInfo>(File.ReadAllText(dir + "/info.json")); TournamentInfo[tourny] = t; } } foreach (var file in Directory.EnumerateFiles(Program.commentdir)) { GameComment com = JsonSerializer.Deserialize <GameComment>(File.ReadAllText(file)); if (com != null) { GameComments[com.RepId] = com; } } // ladder init //LadderInit(); }
public async Task <MMgame> Report(dsreplay replay, string id) { MMgame mmgame = new MMgame(); int gid = int.Parse(id); if (Replays.ContainsKey(gid)) { Replays[gid].Add(replay); } else { Replays.TryAdd(gid, new ConcurrentBag <dsreplay>()); Replays[gid].Add(replay); } Save(Games[gid], replay); lock (Games) { if (Games.ContainsKey(gid)) { if (Games[gid].Reported == true) { return(Games[gid]); } } replay.GenHash(); if (ReplayHash.Contains(replay.HASH)) { //return null; } else { ReplayHash.Add(replay.HASH); } List <MMplayer> team1 = new List <MMplayer>(); List <MMplayer> team2 = new List <MMplayer>(); foreach (var pl in replay.PLAYERS) { MMplayer mmpl = new MMplayer(); if (MMplayers.ContainsKey(pl.NAME)) { mmpl = MMplayers[pl.NAME]; } else { mmpl.Name = "Dummy"; } if (pl.TEAM == replay.WINNER) { team1.Add(mmpl); } else { team2.Add(mmpl); } } MMgame repgame = new MMgame(); repgame = MMrating.RateGame(team1, team2); repgame.ID = Games[gid].ID; repgame.Quality = Games[gid].Quality; repgame.Server = Games[gid].Server; repgame.Reported = true; Games[gid] = repgame; } Save(); return(Games[gid]); }
public StartUp(DbContextOptions <MMdb> mmdb) { _mmdb = mmdb; foreach (string cmdr in DSdata.s_races) { MMraces.TryAdd(cmdr, new MMplayerNG(cmdr)); } /** * using (var db = new MMdb(_mmdb)) * { * foreach (var ent in db.MMdbPlayers) * db.MMdbPlayers.Remove(ent); * foreach (var ent in db.MMdbRatings) * db.MMdbRatings.Remove(ent); * foreach (var ent in db.MMdbRaceRatings) * db.MMdbRaceRatings.Remove(ent); * * db.SaveChanges(); * } **/ // /** using (var db = new MMdb(_mmdb)) { foreach (var ent in db.MMdbPlayers) { MMplayers[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRaces) { MMraces[ent.Name] = new MMplayerNG(ent); } foreach (var ent in db.MMdbRatings) { if (MMplayers.ContainsKey(ent.MMdbPlayer.Name)) { if (MMplayers[ent.MMdbPlayer.Name].AuthName == ent.MMdbPlayer.AuthName) { MMplayers[ent.MMdbPlayer.Name].Rating[ent.Lobby] = new MMPlRating(ent); } } } foreach (var ent in db.MMdbRaceRatings) { if (MMraces.ContainsKey(ent.MMdbRace.Name)) { MMraces[ent.MMdbRace.Name].Rating[ent.Lobby] = new MMPlRating(ent); } } } // **/ foreach (string name in MMplayers.Keys) { if (MMplayers[name].AuthName != null && MMplayers[name].AuthName != "") { Players.Add(MMplayers[name].Name); Auth.Add(MMplayers[name].AuthName, MMplayers[name].Name); } } if (!File.Exists(Program.myJson_file)) { File.Create(Program.myJson_file).Dispose(); } foreach (var line in File.ReadAllLines(Program.myJson_file)) { dsreplay rep = null; try { rep = JsonSerializer.Deserialize <dsreplay>(line); } catch { } if (rep != null) { //rep.Init(); repHash.Add(rep.HASH); if (!replays.ContainsKey(rep.ID)) { replays[rep.ID] = new List <dsreplay>(); } replays[rep.ID].Add(rep); } } // ladder init /** * Save(); * List<string> LadderGames = new List<string>(); * if (File.Exists(Program.ladder_file)) * { * LadderGames = JsonSerializer.Deserialize<List<string>>(File.ReadAllText(Program.ladder_file)); * } * foreach (var ent in LadderGames) * { * MMgameNG game; * MMgameNG racegame; * (game, racegame) = MMrating.RateGame(ent, "Commander3v3True", this); * Save(); * Save(game); * SaveRace(racegame); * } **/ }