Exemple #1
0
        static void ListFromDatabase(Player p, ref bool foundAny, ushort x, ushort y, ushort z)
        {
            if (!Database.TableExists("Block" + p.level.name))
            {
                return;
            }
            using (DataTable Blocks = Database.Backend.GetRows("Block" + p.level.name, "*",
                                                               "WHERE X=@0 AND Y=@1 AND Z=@2", x, y, z)) {
                BlockDBEntry entry = default(BlockDBEntry);
                entry.OldRaw = Block.Invalid;

                for (int i = 0; i < Blocks.Rows.Count; i++)
                {
                    foundAny = true;
                    DataRow row  = Blocks.Rows[i];
                    string  name = row["Username"].ToString().Trim();

                    DateTime time  = DateTime.Parse(row["TimePerformed"].ToString());
                    TimeSpan delta = time - BlockDB.Epoch;
                    entry.TimeDelta = (int)delta.TotalSeconds;
                    entry.Flags     = BlockDBFlags.ManualPlace;

                    byte flags = ParseFlags(row["Deleted"].ToString());
                    if ((flags & 1) == 0)   // block was placed
                    {
                        entry.NewRaw = byte.Parse(row["Type"].ToString());
                        entry.Flags |= (flags & 2) != 0 ? BlockDBFlags.NewCustom : BlockDBFlags.None;
                    }
                    BlockDBChange.Output(p, name, entry);
                }
            }
        }
        public override int DrawBatch(int maxBlocksToDraw)
        {
            int blocksDone = 0;

            for (; entryIndex < changes.Length; entryIndex++)
            {
                BlockDBEntry entry = changes[entryIndex];
                Coords = new Vector3I(entry.X, entry.Y, entry.Z);
                block  = entry.OldBlock;
                if (entry.PlayerId == Player.Info.Id)
                {
                    Context = BlockChangeContext.UndoneSelf | BlockChangeContext.Drawn;
                }
                else
                {
                    Context = BlockChangeContext.UndoneOther | BlockChangeContext.Drawn;
                }
                if (DrawOneBlock())
                {
                    blocksDone++;
                    if (blocksDone >= maxBlocksToDraw || TimeToEndBatch)
                    {
                        entryIndex++;
                        return(blocksDone);
                    }
                }
            }
            IsDone = true;
            return(blocksDone);
        }
Exemple #3
0
        void HighlightBlock(BlockDBEntry e)
        {
            BlockID oldBlock = e.OldBlock;

            if (oldBlock == Block.Invalid)
            {
                return;                            // Exported BlockDB SQL table entries don't have previous block
            }
            BlockID newBlock = e.NewBlock;

            BlockID highlight = (newBlock == Block.Air ||
                                 Block.Convert(oldBlock) == Block.Water || oldBlock == Block.StillWater ||
                                 Block.Convert(oldBlock) == Block.Lava || oldBlock == Block.StillLava)
                ? DeleteHighlight : PlaceHighlight;

            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            if (x < Min.X || y < Min.Y || z < Min.Z)
            {
                return;
            }
            if (x > Max.X || y > Max.Y || z > Max.Z)
            {
                return;
            }
            output(Place((ushort)x, (ushort)y, (ushort)z, highlight));
            found = true;
        }
Exemple #4
0
        void HighlightBlock(BlockDBEntry e)
        {
            ExtBlock oldBlock = ExtBlock.FromRaw(e.OldRaw, (e.Flags & BlockDBFlags.OldCustom) != 0);

            if (oldBlock.BlockID == Block.Invalid)
            {
                return;                                    // Exported BlockDB SQL table entries don't have previous block
            }
            ExtBlock newBlock = ExtBlock.FromRaw(e.NewRaw, (e.Flags & BlockDBFlags.NewCustom) != 0);

            ExtBlock highlight = (newBlock.BlockID == Block.Air ||
                                  Block.Convert(oldBlock.BlockID) == Block.Water || oldBlock.BlockID == Block.StillWater ||
                                  Block.Convert(oldBlock.BlockID) == Block.Lava || oldBlock.BlockID == Block.StillLava)
                ? DeleteHighlight : PlaceHighlight;

            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            if (x < Min.X || y < Min.Y || z < Min.Z)
            {
                return;
            }
            if (x > Max.X || y > Max.Y || z > Max.Z)
            {
                return;
            }
            output(Place((ushort)x, (ushort)y, (ushort)z, highlight));
            found = true;
        }
Exemple #5
0
        void RedoBlock(BlockDBEntry e)
        {
            BlockID block = e.OldBlock;

            if (block == Block.Invalid)
            {
                return;                         // Exported BlockDB SQL table entries don't have previous block
            }
            if ((e.Flags & BlockDBFlags.UndoSelf) == 0)
            {
                return;                                         // not an undo
            }
            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            output(Place((ushort)x, (ushort)y, (ushort)z, block));
        }
