Esempio n. 1
0
        private MyServerAction LoadSandbox(MyMwcVector3Int position, int?userId, MyMissionID?startMission)
        {
            var sectorId = new MyMwcSectorIdentifier(MyMwcSectorTypeEnum.SANDBOX, userId, position, null);
            var sector   = MyLocalCache.LoadSector(sectorId);
            int?version  = sector != null ? (int?)sector.Version : null;

            MyMwcStartSessionRequestTypeEnum startSessionType = userId == MyClientServer.LoggedPlayer.GetUserId() ? MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN : MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS;

            if (userId != null)
            {
                MyServerAction loadAction = new MyServerAction(MyTextsWrapperEnum.EnterSectorInProgressPleaseWait, TimeSpan.FromSeconds(360));
                loadAction.BeginAction = c => c.BeginLoadSandbox(position, userId, version, null, c);
                loadAction.EndAction   = (c, r) => SandboxSectorLoaded(position, MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(c.EndLoadSandbox(r)), sector, startSessionType, startMission);
                loadAction.Start();
                return(loadAction);
            }
            else if (sector != null)
            {
                var checkpoint = MyLocalCache.MultiplayerCheckpoint();
                if (checkpoint == null)
                {
                    throw new MyDataCorruptedException("Cannot load MP checkpoint");
                }

                if (!MySteam.IsActive && MyClientServer.IsMwAccount)
                {
                    checkpoint.PlayerObjectBuilder.Money = (float)MySectorServiceClient.GetCheckedInstance().GetGameMoney();
                    MySectorServiceClient.SafeClose();
                }

                checkpoint.SectorObjectBuilder = sector;
                SandboxSectorLoaded(position, checkpoint, sector, startSessionType, startMission);
                return(null);
            }
            else
            {
                throw new MyDataCorruptedException("Cannot load sandbox/MP sector");
            }
        }