Esempio n. 1
0
        /// <summary>
        /// This Methods allows to Backup 1 Grid and all of its subgrids.
        ///
        /// The Grids are just taken and backed up as is. So its up to the caller to filter "connected"
        /// grids, or make sure the grids are connected in the first place. If two Separate grids are
        /// put in there they *can* be backed up, however it may cause problems upon restoring them.
        ///
        /// Since this Method already uses ObjectBuilders it is not needed to run on Main-Thread and
        /// also not adviced as Writing XML to disk could take a few millisecond longer.
        ///
        /// Apart from that no parallelization is done so there wont be any parallel task started or anything.
        /// </summary>
        /// <param name="grids">The list of connected grid ObjectBuilders you want to backup</param>
        /// <param name="identityId">IdentityID of the biggest owner of the grid. Can be 0 if nobody owns it.</param>
        /// <returns>true if and only if the grids were saved correctly. false otherwise.</returns>
        public bool BackupGridsManuallyWithBuilders(List <MyObjectBuilder_CubeGrid> grids, long identityId)
        {
            if (grids == null || grids.Count == 0)
            {
                Log.Warn("Grids for manual backup empty!");
                return(false);
            }

            return(BackupQueue.BackupSingleGridStatic(identityId, grids, CreatePath(), this));
        }
Esempio n. 2
0
        /// <summary>
        /// This Methods allows to Backup 1 Grid and all of its subgrids.
        ///
        /// The Grids are just taken and backed up as is. So its up to the caller to filter "connected"
        /// grids, or make sure the grids are connected in the first place. If two Separate grids are
        /// put in there they *can* be backed up, however it may cause problems upon restoring them.
        ///
        /// This Method must be called on game thread in order to work, as the internal generation of
        /// ObjectBuilders must be called from game thread. The method itself does not check for it.
        /// </summary>
        /// <param name="grids">The list of connected grids you want to backup</param>
        /// <param name="biggestGrid">Out: Biggest grid of the group (the one which name and ID is used in the folder structure)</param>
        /// <param name="playerId">Out: Player ID that owns the biggest grid in the group. 0 if nobody, -1 if there is no biggest grid. Commonly happening when List is empty</param>
        /// <param name="context">Optional: When called via command context it may output stuff to the console</param>
        /// <returns>true if and only if the grids were saved correctly. false otherwise.</returns>
        public bool BackupGridsManually(List <MyCubeGrid> grids, out MyCubeGrid biggestGrid, out long playerId, CommandContext context = null)
        {
            biggestGrid = null;

            foreach (var grid in grids)
            {
                if (biggestGrid == null || biggestGrid.BlocksCount < grid.BlocksCount)
                {
                    biggestGrid = grid;
                }
            }

            /* No biggest grid should not be possible, unless the gridgroup only had projections -.- just skip it. */
            if (biggestGrid == null)
            {
                if (context != null)
                {
                    context.Respond("Grid incompatible!");
                }

                playerId = -1;

                return(false);
            }

            /* No owner at all? hard to believe. but okay. */
            if (biggestGrid.BigOwners.Count == 0)
            {
                playerId = 0;
            }
            else
            {
                playerId = biggestGrid.BigOwners[0];
            }

            return(BackupQueue.BackupSingleGridStatic(playerId, grids, CreatePath(), null, this, false));
        }
Esempio n. 3
0
 public GridBackupPlugin()
 {
     backupQueue = new BackupQueue(this);
 }