public string DoSHA256(string input)
 {
     using (var sha256 = SHA256.Create()) return(ByteUtils.ByteToHexBitFiddle(sha256.ComputeHash(Encoding.UTF8.GetBytes(input))));
 }
Example #2
0
 public string DoSHA256(string input) => ByteUtils.ByteToHexBitFiddle(sha256.ComputeHash(Encoding.UTF8.GetBytes(input)));
Example #3
0
        private async Task QueryMetaFromServer(List <Tuple <long, string, SCCMListElementLocalPlayable, string> > userlevelsLocal)
        {
            var userlevel_online = await MainGame.Inst.Backend.QueryUserLevel(MainGame.Inst.Profile, QueryUserLevelCategory.AllLevelsOfUserid, MainGame.Inst.Profile.OnlineUserID.ToString(), 0);

            if (userlevel_online == null)
            {
                return;                                       // no internetz
            }
            var redownload = new List <Tuple <long, SCCMLevelMeta> >();

            foreach (var lvlonline in userlevel_online)
            {
                var match = userlevelsLocal.FirstOrDefault(loc => loc.Item1 == lvlonline.OnlineID);
                if (match != null)
                {
                    if (lvlonline.Hash.ToUpper() != match.Item2.ToUpper())
                    {
                        // Hash mismatch - redownload

                        MainGame.Inst.DispatchBeginInvoke(() =>
                        {
                            match.Item3.Remove();
                            SCCMUtils.DeleteUserLevelFinished(match.Item4);
                        });

                        SAMLog.Info("SCCMTML::QMFS-1", $"Hash-mismatch local user level {lvlonline.OnlineID} - redownload");

                        redownload.Add(Tuple.Create(lvlonline.OnlineID, lvlonline));
                    }
                    else
                    {
                        // all ok - update meta

                        MainGame.Inst.DispatchBeginInvoke(() =>
                        {
                            match.Item3.SetMeta(lvlonline);
                        });
                    }
                }
                else
                {
                    // missing - download

                    SAMLog.Info("SCCMTML::QMFS-2", $"Missing local user level {lvlonline.OnlineID} - redownload");
                    redownload.Add(Tuple.Create(lvlonline.OnlineID, lvlonline));
                }
            }

            foreach (var dl in redownload)
            {
                var levelcontent = await MainGame.Inst.Backend.DownloadUserLevel(MainGame.Inst.Profile, dl.Item1);

                if (levelcontent == null)
                {
                    continue;
                }

                try
                {
                    var dat = new LevelBlueprint();
                    dat.BinaryDeserialize(new BinaryReader(new MemoryStream(levelcontent)));

                    MainGame.Inst.DispatchBeginInvoke(() =>
                    {
                        SCCMUtils.UpdateUserLevelsFinished(dl.Item2.OnlineID, levelcontent);
                        var entry = new SCCMListElementLocalPlayable(dat);
                        _presenter.AddEntry(entry);
                        entry.SetMeta(dl.Item2);
                    });
                }
                catch (Exception e)
                {
                    SAMLog.Error("SCCMTML::COMPILEFAIL_QMFS", "Could not compile dowbnloaded level", $"Exception: {e}\n\n\nLevel: {dl.Item1}\n\n\nContent:{ByteUtils.ByteToHexBitFiddle(levelcontent)}");
                }
            }
        }
Example #4
0
        public static List <Tuple <string, LevelBlueprint, string> > ListUserLevelsFinished()
        {
            var allfiles = FileHelper.Inst.ListData();

            var result = new List <Tuple <string, LevelBlueprint, string> >();

            foreach (var file in allfiles)
            {
                if (!file.StartsWith("UPLOADEDLEVELDATA_"))
                {
                    continue;
                }

                byte[] content = null;
                try
                {
                    var dat = new LevelBlueprint();
                    content = FileHelper.Inst.ReadBinDataOrNull(file);
                    dat.BinaryDeserialize(new BinaryReader(new MemoryStream(content)));

                    var hash = ByteUtils.ByteToHexBitFiddle(MainGame.Inst.Bridge.DoSHA256(content));

                    result.Add(Tuple.Create(file, dat, hash));
                }
                catch (Exception e)
                {
                    SAMLog.Error("SCCMU::READFAIL_LULF", "Could not read CustomLevelData", $"Exception: {e}\n\n\nFile: {file}\n\n\nContent:{ByteUtils.ByteToHexBitFiddle(content)}");
                }
            }

            return(result);
        }