public void UpdateCustomBlock(byte raw, BlockDefinition def) { CustomBlockDefs[raw] = def; ExtBlock block = ExtBlock.FromRaw(raw); UpdateBlockHandler(block); blockAABBs[block.Index] = Block.BlockAABB(block, this); }
void HandleBlockchange(byte[] buffer, int offset) { try { if (!loggedIn || spamChecker.CheckBlockSpam()) { return; } ushort x = NetUtils.ReadU16(buffer, offset + 1); ushort y = NetUtils.ReadU16(buffer, offset + 3); ushort z = NetUtils.ReadU16(buffer, offset + 5); if (frozen) { RevertBlock(x, y, z); return; } byte action = buffer[offset + 7]; if (action > 1) { const string msg = "Unknown block action!"; Leave(msg, msg, true); return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } ExtBlock held = ExtBlock.FromRaw(buffer[offset + 8]); RawHeldBlock = held; if ((action == 0 || held.BlockID == Block.Air) && !level.Config.Deletable) { SendMessage("Deleting blocks is disabled in this level."); RevertBlock(x, y, z); return; } else if (action == 1 && !level.Config.Buildable) { SendMessage("Placing blocks is disabled in this level."); RevertBlock(x, y, z); return; } if (held.BlockID == Block.custom_block) { if (!hasBlockDefs || level.CustomBlockDefs[held.ExtID] == null) { SendMessage("Invalid block type: " + held.ExtID); RevertBlock(x, y, z); return; } } ManualChange(x, y, z, action != 0, held, true); } catch (Exception e) { // Don't ya just love it when the server tattles? Chat.MessageOps(DisplayName + " has triggered a block change error"); Chat.MessageOps(e.GetType().ToString() + ": " + e.Message); Logger.LogError(e); } }
internal Player() { spamChecker = new SpamChecker(this); SessionID = Interlocked.Increment(ref sessionCounter) & SessionIDMask; for (int i = 0; i < BlockBindings.Length; i++) { BlockBindings[i] = ExtBlock.FromRaw((byte)i); } }
public static void UpdateGlobalBlockProps() { for (int i = 0; i < GlobalProps.Length; i++) { ExtBlock block = ExtBlock.FromRaw((byte)i); GlobalProps[i] = BlockProps.MakeDefault(); GlobalProps[i] = DefaultProps(block); } BlockProps.Load("global", GlobalProps, GlobalPropsLock, false); }
void HandleMovement(byte[] buffer, int offset) { if (!loggedIn || trainGrab || following.Length > 0) { CheckBlocks(Pos); return; } if (Supports(CpeExt.HeldBlock)) { RawHeldBlock = ExtBlock.FromRaw(buffer[offset + 1]); } int x, y, z; if (hasExtPositions) { x = NetUtils.ReadI32(buffer, offset + 2); y = NetUtils.ReadI32(buffer, offset + 6); z = NetUtils.ReadI32(buffer, offset + 10); offset += 6; // for yaw/pitch offset below } else { x = NetUtils.ReadI16(buffer, offset + 2); y = NetUtils.ReadI16(buffer, offset + 4); z = NetUtils.ReadI16(buffer, offset + 6); } byte yaw = buffer[offset + 8], pitch = buffer[offset + 9]; Position next = new Position(x, y, z); CheckBlocks(next); OnPlayerMoveEvent.Call(this, next, yaw, pitch); if (cancelmove) { cancelmove = false; return; } Pos = next; SetYawPitch(yaw, pitch); if (!Moved() || Loading) { return; } if (DateTime.UtcNow < AFKCooldown) { return; } LastAction = DateTime.UtcNow; if (IsAfk) { CmdAfk.ToggleAfk(this, ""); } }
static void UpdateLoadedLevels(BlockDefinition[] oldGlobalDefs) { Level[] loaded = LevelInfo.Loaded.Items; foreach (Level lvl in loaded) { for (int i = 0; i < lvl.CustomBlockDefs.Length; i++) { if (lvl.CustomBlockDefs[i] != oldGlobalDefs[i]) { continue; } ExtBlock block = ExtBlock.FromRaw((byte)i); lvl.Props[block.Index] = DefaultProps(block); lvl.UpdateCustomBlock(block.RawID, GlobalDefs[i]); } } }