Example #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);
                }
            }
        }
Example #2
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);
        }
Example #3
0
        bool PlacedMark(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            ushort x = (ushort)marks[0].X, y = (ushort)marks[0].Y, z = (ushort)marks[0].Z;

            block = p.level.GetBlock(x, y, z);
            p.RevertBlock(x, y, z);
            Dictionary <int, string> names = new Dictionary <int, string>();

            p.Message("Retrieving block change records..");

            bool foundAny = false;

            ListFromDatabase(p, ref foundAny, x, y, z);
            using (IDisposable rLock = p.level.BlockDB.Locker.AccquireRead(30 * 1000)) {
                if (rLock != null)
                {
                    p.level.BlockDB.FindChangesAt(x, y, z,
                                                  entry => OutputEntry(p, ref foundAny, names, entry));
                }
                else
                {
                    p.Message("&WUnable to accquire read lock on BlockDB after 30 seconds, aborting.");
                    return(false);
                }
            }

            if (!foundAny)
            {
                p.Message("No block change records found for this block.");
            }
            BlockID raw       = Block.IsPhysicsType(block) ? block : Block.ToRaw(block);
            string  blockName = Block.GetName(p, block);

            p.Message("Block ({0}, {1}, {2}): &f{3} = {4}%S.", x, y, z, raw, blockName);

            CommandData data = (CommandData)state;

            if (HasExtraPerm(p, data.Rank, 1))
            {
                BlockDBChange.OutputMessageBlock(p, block, x, y, z);
                BlockDBChange.OutputPortal(p, block, x, y, z);
            }
            Server.DoGC();
            return(true);
        }
Example #4
0
        void PlacedBlock(Player p, ushort x, ushort y, ushort z, byte type, byte extType)
        {
            if (!p.staticCommands)
            {
                p.ClearBlockchange();
            }
            byte b = p.level.GetTile(x, y, z);

            if (b == Block.Invalid)
            {
                Player.Message(p, "Invalid Block ({0}, {1}, {2}).", x, y, z); return;
            }
            p.RevertBlock(x, y, z);

            byte id = b;

            if (b == Block.custom_block)
            {
                id = p.level.GetExtTile(x, y, z);
            }
            Dictionary <int, string> names = new Dictionary <int, string>();

            string blockName = p.level.BlockName(b, id);

            Player.Message(p, "Block ({0}, {1}, {2}): &f{3} = {4}%S.", x, y, z, id, blockName);
            bool foundAny = false;

            ListFromDatabase(p, ref foundAny, names, x, y, z);
            p.level.BlockDB.FindChangesAt(x, y, z,
                                          entry => OutputEntry(p, ref foundAny, names, entry));
            ListInMemory(p, ref foundAny, names, x, y, z);

            if (!foundAny)
            {
                Player.Message(p, "No block change records found for this block.");
            }
            BlockDBChange.OutputMessageBlock(p, b, id, x, y, z);
            BlockDBChange.OutputPortal(p, b, id, x, y, z);

            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Example #5
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);
            }
        }