Ejemplo n.º 1
0
        /// <summary>
        /// Upload new song and chart data to remote
        /// </summary>
        /// <param name="songid">ID of song to add</param>
        public static async void UploadSongInfo(string songid)
        {
            var song = Utils.songDb[songid];

            //Utils.Debug($"Song {songid}");

            HttpStatusCode response = HttpStatusCode.InternalServerError;

            do
            {
                response = AddSong(song);
            } while (response != HttpStatusCode.OK);

            for (int i = 0; i < song.level.Length; i++)
            {
                if (i == 0 || i == 5 || song.level[i] == 0)
                {
                    continue;
                }

                Thread.Sleep(20);
                try
                {
                    ChartInfo chart = new ChartInfo()
                    {
                        level      = song.level[i],
                        songid     = songid,
                        difficulty = (Difficulty)i,
                        totalNotes = song.totalNotes[i],
                        unlocked   = Utils.GetUnlockStateForDifficulty(songid, (Difficulty)i)
                    };

                    do
                    {
                        response = AddChart(chart);
                    } while (response != HttpStatusCode.OK);

                    do
                    {
                        response = PostScore(chart, ScoreMap.Scores[songid].score[i], ScoreMap.Scores[songid].misscount[i], ScoreMap.Scores[songid].lamp[i]);
                    } while (response != HttpStatusCode.OK);
                }
                catch
                {
                    Utils.Log($"Server issues when adding {songid}[{i}]");
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetch all metadata for a specific chart
        /// </summary>
        /// <param name="song"></param>
        /// <param name="difficulty"></param>
        /// <returns></returns>
        ChartInfo FetchChartInfo(SongInfo song, Difficulty difficulty)
        {
            ChartInfo result = new ChartInfo();

            /* Lamp: 0-7, [noplay, fail, a-clear, e-clear, N, H, EX, FC] */
            result.difficulty    = difficulty;
            result.level         = song.level[(int)difficulty];
            result.title         = song.title;
            result.title_english = song.title_english;
            result.totalNotes    = song.totalNotes[(int)difficulty];
            result.artist        = song.artist;
            result.genre         = song.genre;
            result.bpm           = song.bpm;
            result.songid        = song.ID;
            result.unlocked      = Utils.GetUnlockStateForDifficulty(song.ID, difficulty);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a new chart for a song at remote
        /// </summary>
        /// <param name="chart">Metadata for one chart difficulty</param>
        /// <returns>Server response</returns>
        static HttpStatusCode AddChart(ChartInfo chart)
        {
            var content = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "apikey", Config.API_key },
                { "songid", chart.songid },
                { "unlocked", chart.unlocked.ToString() },
                { "diff", chart.difficulty.ToString() },
                { "level", chart.level.ToString() },
                { "notecount", chart.totalNotes.ToString() }
            }
                                                    );
            var response = client.PostAsync(Config.Server + "/api/addchart", content);

            Utils.Debug(response.Result.Content.ReadAsStringAsync().Result);
            return(response.Result.StatusCode);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Post score to remote
        /// </summary>
        /// <param name="chart">Chart information</param>
        /// <param name="exscore">Ex score</param>
        /// <param name="misscount">Miss count</param>
        /// <param name="lamp">Clear state</param>
        /// <returns></returns>
        static HttpStatusCode PostScore(ChartInfo chart, int exscore, uint misscount, Lamp lamp)
        {
            var grade   = (lamp == Lamp.NP && exscore == 0) ? Grade.NP : Utils.ScoreToGrade(chart.songid, chart.difficulty, exscore);
            var content = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "apikey", Config.API_key },
                { "songid", chart.songid },
                { "diff", chart.difficulty.ToString() },
                { "exscore", exscore.ToString() },
                { "misscount", misscount.ToString() },
                { "grade", grade.ToString() },
                { "lamp", lamp.ToString() }
            }
                                                    );
            var response = client.PostAsync(Config.Server + "/api/postscore", content);

            Utils.Debug(response.Result.Content.ReadAsStringAsync().Result);
            return(response.Result.StatusCode);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Fetch all data relating to the recent play
        /// </summary>
        public void Fetch()
        {
            judges.Fetch();
            settings.Fetch(judges.playtype);

            timestamp = DateTime.UtcNow;

            short word = 4;

            Difficulty difficulty = 0;

            try
            {
                var song = Utils.ReadInt32(Offsets.PlayData, 0);
                difficulty = (Difficulty)Utils.ReadInt32(Offsets.PlayData, word);
                clearLamp  = (Lamp)Utils.ReadInt32(Offsets.PlayData, word * 6);
                gauge      = Utils.ReadInt32(Offsets.PlayData, word * 8);

                songID        = song.ToString("00000");
                chart         = FetchChartInfo(Utils.songDb[songID], difficulty);
                DataAvailable = true;
            }
            catch
            {
                Console.WriteLine("Unable to fetch play data, using currentplaying value instead");
                var currentChart = Utils.FetchCurrentChart();
                songID        = currentChart.songID;
                difficulty    = currentChart.difficulty;
                clearLamp     = Lamp.AC; /* What clear lamp should be given on stuff not sent to server? */
                chart         = FetchChartInfo(Utils.songDb[songID], difficulty);
                DataAvailable = false;
            }

            if (judges.PFC && clearLamp == Lamp.FC)
            {
                clearLamp = Lamp.PFC;
            }

            exscore = (judges.pgreat * 2 + judges.great);

            grade = Utils.ScoreToGrade(songID, difficulty, exscore);
        }