Esempio n. 1
0
        public async Task <ActionResult <EamuseXrpcData> > Register([FromBody] EamuseXrpcData data)
        {
            XElement gametop = data.Document.Element("call").Element("gametop");
            XElement player  = gametop.Element("data").Element("player");
            string   refId   = player.Element("refid").Value.ToUpper();
            string   name    = player.Element("name").Value;

            Card card = await ctx.Cards
                        .Include(c => c.Player.JubeatProfile)
                        .ThenInclude(p => p.Jubilitys)
                        .Include(c => c.Player.JubeatProfile.ClanData)
                        .Include(c => c.Player.JubeatProfile.ClanSettings)
                        .SingleOrDefaultAsync(c => c.RefId == refId);

            if (card == null || card.Player == null)
            {
                return(NotFound());
            }

            if (card.Player.JubeatProfile == null)
            {
                card.Player.JubeatProfile = new JubeatProfile();
            }

            card.Player.JubeatProfile.Name = name;

            await ctx.SaveChangesAsync();

            try
            {
                data.Document = new XDocument(new XElement("response", new XElement("gametop",
                                                                                    new XElement("data",
                                                                                                 GetInfoElement(),
                                                                                                 await GetPlayerElement(card)
                                                                                                 )
                                                                                    )));
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(StatusCode(500));
            }

            return(data);
        }
Esempio n. 2
0
        public async Task <ActionResult <EamuseXrpcData> > GetRefId([FromBody] EamuseXrpcData data)
        {
            XElement cardmng = data.Document.Element("call").Element("cardmng");

            string cardId = cardmng.Attribute("cardid").Value.ToUpper();
            string passwd = cardmng.Attribute("passwd").Value;

            if (await ctx.Cards.AnyAsync(c => c.CardId == cardId))
            {
                data.Document = new XDocument(new XElement("response", new XElement("cardmng")));
                return(data);
            }

            Random rng = new Random();

            byte[] dataId = new byte[8];
            byte[] refId  = new byte[8];

            rng.NextBytes(dataId);
            rng.NextBytes(refId);

            Player player = new Player()
            {
                Passwd = passwd
            };

            Card card = new Card()
            {
                CardId = cardId,
                DataId = dataId.ToHexString(),
                RefId  = refId.ToHexString(),
                Player = player
            };

            ctx.Players.Add(player);
            ctx.Cards.Add(card);

            await ctx.SaveChangesAsync();

            data.Document = new XDocument(new XElement("response", new XElement("cardmng",
                                                                                new XAttribute("dataid", card.DataId),
                                                                                new XAttribute("refid", card.RefId)
                                                                                )));

            return(data);
        }
