Esempio n. 1
0
        static bool CursedLand(Client player, PlayerBlockPlacement placement)
        {
            SlotItem i = player.Session.ActiveItem;

            if (i != null && i.ItemID == BlockID.Bucket)
            {
                var pps = new PlayerPositionLookClient();
                pps.Position    = placement.BlockPosition.CloneDouble();
                pps.OnGround    = false;
                pps.Position.Y += 1.1;
                pps.Position.X += 0.5;
                pps.Position.Z += 0.5;
                pps.Pitch       = Math.PI / 2;
                pps.Yaw         = player.Session.Yaw;
                player.FromClient(pps);

                var ppc = new PlayerPositionLookServer(pps.Position);
                ppc.Pitch = Math.PI / 2;
                ppc.Yaw   = player.Session.Yaw;
                player.SendToClient(ppc);
            }

            BlockChange bc = new BlockChange(placement.BlockPosition.Offset(placement.FaceDirection), BlockID.Air);

            player.SendToClient(bc);

            //Block all actions
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// What the Client sends to the server.
        /// </summary>
        public override void FromClient(PacketFromClient packet)
        {
            while (phase == Phases.Handshake)
            {
                Thread.Sleep(100);
            }
            //Wait for handshake to complete
            if (phase == Phases.FinalClose)
            {
                throw new SessionClosedException();
            }

            if (packet.PacketID == PassThrough.ID)
            {
                SendToBackend(packet);
                return;
            }

            //Fix players eid to what is known for the server
            if (packet is IEntity)
            {
                IEntity ie = (IEntity)packet;
                if (ie.EID == Player.EntityID)
                {
                    ie.EID = EID;
                    packet.SetPacketBuffer(null);
                }
            }

            WorldRegion region = CurrentRegion;

            switch (packet.PacketID)
            {
            case PlayerPosition.ID:
                if (AttachedEntity > 0)
                {
                    //Ignore relative movements
                }
                else
                {
                    var pp = ((PlayerPosition)packet);
                    if (pp.Position.Y > -900)
                    {
                        SetPosition(pp.Position, true);
                        OnGround = pp.OnGround != 0;
                    }
                }
                break;

            case PlayerPositionLookClient.ID:
                if (AttachedEntity > 0)
                {
                    //Ignore relative movements
                }
                else
                {
                    PlayerPositionLookClient pp = ((PlayerPositionLookClient)packet);
                    if (pp.Position.Y > -900)
                    {
                        SetPosition(pp.Position, true);
                        OnGround = pp.OnGround;
                    }
                }
                Pitch = ((PlayerPositionLookClient)packet).Pitch;
                Yaw   = ((PlayerPositionLookClient)packet).Yaw;
                break;

            case PlayerGround.ID:
                OnGround = ((PlayerGround)packet).OnGround;
                //Good but a few false positives

                /*
                 * if (Sprinting)//Hacked client: Invalid sprint
                 * {
                 *  Chatting.Parser.TellAdmin(Player.Name + Chat.Gray + " sprinting standing still");
                 * }*/
                break;

            case  EntityAction.ID:
                EntityAction ea = packet as EntityAction;
                switch (ea.Action)
                {
                case EntityAction.Actions.LeaveBed:
                    Sleeping = false;
                    break;

                case EntityAction.Actions.Crounch:
                    Crouched = true;
                    break;

                case EntityAction.Actions.Uncrounch:
                    Crouched = false;
                    break;

                case EntityAction.Actions.StartSprinting:
                    Sprinting = true;
                    break;

                case EntityAction.Actions.StopSprinting:
                    Sprinting = false;
                    break;
                }
                break;

            case UseEntity.ID:
                if (Mode == GameMode.Creative && (Player.Admin(Permissions.AnyAdmin) == false))
                {
                    return;     //Donors can't hurt while in creative mode
                }
                if (UseEntityFromClient((UseEntity)packet))
                {
                    return;
                }
                break;

            case HeldItemClient.ID:
                //Active item
                var hc = (HeldItemClient)packet;
                if (hc.SlotID >= 0 && hc.SlotID <= 8)
                {
                    ActiveInventoryIndex = hc.SlotID;
                }
                else
                {
                    Log.Write(
                        new InvalidOperationException("Invalid holding slot id: " + hc.SlotID),
                        this.Player
                        );
                }
                break;

            //Prevent non admins from getting items in creative
            case CreativeInventory.ID:
                if (Player.Admin(Permissions.CreativeBuild) == false)
                {
                    Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt));
                    Player.TellSystem(Chat.Yellow, "Creative Inventory Disabled");
                    return;
                }

                CreativeInventory ci = (CreativeInventory)packet;
                if (0 <= ci.Slot && ci.Slot <= Inventory.Length)
                {
                    Inventory[ci.Slot] = ci.Item;
                }
                break;

            //If block action is done from another region
            case PlayerBlockPlacement.ID:
                //AfkTime = DateTime.Now;

                //Non admins can't place block
                if (Mode == GameMode.Creative && (Player.Admin(Permissions.CreativeBuild) == false))
                {
                    Player.SendToClient(new EntityStatus(Player.EntityID, EntityStatuses.EntityHurt));
                    Player.TellSystem(Chat.Yellow, "Creative Build Disabled");
                    return;
                }

                PlayerBlockPlacement pb = (PlayerBlockPlacement)packet;
                if (pb.BlockPosition.IsNull() == false)
                {
                    CoordDouble pos = pb.BlockPosition.CloneDouble();
                    region = RegionCrossing.GetRegion(pos, Dimension, World.Regions);
                    //Remember the last position clicked so we can do better chest protection
                    LastClickRegion = region;     //this is obsolete since we moved to blocking open across regions
                }
                else
                {
                    if (pb.Item != null)
                    {
                        Charge = new ChargeState(pb.Item.ItemID);
                    }
                }

                if (FilterDirection(pb.BlockPosition))
                {
                    return;
                }

                if (region == null)
                {
                    if (Dimension == 0 && FilterLava(pb))
                    {
                        return;
                    }
                }
                if (Protected.ProtectBlockPlace(this, region, pb))
                {
                    return;
                }

                break;

            case PlayerDigging.ID:
                //AfkTime = DateTime.Now;
                PlayerDigging pd = (PlayerDigging)packet;
                if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging || pd.Status == PlayerDigging.StatusEnum.StartedDigging)
                {
                    CoordDouble pos = pd.Position.CloneDouble();
                    region = RegionCrossing.GetRegion(pos, Dimension, World.Regions);
                }
                //Log breaking blocks to determine if they found the diamond
                if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging)
                {
                    OreTracker.BrokeBlock = DateTime.Now;
                }

                if (pd.Status == PlayerDigging.StatusEnum.ShootArrow)
                {
                    Charge = null;
                }

                //Prevent non admin creative from digging
                if (Mode == GameMode.Creative && Player.Admin(Permissions.AnyAdmin) == false)
                {
                    return;
                }
                if (FilterDirection(pd.Position))
                {
                    return;
                }

                if (Protected.ProtectBlockBreak(this, region, pd))
                {
                    return;
                }
                break;

            case WindowClick.ID:
                var wc = packet as WindowClick;
                if (wc.WindowID == 0)
                {
                    //TODO: handle
                }
                //AfkTime = DateTime.Now;
                if (Protected.ProtectChestsClick(this, wc))
                {
                    return;
                }

                ///Workaround bug clicky items duplication
                if (wc.Item != null)
                {
                    if (wc.Item.Count > 64)
                    {
                        return;
                    }
                }
                break;

            case WindowCloseClient.ID:
                WindowClose((WindowCloseClient)packet);
                break;
            }

            if (region != null)
            {
                if (region.Type == SpawnRegion.Type)
                {
                    if (SpawnRegion.FilterClient(Player, packet))
                    {
                        return;
                    }
                }
                if (region.Type == SpawnTimeRegion.Type)
                {
                    if (SpawnTimeRegion.FilterClient(region, Player, packet))
                    {
                        return;
                    }
                }
            }

            SendToBackend(packet);
        }
