public void HandleManualChange(ushort x, ushort y, ushort z, bool placing, BlockID block, bool checkPlaceDist) { BlockID old = level.GetBlock(x, y, z); if (old == Block.Invalid) { return; } if (jailed || frozen || !canBuild) { RevertBlock(x, y, z); return; } if (!agreed) { Message(mustAgreeMsg); RevertBlock(x, y, z); return; } if (level.IsMuseum && Blockchange == null) { return; } bool deletingBlock = !painting && !placing; if (Unverified) { Message("%WYou must first verify with %T/Pass [Password]"); RevertBlock(x, y, z); return; } if (LSGame.Instance.Running && LSGame.Instance.Map == level && LSGame.Instance.IsPlayerDead(this)) { Message("You are out of the round, and cannot build."); RevertBlock(x, y, z); return; } if (ClickToMark && DoBlockchangeCallback(x, y, z, block)) { return; } OnBlockChangeEvent.Call(this, x, y, z, block, placing); if (cancelBlock) { cancelBlock = false; return; } if (old >= Block.Air_Flood && old <= Block.Door_Air_air) { Message("Block is active, you cannot disturb it."); RevertBlock(x, y, z); return; } if (!deletingBlock) { PhysicsArgs args = level.foundInfo(x, y, z); if (args.HasWait) { return; } } if (Rank == LevelPermission.Banned) { return; } if (checkPlaceDist) { int dx = Pos.BlockX - x, dy = Pos.BlockY - y, dz = Pos.BlockZ - z; int diff = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); if (diff > ReachDistance + 4) { Logger.Log(LogType.Warning, "{0} attempted to build with a {1} distance offset", name, diff); Message("You can't build that far away."); RevertBlock(x, y, z); return; } } BlockID held = block; block = BlockBindings[block]; if (!CheckManualChange(old, block, deletingBlock)) { RevertBlock(x, y, z); return; } if (ModeBlock != Block.Invalid) { block = ModeBlock; } // Ignores updating blocks that are the same and revert block back only to the player BlockID newB = deletingBlock ? Block.Air : block; if (old == newB) { if (painting || !Block.VisuallyEquals(old, held)) { RevertBlock(x, y, z); } return; } if (deletingBlock) { DeleteBlock(old, x, y, z, block); } else { ChangeResult result = PlaceBlock(old, x, y, z, block); // Client always assumes delete succeeds, so we need to echo back the painted over block // if the block was not changed visually (e.g. they paint white with door_white) if (painting && result != ChangeResult.Modified) { RevertBlock(x, y, z); } } }
public void ManualChange(ushort x, ushort y, ushort z, bool placing, ExtBlock block, bool checkPlaceDist) { ExtBlock old = level.GetBlock(x, y, z); if (old.IsInvalid) { return; } if (jailed || !canBuild) { RevertBlock(x, y, z); return; } if (!agreed) { SendMessage(mustAgreeMsg); RevertBlock(x, y, z); return; } if (level.IsMuseum && Blockchange == null) { return; } bool deletingBlock = !painting && !placing; if (ServerConfig.verifyadmins && adminpen) { SendMessage("&cYou must first verify with %T/Pass [Password]"); RevertBlock(x, y, z); return; } if (Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this)) { SendMessage("You are out of the round, and cannot build."); RevertBlock(x, y, z); return; } if (ClickToMark && DoBlockchangeCallback(x, y, z, block)) { return; } OnBlockChangeEvent.Call(this, x, y, z, block, placing); if (cancelBlock) { cancelBlock = false; return; } if (old.BlockID >= Block.Air_Flood && old.BlockID <= Block.Door_Air_air) { SendMessage("Block is active, you cannot disturb it."); RevertBlock(x, y, z); return; } if (!deletingBlock) { PhysicsArgs args = level.foundInfo(x, y, z); if (args.HasWait) { return; } } if (group.Permission == LevelPermission.Banned) { return; } if (checkPlaceDist) { int dx = Pos.BlockX - x, dy = Pos.BlockY - y, dz = Pos.BlockZ - z; int diff = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); if (diff > ReachDistance + 4) { Logger.Log(LogType.Warning, "{0} attempted to build with a {1} distance offset", name, diff); SendMessage("You can't build that far away."); RevertBlock(x, y, z); return; } } ExtBlock held = block; block = BlockBindings[block.RawID]; if (!CheckManualChange(old, block, deletingBlock)) { RevertBlock(x, y, z); return; } if (!ModeBlock.IsAir) { block = ModeBlock; } //Ignores updating blocks that are the same and revert block back only to the player ExtBlock newB = deletingBlock ? ExtBlock.Air : block; if (old == newB) { if (painting || !old.VisuallyEquals(held)) { RevertBlock(x, y, z); } return; } if (deletingBlock) { bool deleted = DeleteBlock(old, x, y, z, block); } else { bool placed = PlaceBlock(old, x, y, z, block); // Client always assumes delete succeeds, so we need to echo back the painted over block // if the block was not changed visually (e.g. they paint white with door_white) if (!placed && painting) { RevertBlock(x, y, z); } } }
public void ManualChange(ushort x, ushort y, ushort z, byte action, byte block, byte extBlock, bool checkPlaceDist) { byte old = level.GetTile(x, y, z), oldExt = 0; if (old == Block.Invalid) { return; } if (old == Block.custom_block) { oldExt = level.GetExtTile(x, y, z); } if (jailed || !agreed || !canBuild) { RevertBlock(x, y, z); return; } if (level.IsMuseum && Blockchange == null) { return; } if (action > 1) { const string msg = "Unknown block action!"; Leave(msg, msg, true); return; } bool doDelete = !painting && action == 0; if (Server.verifyadmins && adminpen) { SendMessage("&cYou must first verify with %T/pass [Password]"); RevertBlock(x, y, z); return; } if (Server.zombie.Running && Server.zombie.HandlesManualChange(this, x, y, z, action, block, old)) { return; } if (Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this)) { SendMessage("You are out of the round, and cannot build."); RevertBlock(x, y, z); return; } lastClick.X = x; lastClick.Y = y; lastClick.Z = z; if (Blockchange != null) { Blockchange(this, x, y, z, block, extBlock); return; } if (PlayerBlockChange != null) { PlayerBlockChange(this, x, y, z, block, extBlock); } OnBlockChangeEvent.Call(this, x, y, z, block, extBlock); if (cancelBlock) { cancelBlock = false; return; } if (old >= Block.air_flood && old <= Block.air_door_air) { SendMessage("Block is active, you cannot disturb it."); RevertBlock(x, y, z); return; } if (!deleteMode) { PhysicsArgs args = level.foundInfo(x, y, z); if (args.HasWait) { return; } } if (group.Permission == LevelPermission.Banned) { return; } if (checkPlaceDist && group.Permission == LevelPermission.Guest) { int dx = ((short)pos[0] / 32) - x, dy = ((short)pos[1] / 32) - y, dz = ((short)pos[2] / 32) - z; int diff = (int)Math.Sqrt(dx * dx + dy * dy + dz * dz); if (diff > ReachDistance + 4) { Server.s.Log(name + " attempted to build with a " + diff + " distance offset"); SendMessage("You can't build that far away."); RevertBlock(x, y, z); return; } } if (!CheckManualChange(old, block, doDelete)) { RevertBlock(x, y, z); return; } byte blockRaw = block; if (block < Block.CpeCount) { block = bindings[block]; } ushort flags = BlockDBFlags.ManualPlace; if (painting && !doDelete) { flags = BlockDBFlags.Painted; } //Ignores updating blocks that are the same and send block only to the player byte newBlock = (painting || action == 1) ? block : (byte)0; if (old == newBlock && (painting || blockRaw != block)) { if (old != Block.custom_block || extBlock == level.GetExtTile(x, y, z)) { RevertBlock(x, y, z); return; } } byte heldExt = 0; byte heldBlock = GetActualHeldBlock(out heldExt); int index = level.PosToInt(x, y, z); if (doDelete) { if (DeleteBlock(old, x, y, z, block, extBlock)) { level.BlockDB.Add(this, x, y, z, flags, old, oldExt, 0, 0); } } else { if (PlaceBlock(old, x, y, z, block, extBlock)) { level.BlockDB.Add(this, x, y, z, flags, old, oldExt, heldBlock, heldExt); } } }