Exemple #6
0
        void UndoBlock(BlockDBEntry e)
        {
            BlockID block = e.OldBlock;

            if (block == Block.Invalid)
            {
                return;                         // Exported BlockDB SQL table entries don't have previous block
            }
            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            if (x < Min.X || y < Min.Y || z < Min.Z)
            {
                return;
            }
            if (x > Max.X || y > Max.Y || z > Max.Z)
            {
                return;
            }

            if (conservative)
            {
                oldest[e.Index] = block;
                return;
            }

            const int flags = BlockDBFlags.UndoOther | BlockDBFlags.UndoSelf;

            if ((e.Flags & flags) != 0)
            {
                Player.Message("%WThis undo overlaps with previous undos, " +
                               "so undoing may take longer..");
                oldest          = new Dictionary <int, BlockID>();
                oldest[e.Index] = block;

                conservative = true;
                found        = true;
                return;
            }

            output(Place((ushort)x, (ushort)y, (ushort)z, block));
            found = true;
        }
Exemple #7
0
            public void Output(BlockDBEntry entry)
            {
                if (entry.TimeDelta >= start)
                {
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (entry.PlayerID == ids[i])
                        {
                            return;
                        }
                    }
                }

                left++;
                entries.Add(entry);
                if (entries.Count == 4096)
                {
                    format.WriteEntries(dst, entries);
                    entries.Count = 0;
                }
            }
Exemple #8
0
        void UndoBlock(BlockDBEntry e)
        {
            BlockID block = e.OldBlock;

            if (block == Block.Invalid)
            {
                return;                         // Exported BlockDB SQL table entries don't have previous block
            }
            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            if (x < Min.X || y < Min.Y || z < Min.Z)
            {
                return;
            }
            if (x > Max.X || y > Max.Y || z > Max.Z)
            {
                return;
            }
            output(Place((ushort)x, (ushort)y, (ushort)z, block));
            found = true;
        }
Exemple #9
0
        void UndoBlock(BlockDBEntry e)
        {
            ExtBlock block = ExtBlock.FromRaw(e.OldRaw, (e.Flags & BlockDBFlags.OldCustom) != 0);

            if (block.BlockID == Block.Invalid)
            {
                return;                                 // Exported BlockDB SQL table entries don't have previous block
            }
            int x = e.Index % dims.X;
            int y = (e.Index / dims.X) / dims.Z;
            int z = (e.Index / dims.X) % dims.Z;

            if (x < Min.X || y < Min.Y || z < Min.Z)
            {
                return;
            }
            if (x > Max.X || y > Max.Y || z > Max.Z)
            {
                return;
            }
            output(Place((ushort)x, (ushort)y, (ushort)z, block));
            found = true;
        }
Exemple #10
0
        static void ListFromDatabase(Player p, ref bool foundAny, ushort x, ushort y, ushort z)
        {
            if (!Database.TableExists("Block" + p.level.name))
            {
                return;
            }

            List <string[]> entries = Database.GetRows("Block" + p.level.name, "Username,TimePerformed,Deleted,Type",
                                                       "WHERE X=@0 AND Y=@1 AND Z=@2", x, y, z);

            if (entries.Count > 0)
            {
                foundAny = true;
            }
            BlockDBEntry entry = default(BlockDBEntry);

            entry.OldRaw = Block.Invalid;

            foreach (string[] row in entries)
            {
                DateTime time  = row[1].ParseDBDate();
                TimeSpan delta = time - BlockDB.Epoch;
                entry.TimeDelta = (int)delta.TotalSeconds;
                entry.Flags     = BlockDBFlags.ManualPlace;

                byte flags = ParseFlags(row[2]);
                if ((flags & 1) == 0)   // block was placed
                {
                    entry.NewRaw = byte.Parse(row[3]);
                    if ((flags & 2) != 0)
                    {
                        entry.Flags |= BlockDBFlags.NewExtended;
                    }
                }
                BlockDBChange.Output(p, row[0], entry);
            }
        }
Exemple #11
0
        static void OutputEntry(Player p, ref bool foundAny, Dictionary <int, string> names, BlockDBEntry entry)
        {
            DateTime now  = DateTime.UtcNow;
            string   name = null;

            if (!names.TryGetValue(entry.PlayerID, out name))
            {
                name = NameConverter.FindName(entry.PlayerID);
                names[entry.PlayerID] = name;
            }
            foundAny = true;
            BlockDBChange.Output(p, name, entry);
        }
 public bool Prepare( Vector3I[] marks, BlockDBEntry[] changesToApply ) {
     if( changesToApply == null ) throw new ArgumentNullException( "changesToApply" );
     changes = changesToApply;
     return Prepare( marks );
 }