Example #1
0
        int HandlePlayerClicked(byte[] buffer, int offset, int left)
        {
            const int size = 1 + 1 + 1 + 2 + 2 + 1 + 2 + 2 + 2 + 1;

            if (left < size)
            {
                return(0);
            }

            MouseButton Button   = (MouseButton)buffer[offset + 1];
            MouseAction Action   = (MouseAction)buffer[offset + 2];
            ushort      yaw      = NetUtils.ReadU16(buffer, offset + 3);
            ushort      pitch    = NetUtils.ReadU16(buffer, offset + 5);
            byte        entityID = buffer[offset + 7];
            ushort      x        = NetUtils.ReadU16(buffer, offset + 8);
            ushort      y        = NetUtils.ReadU16(buffer, offset + 10);
            ushort      z        = NetUtils.ReadU16(buffer, offset + 12);

            TargetBlockFace face = (TargetBlockFace)buffer[offset + 14];

            if (face > TargetBlockFace.None)
            {
                face = TargetBlockFace.None;
            }
            OnPlayerClickEvent.Call(this, Button, Action, yaw, pitch, entityID, x, y, z, face);
            return(size);
        }
Example #2
0
        void HandlePlayerClicked(byte[] packet)
        {
            if (OnPlayerClick == null)
            {
                return;
            }

            var    Button   = (MouseButton)packet[1];
            var    Action   = (MouseAction)packet[2];
            ushort Yaw      = NetUtils.ReadU16(packet, 3);
            ushort Pitch    = NetUtils.ReadU16(packet, 5);
            byte   EntityID = packet[7];
            ushort X        = NetUtils.ReadU16(packet, 8);
            ushort Y        = NetUtils.ReadU16(packet, 10);
            ushort Z        = NetUtils.ReadU16(packet, 12);
            byte   Face     = packet[14];

            var face = TargetBlockFace.None;

            if (Face < (byte)face)
            {
                face = (TargetBlockFace)Face;
            }
            OnPlayerClick(this, Button, Action, Yaw, Pitch, EntityID, X, Y, Z, face);
            OnPlayerClickEvent.Call(this, Button, Action, Yaw, Pitch, EntityID, X, Y, Z, face);
        }
Example #3
0
        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);
            }
        }
Example #4
0
        void ProcessBlockchange(byte[] buffer, int offset)
        {
            try {
                if (spamChecker.CheckBlockSpam())
                {
                    return;
                }
                ushort x = NetUtils.ReadU16(buffer, offset + 1);
                ushort y = NetUtils.ReadU16(buffer, offset + 3);
                ushort z = NetUtils.ReadU16(buffer, offset + 5);

                byte action = buffer[offset + 7];
                if (action > 1)
                {
                    Leave("Unknown block action!", true); return;
                }

                LastAction = DateTime.UtcNow;
                if (IsAfk)
                {
                    CmdAfk.ToggleAfk(this, "");
                }

                BlockID held = ReadBlock(buffer, offset + 8);
                ClientHeldBlock = held;

                if ((action == 0 || held == Block.Air) && !level.Config.Deletable)
                {
                    // otherwise if you're holding air and try to place a block, this message would show
                    if (!level.IsAirAt(x, y, z))
                    {
                        Message("Deleting blocks is disabled in this level.");
                    }

                    RevertBlock(x, y, z); return;
                }
                else if (action == 1 && !level.Config.Buildable)
                {
                    Message("Placing blocks is disabled in this level.");
                    RevertBlock(x, y, z); return;
                }

                if (held >= Block.Extended)
                {
                    if (!hasBlockDefs || level.CustomBlockDefs[held] == null)
                    {
                        Message("Invalid block type: " + Block.ToRaw(held));
                        RevertBlock(x, y, z); return;
                    }
                }
                HandleManualChange(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);
            }
        }
Example #5
0
        void HandleBlockchange(byte[] packet)
        {
            try {
                if (!loggedIn || spamChecker.CheckBlockSpam())
                {
                    return;
                }
                ushort x = NetUtils.ReadU16(packet, 1);
                ushort y = NetUtils.ReadU16(packet, 3);
                ushort z = NetUtils.ReadU16(packet, 5);
                if (frozen)
                {
                    RevertBlock(x, y, z); return;
                }

                byte action = packet[7], block = packet[8];
                byte extBlock = block;
                RawHeldBlock = block;

                if ((action == 0 || block == 0) && !level.Deletable)
                {
                    SendMessage("Deleting blocks is disabled in this level.");
                    RevertBlock(x, y, z); return;
                }
                else if (action == 1 && !level.Buildable)
                {
                    SendMessage("Placing blocks is disabled in this level.");
                    RevertBlock(x, y, z); return;
                }

                if (block >= Block.CpeCount)
                {
                    if (!hasBlockDefs || level.CustomBlockDefs[block] == null)
                    {
                        SendMessage("Invalid block type: " + block);
                        RevertBlock(x, y, z); return;
                    }
                    extBlock = block;
                    block    = Block.custom_block;
                }
                ManualChange(x, y, z, action, block, extBlock);
            } 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);
                Server.ErrorLog(e);
            }
        }