Esempio n. 3
0
        public async Task <ActionResult <EamuseXrpcData> > Register([FromBody] EamuseXrpcData xrpcData)
        {
            try
            {
                XElement dataE   = xrpcData.Document.Element("call").Element("gameend").Element("data");
                XElement playerE = dataE.Element("player");

                xrpcData.Document = new XDocument(new XElement("response", new XElement("gameend")));

                if (playerE == null)
                {
                    return(xrpcData);
                }

                int jid = int.Parse(playerE.Element("jid").Value);

                JubeatProfile profile = await ctx.JubeatProfiles
                                        .Include(p => p.ClanData)
                                        .Include(p => p.ClanSettings)
                                        .Include(p => p.Jubilitys)
                                        .SingleOrDefaultAsync(p => p.ID == jid);

                var data     = profile.ClanData;
                var settings = profile.ClanSettings;

                if (profile == null || data == null || settings == null)
                {
                    return(NotFound());
                }

                XElement teamE = playerE.Element("team");
                data.Team     = byte.Parse(teamE.Attribute("id").Value);
                data.Street   = int.Parse(teamE.Element("street").Value);
                data.Section  = int.Parse(teamE.Element("section").Value);
                data.HouseNo1 = short.Parse(teamE.Element("house_number_1").Value);
                data.HouseNo1 = short.Parse(teamE.Element("house_number_2").Value);

                XElement infoE = dataE.Element("info");
                data.PlayTime = int.Parse(infoE.Element("play_time").Value);

                XElement pInfoE = playerE.Element("info");
                data.TuneCount       = int.Parse(pInfoE.Element("tune_cnt").Value);
                data.ClearCount      = int.Parse(pInfoE.Element("clear_cnt").Value);
                data.FcCount         = int.Parse(pInfoE.Element("fc_cnt").Value);
                data.ExCount         = int.Parse(pInfoE.Element("ex_cnt").Value);
                data.MatchCount      = int.Parse(pInfoE.Element("match_cnt").Value);
                data.BeatCount       = int.Parse(pInfoE.Element("beat_cnt").Value);
                data.SaveCount       = int.Parse(pInfoE.Element("save_cnt").Value);
                data.SavedCount      = int.Parse(pInfoE.Element("saved_cnt").Value);
                data.BonusTunePoints = int.Parse(pInfoE.Element("bonus_tune_points").Value);
                data.BonusTunePlayed = pInfoE.Element("is_bonus_tune_played").Value == "1";

                XElement jboxE = playerE.Element("jbox");
                data.JboxPoints = int.Parse(jboxE.Element("point").Value);

                XElement lastE = playerE.Element("last");
                settings.ExpertOption = sbyte.Parse(lastE.Element("expert_option").Value);
                settings.Sort         = sbyte.Parse(lastE.Element("sort").Value);
                settings.Category     = sbyte.Parse(lastE.Element("category").Value);

                XElement settingsE = lastE.Element("settings");
                settings.Marker       = sbyte.Parse(settingsE.Element("marker").Value);
                settings.Theme        = sbyte.Parse(settingsE.Element("theme").Value);
                settings.RankSort     = sbyte.Parse(settingsE.Element("rank_sort").Value);
                settings.ComboDisplay = sbyte.Parse(settingsE.Element("combo_disp").Value);
                settings.Matching     = sbyte.Parse(settingsE.Element("matching").Value);
                settings.Hard         = sbyte.Parse(settingsE.Element("hard").Value);
                settings.Hazard       = sbyte.Parse(settingsE.Element("hazard").Value);

                IEnumerable <XElement> tunes = dataE.Element("result").Elements("tune");

                foreach (XElement tune in tunes)
                {
                    XElement tunePlayer = tune.Element("player");
                    XElement tuneScore  = tunePlayer.Element("score");

                    int   musicId = int.Parse(tune.Element("music").Value);
                    sbyte seq     = sbyte.Parse(tuneScore.Attribute("seq").Value);

                    JubeatScore score = new JubeatScore()
                    {
                        ProfileID = profile.ID,
                        MusicID   = musicId,
                        Seq       = seq
                    };

                    score.Timestamp    = long.Parse(tune.Element("timestamp").Value);
                    score.Score        = int.Parse(tunePlayer.Element("score").Value);
                    score.Clear        = sbyte.Parse(tuneScore.Attribute("clear").Value);
                    score.IsHardMode   = tunePlayer.Element("is_hard_mode").Value == "1";
                    score.IsHazardMode = tunePlayer.Element("is_hazard_end").Value == "1";
                    score.NumPerfect   = short.Parse(tunePlayer.Element("nr_perfect").Value);
                    score.NumGreat     = short.Parse(tunePlayer.Element("nr_great").Value);
                    score.NumGood      = short.Parse(tunePlayer.Element("nr_good").Value);
                    score.NumPoor      = short.Parse(tunePlayer.Element("nr_poor").Value);
                    score.NumMiss      = short.Parse(tunePlayer.Element("nr_miss").Value);

                    string[] mbarStrs = tunePlayer.Element("play_mbar").Value.Split(' ');
                    score.Bar = Array.ConvertAll(mbarStrs, s => byte.Parse(s));

                    ctx.JubeatScores.Add(score);

                    JubeatHighscore highscore = ctx.JubeatHighscores
                                                .Where(s => s.MusicID == musicId && s.Seq == seq && s.ProfileID == profile.ID)
                                                .SingleOrDefault();

                    if (highscore == null)
                    {
                        highscore = new JubeatHighscore()
                        {
                            ProfileID = profile.ID,
                            MusicID   = musicId,
                            Seq       = seq
                        };

                        ctx.JubeatHighscores.Add(highscore);
                    }

                    if (score.Score > highscore.Score)
                    {
                        highscore.Timestamp = score.Timestamp;
                    }

                    highscore.Score      = int.Parse(tunePlayer.Element("best_score").Value);
                    highscore.Clear      = sbyte.Parse(tunePlayer.Element("best_clear").Value);
                    highscore.PlayCount  = int.Parse(tunePlayer.Element("play_cnt").Value);
                    highscore.ClearCount = int.Parse(tunePlayer.Element("clear_cnt").Value);
                    highscore.FcCount    = int.Parse(tunePlayer.Element("fc_cnt").Value);
                    highscore.ExcCount   = int.Parse(tunePlayer.Element("ex_cnt").Value);

                    mbarStrs      = tunePlayer.Element("mbar").Value.Split(' ');
                    highscore.Bar = Array.ConvertAll(mbarStrs, s => byte.Parse(s));
                }

                XElement jubility = playerE.Element("jubility");
                data.JubilityParam = int.Parse(jubility.Attribute("param").Value);

                profile.Jubilitys.Clear();

                foreach (XElement targetMusic in jubility.Element("target_music_list").Elements("target_music"))
                {
                    profile.Jubilitys.Add(new JubeatClanJubility()
                    {
                        MusicID    = int.Parse(targetMusic.Element("music_id").Value),
                        Seq        = sbyte.Parse(targetMusic.Element("seq").Value),
                        Score      = int.Parse(targetMusic.Element("score").Value),
                        Value      = int.Parse(targetMusic.Element("value").Value),
                        IsHardMode = targetMusic.Element("is_hard_mode").Value == "1"
                    });
                }

                await ctx.SaveChangesAsync();

                return(xrpcData);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(StatusCode(500));
            }
        }