Esempio n. 3
0
        public override void FromClient(PacketFromClient packet)
        {
            switch (packet.PacketID)
            {
                #region Block place/break

            case PlayerDigging.ID:
                PlayerDigging pd = packet as PlayerDigging;
                if (pd.Status == PlayerDigging.StatusEnum.FinishedDigging)
                {
                    QueueToAll(new BlockChange(pd.Position, BlockID.Air));
                }
                return;

                /* TODO: fix: crashes with new items such as pot
                 *  case PlayerBlockPlacement.ID:
                 *      PlayerBlockPlacement pbp = packet as PlayerBlockPlacement;
                 *      if(pbp.Item == null)
                 *          return;
                 *      var bc = new BlockChange(pbp.BlockPosition.Offset(pbp.FaceDirection), pbp.Item.ItemID);
                 *      bc.Metadata = (byte)pbp.Item.Uses;
                 *      QueueToAll(bc);
                 *      return;*/

                #endregion

                #region Moving Looking

            case PlayerPositionLookClient.ID:
            {
                PlayerPositionLookClient p = (PlayerPositionLookClient)packet;

                SetPosition(p.Position, true);
                Pitch = p.Pitch;
                Yaw   = p.Yaw;

                if (Player.Settings.Cloaked == null)
                {
                    EntityTeleport et = new EntityTeleport(Player.EntityID, p.Position);
                    et.Yaw   = p.Yaw;
                    et.Pitch = p.Pitch;
                    QueueToAllButMe(et);

                    QueueToAllButMe(new EntityHeadYaw(Player.EntityID, Yaw));
                }
                CheckPosition();
                return;
            }

                #endregion

            case UseEntity.ID:
                //UseEntity ue = (UseEntity)packet;
                //Sender see hurt
                //New: hurt attacker, old: ue.Target
                QueueToAll(new EntityStatus(this.Player.EntityID, EntityStatuses.EntityHurt));
                QueueToAll(new Effect(SoundEffects.MobSpawn, Position.CloneInt()));
                return;

#if DEBUG
            case PlayerGround.ID:
            case KeepAlivePing.ID:    //case KeepAlivePong.ID:
                return;

            default:
                //Console.WriteLine("Unhandled: " + packet);
                return;
#endif
            }
        }