Example #6
0
        void HandleTwoWayPing(byte[] buffer, int offset)
        {
            bool   serverToClient = buffer[offset + 1] != 0;
            ushort data           = NetUtils.ReadU16(buffer, offset + 2);

            if (!serverToClient)
            {
                // Client-> server ping, immediately send reply.
                Send(Packet.TwoWayPing(false, data));
            }
            else
            {
                // Server -> client ping, set time received for reply.
                Ping.Update(data);
            }
        }
        BlockID ReadBlock(byte[] buffer, int offset)
        {
            BlockID block;

            if (hasExtBlocks)
            {
                block = NetUtils.ReadU16(buffer, offset);
            }
            else
            {
                block = buffer[offset];
            }

            if (block > Block.MaxRaw)
            {
                block = Block.MaxRaw;
            }
            return(Block.FromRaw(block));
        }
Example #8
0
        int HandleTwoWayPing(byte[] buffer, int offset, int left)
        {
            const int size = 1 + 1 + 2;

            if (left < size)
            {
                return(0);
            }

            bool   serverToClient = buffer[offset + 1] != 0;
            ushort data           = NetUtils.ReadU16(buffer, offset + 2);

            if (!serverToClient)
            {
                // Client-> server ping, immediately send reply.
                Send(Packet.TwoWayPing(false, data));
            }
            else
            {
                // Server -> client ping, set time received for reply.
                Ping.Update(data);
            }
            return(size);
        }
Example #9
0
        void HandleMovement(byte[] packet)
        {
            if (!loggedIn || trainGrab || following != "")
            {
                return;
            }
            byte heldBlock = packet[1];

            if (HasCpeExt(CpeExt.HeldBlock))
            {
                RawHeldBlock = heldBlock;
            }

            ushort x = NetUtils.ReadU16(packet, 2);
            ushort y = NetUtils.ReadU16(packet, 4);
            ushort z = NetUtils.ReadU16(packet, 6);
            byte   rotx = packet[8], roty = packet[9];

            if (frozen)
            {
                bool movedX = Math.Abs((short)x - (short)pos[0]) > 4;  // moved more than 0.125 blocks horizontally
                bool movedY = Math.Abs((short)y - (short)pos[1]) > 40; // moved more than 1.25 blocks vertically
                bool movedZ = Math.Abs((short)z - (short)pos[2]) > 4;  // moved more than 0.125 blocks horizontally
                if (movedX || movedY || movedZ)
                {
                    SendPos(Entities.SelfID, pos[0], pos[1], pos[2], rotx, roty);
                }
                return;
            }

            if (Server.Countdown.HandlesMovement(this, x, y, z, rotx, roty))
            {
                return;
            }
            if (Server.zombie.Running && Server.zombie.HandlesMovement(this, x, y, z, rotx, roty))
            {
                return;
            }

            if (OnMove != null)
            {
                OnMove(this, x, y, z);
            }
            if (PlayerMove != null)
            {
                PlayerMove(this, x, y, z);
            }
            PlayerMoveEvent.Call(this, x, y, z);

            if (OnRotate != null)
            {
                OnRotate(this, rot);
            }
            if (PlayerRotate != null)
            {
                PlayerRotate(this, rot);
            }
            PlayerRotateEvent.Call(this, rot);

            if (cancelmove)
            {
                SendPos(Entities.SelfID, pos[0], pos[1], pos[2], rot[0], rot[1]); return;
            }

            pos = new ushort[3] {
                x, y, z
            };
            rot = new byte[2] {
                rotx, roty
            };
            if (!Moved() || Loading)
            {
                return;
            }
            if (DateTime.UtcNow < AFKCooldown)
            {
                return;
            }

            LastAction = DateTime.UtcNow;
            if (IsAfk)
            {
                CmdAfk.ToggleAfk(this, "");
            }
            /*if (!CheckIfInsideBlock()) { clippos = pos; cliprot = rot; }*/
        }