Exemple #1
0
 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);
     }
 }
Exemple #2
0
        public MMrepository(ILogger <MMrepository> logger)
        {
            _logger = logger;

            if (File.Exists(data_json))
            {
                TextReader reader = new StreamReader(data_json, Encoding.UTF8);
                string     fileContents;
                while ((fileContents = reader.ReadLine()) != null)
                {
                    var player = JsonConvert.DeserializeObject <BasePlayer>(fileContents);
                    if (player != null && player.Name != null)
                    {
                        MMplayer pl = new MMplayer();
                        pl = new MMplayer(player);
                        MMplayers.TryAdd(player.Name, pl);
                    }
                }
                reader.Close();
            }
            _logger.LogInformation("Initialized MMplayers with {0} ents.", MMplayers.Count());

            foreach (var file in Directory.EnumerateFiles(WorkDir + "/games", "*_found.json"))
            {
                var   ent = Path.GetFileName(file);
                Match m   = rx_mmid.Match(ent);
                if (m.Success)
                {
                    int mmid = int.Parse(m.Groups[1].ToString());
                    if (mmid > MMID)
                    {
                        MMID = mmid;
                    }
                }

                try
                {
                    var json = JsonConvert.DeserializeObject <MMgame>(File.ReadAllText(file));
                    Games.TryAdd(json.ID, json);
                } catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            _logger.LogInformation("Setting MMID to " + MMID);

            foreach (var file in Directory.EnumerateFiles(WorkDir + "/games", "*_report.json"))
            {
                try
                {
                    var json = JsonConvert.DeserializeObject <MMgame>(file);
                    Games[json.ID] = json;
                }
                catch { }
            }

            foreach (var file in Directory.EnumerateFiles(WorkDir + "/games", "*_replay_*.json"))
            {
                try
                {
                    var json = JsonConvert.DeserializeObject <dsreplay>(file);
                    ReplayHash.Add(json.HASH);
                }
                catch { }
            }

            /**
             * var options = new JsonSerializerOptions
             * {
             *  WriteIndented = true
             * };
             * var ladder = System.Text.Json.JsonSerializer.Serialize(laddergames, options);
             * File.WriteAllText(WorkDir + "/ladder.json", ladder);
             **/
            GetLadder();
            QMMplayers.CollectionChanged += QplayersChanged;
        }