Example #1
0
        public bool DoBlockchange(Player p, ushort x, ushort y, ushort z,
                                  byte block, byte extBlock = 0, bool drawn = false)
        {
            string errorLocation = "start";

retry:
            try
            {
                //if (x < 0 || y < 0 || z < 0) return;
                if (x >= Width || y >= Height || z >= Length)
                {
                    return(false);
                }
                byte old = GetTile(x, y, z), extOld = 0;
                if (old == Block.custom_block)
                {
                    extOld = GetExtTile(x, y, z);
                }

                errorLocation = "Permission checking";
                if (!CheckAffectPermissions(p, x, y, z, old, block, extBlock))
                {
                    p.RevertBlock(x, y, z); return(false);
                }

                if (old == Block.sponge && physics > 0 && block != Block.sponge)
                {
                    OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z));
                }
                if (old == Block.lava_sponge && physics > 0 && block != Block.lava_sponge)
                {
                    OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true);
                }

                errorLocation = "Undo buffer filling";
                Player.UndoPos Pos;
                Pos.x         = x; Pos.y = y; Pos.z = z;
                Pos.mapName   = name;
                Pos.type      = old; Pos.extType = extOld;
                Pos.newtype   = block; Pos.newExtType = extBlock;
                Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds;
                p.UndoBuffer.Add(this, Pos);

                errorLocation = "Setting tile";
                p.IncrementBlockStats(block, drawn);

                SetTile(x, y, z, block);
                if (old == Block.custom_block && block != Block.custom_block)
                {
                    RevertExtTileNoCheck(x, y, z);
                }
                if (block == Block.custom_block)
                {
                    SetExtTileNoCheck(x, y, z, extBlock);
                }

                errorLocation = "Adding physics";
                if (p.PlayingTntWars && block == Block.smalltnt)
                {
                    AddTntCheck(PosToInt(x, y, z), p);
                }
                if (physics > 0 && ActivatesPhysics(block, extBlock))
                {
                    AddCheck(PosToInt(x, y, z));
                }

                changed  = true;
                backedup = false;
                bool diffBlock = old == Block.custom_block ? extOld != extBlock :
                                 Block.Convert(old) != Block.Convert(block);
                return(diffBlock);
            } catch (OutOfMemoryException) {
                Player.Message(p, "Undo buffer too big! Cleared!");
                p.UndoBuffer.Clear();
                p.RemoveInvalidUndos();
                goto retry;
            } catch (Exception e) {
                Server.ErrorLog(e);
                Chat.MessageOps(p.name + " triggered a non-fatal error on " + ColoredName);
                Chat.MessageOps("Error location: " + errorLocation);
                Server.s.Log(p.name + " triggered a non-fatal error on " + ColoredName);
                Server.s.Log("Error location: " + errorLocation);
                return(false);
            }
        }