Exemplo n.º 1
0
        /// <summary>
        /// Convert a byte array to an <see cref="UnlockData"/> object
        /// </summary>
        /// <param name="buf">Byte array</param>
        /// <returns>An <see cref="UnlockData"/> object representation of the input</returns>
        static int ParseUnlockBuffer(byte[] buf)
        {
            int position   = 0;
            int extra      = 0;
            int structSize = Marshal.SizeOf(typeof(UnlockData));

            while (position < buf.Length)
            {
                var        sData = buf.Skip(position).Take(structSize).ToArray();
                UnlockData data  = new UnlockData {
                    songID  = BytesToInt32(sData, 0),
                    type    = (unlockType)BytesToInt32(sData, 4),
                    unlocks = BytesToInt32(sData, 8)
                };
                string id = data.songID.ToString("D5");
                if (id == "00000") /* Take into account where songDb is populated with unreleased songs */
                {
                    break;
                }
                unlockDb.Add(id, data);
                try
                {
                    var song = songDb[id];
                    song.type  = data.type;
                    songDb[id] = song;
                } catch
                {
                    Debug($"Song {id} not present in song database");
                    extra++;
                }

                position += structSize;
            }
            return(extra);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update unlock state of charts for song at remote
        /// </summary>
        /// <param name="songid">Song whose charts are to be updated</param>
        /// <param name="unlocks">Unlock information for song</param>
        public static async void ReportUnlock(string songid, UnlockData unlocks)
        {
            var content = new FormUrlEncodedContent(new Dictionary <string, string>()
            {
                { "apikey", Config.API_key },
                { "songid", songid },
                { "state", unlocks.unlocks.ToString() }
            }
                                                    );
            var response = await client.PostAsync(Config.Server + "/api/unlocksong", content);

            Utils.Debug(await response.Content.ReadAsStringAsync());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Update and detect changes to song unlock states
        /// </summary>
        /// <returns>Changes between the two unlock statuses, if any. Empty dictionary otherwise</returns>
        public static Dictionary <string, UnlockData> UpdateUnlockStates()
        {
            var oldUnlocks = unlockDb;

            GetUnlockStates();
            var changes = new Dictionary <string, UnlockData>();

            foreach (var key in unlockDb.Keys)
            {
                if (!oldUnlocks.ContainsKey(key))
                {
                    Log($"Key {key} was not present in past unlocks array");
                    continue;
                }
                if (unlockDb[key].unlocks != oldUnlocks[key].unlocks)
                {
                    UnlockData value = unlockDb[key];
                    changes.Add(key, value);
                    oldUnlocks[key] = unlockDb[key];
                }
            }
            return(changes);
        }