Пример #1
0
        private async Task <SCCMListPresenter.LoadFuncResult> QueryData(SCCMListPresenter list, int page, int reqid)
        {
            try
            {
                var r = await MainGame.Inst.Backend.QueryUserLevel(MainGame.Inst.Profile, QueryUserLevelCategory.NewLevels, string.Empty, page);

                if (r == null)
                {
                    return(SCCMListPresenter.LoadFuncResult.Error);
                }
                else
                {
                    if (r.Count == 0)
                    {
                        return(SCCMListPresenter.LoadFuncResult.LastPage);
                    }
                    else
                    {
                        MonoSAMGame.CurrentInst.DispatchBeginInvoke(() =>
                        {
                            if (list.IsCurrentRequest(reqid))
                            {
                                foreach (var levelmeta in r)
                                {
                                    list.AddEntry(new SCCMListElementOnlinePlayable(levelmeta));
                                }
                            }
                        });

                        return(SCCMListPresenter.LoadFuncResult.Success);
                    }
                }
            }
            catch (Exception e)
            {
                SAMLog.Error("SCCMTN::QD", e);

                MonoSAMGame.CurrentInst.DispatchBeginInvoke(() =>
                {
                    HUD.AddModal(new HUDFadeOutInfoBox(5, 2, 0.3f)
                    {
                        L10NText   = L10NImpl.STR_CPP_COMERR,
                        TextColor  = FlatColors.Clouds,
                        Background = HUDBackgroundDefinition.CreateRounded(FlatColors.Alizarin, 16),

                        CloseOnClick = true,
                    }, true);
                });

                return(SCCMListPresenter.LoadFuncResult.Error);
            }
        }
Пример #2
0
        private Task <SCCMListPresenter.LoadFuncResult> QueryData(SCCMListPresenter list, int page, int reqid)
        {
            list.AddEntry(new SCCMListElementNewUserLevel());

            foreach (var userlevel in SCCMUtils.ListUserLevelsUnfinished())
            {
                if (userlevel.AuthorUserID != MainGame.Inst.Profile.OnlineUserID)
                {
                    continue;
                }
                list.AddEntry(new SCCMListElementEditable(userlevel));
            }

            var localLevels = new List <Tuple <long, string, SCCMListElementLocalPlayable, string> >();

            foreach (var userleveltuple in SCCMUtils.ListUserLevelsFinished())
            {
                var filename  = userleveltuple.Item1;
                var userlevel = userleveltuple.Item2;
                var levelhash = userleveltuple.Item3;

                if (userlevel.CustomMeta_UserID == MainGame.Inst.Profile.OnlineUserID)
                {
                    var entry = new SCCMListElementLocalPlayable(userlevel);
                    localLevels.Add(Tuple.Create(userlevel.CustomMeta_LevelID, levelhash, entry, filename));

                    list.AddEntry(entry);
                }
                else
                {
                    SAMLog.Info("SCCMTML::DelFinLevel", $"Level {userlevel.UniqueID:B} deleted cause wrong username {userlevel.CustomMeta_UserID} <> {MainGame.Inst.Profile.OnlineUserID}");
                    SCCMUtils.DeleteUserLevelFinished(filename);
                }
            }

            QueryMetaFromServer(localLevels).EnsureNoError();

            return(Task.FromResult(SCCMListPresenter.LoadFuncResult.LastPage));
        }
Пример #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)}");
                }
            }
        }