Exemplo n.º 1
0
        void Set(Client player, string[] cmd, int iarg)
        {
            int ymin, ymax;

            if (cmd.Length == iarg + 2)
            {
                if (int.TryParse(cmd [iarg], out ymin) == false)
                {
                    throw new ErrorException("argument not an integer");
                }
                if (int.TryParse(cmd [iarg + 1], out ymax) == false)
                {
                    throw new ErrorException("argument not an integer");
                }
            }
            else if (cmd.Length == iarg)
            {
                ymin = 50;
                ymax = 256;
            }
            else
            {
                throw new ShowHelpException();
            }
            SetRegionEnd(player, ymin, ymax);
            RegionCrossing.SetRegion(player.Session);
        }
Exemplo n.º 2
0
        void Delete(Client player, string[] cmd, int iarg)
        {
            if (player.Admin() == false)
            {
                throw new ErrorException("Disabled");
            }
            WorldRegion region = player.Session.CurrentRegion;

            if (region == null)
            {
                throw new ErrorException("No region here");
            }

            if (cmd.Length <= iarg)
            {
                throw new ShowHelpException(); //Need more arguments
            }
            RegionList regions = player.Session.World.Regions;

            string subdel = cmd [iarg].ToLowerInvariant();

            switch (subdel)
            {
            case "single":
                DeleteSingle(region, regions);
                player.TellSystem(Chat.Purple, region.Name + " removed");
                player.Session.CurrentRegion = null;
                break;

            case "recursive":
                DeleteRecursive(region);
                player.TellSystem(Chat.Purple, region.Name + " and subregions removed");
                region.Deleted = true;
                player.Session.CurrentRegion = null;
                break;

            case "subonly":
                DeleteSubregions(region);
                player.TellSystem(Chat.Purple, "Subregions of " + region.Name + " removed");
                break;

            default:
                throw new ShowHelpException();
            }
            RegionLoader.Save(regions);

            //Update all players regions
            foreach (var p in PlayerList.List)
            {
                RegionCrossing.SetRegion(p.Session);
            }

            ScoreboardRegionManager.UpdateAllPlayersRegion();
        }
Exemplo n.º 3
0
        protected virtual void SetPosition(CoordDouble pos, bool speedguard)
        {
            if (World.Regions != null)
            {
                RegionCrossing.SetRegion(this);
            }

            if (Mode == GameMode.Creative)
            {
                speedguard = false;
            }
            if (Mode == GameMode.Spectator)
            {
                speedguard = false;
            }

            if (speedguard)
            {
                SpeedGuard.ClientMovement(this, pos);
            }
            Position = pos;
        }
Exemplo n.º 4
0
        internal static WorldRegion Create(Dimensions dimension, CoordDouble start, CoordDouble end, string regionName, Client player, string resident, RegionList regions)
        {
            if (regions == null)
            {
                throw new ErrorException("No regions in this world");
            }

            WorldRegion w = new WorldRegion(dimension, start, end, regionName);

            w.Residents.Add(resident);
            w.Type = "protected";

            lock (regions)
            {
                //Test for overlapping regions
                WorldRegion existing = RegionCrossing.GetBaseRegion(regions.List, w, dimension);
                if (existing == null)
                {
                    //New Top level region
                    regions.List.Add(w);
                    RegionLoader.Save(regions);
                    return(w);
                }

                //Make sure you already are a part of the region
                if (existing.ResidentPermissions(player) == false)
                {
                    throw new ErrorException("You can't set a subregion unless you are a resident in the parent region.");
                }

                //All inside, make subregion
                if (existing.Cover(w))
                {
                    if (existing.SubRegions == null)
                    {
                        existing.SubRegions = new List <WorldRegion>();
                    }
                    existing.SubRegions.Add(w);
                    RegionLoader.Save(regions);
                    return(w);
                }
                //Need to make a wrapping region

                //Only admins may create wrapping regions
                if (player != null && player.Admin() == false)
                {
                    throw new ErrorException("New region must be fully inside " + existing);
                }

                //New region covering several old ones?
                var parentList = WorldRegion.GetParentList(regions, existing);
                if (parentList == null)
                {
                    throw new ErrorException("Parent list not found for " + existing);
                }

                //regions to move inside the new one
                var moving = new List <WorldRegion>();

                //Determine if we are breaking any boundaries
                bool breaking = false;
                foreach (var s in parentList)
                {
                    if (w.Cover(s))
                    {
                        moving.Add(s);
                    }
                    else if (w.Overlap(s))   //Overlap but not cover completely
                    {
                        player.TellSystem(Chat.Red, "Breaking boundaries: " + s);
                        breaking = true;
                    }
                }
                if (breaking)
                {
                    player.TellSystem(Chat.Red, "Failed creating: " + w);
                    player.TellSystem(Chat.Red, "Aborting: Broke region boundaries");
                    return(null);
                }

                //Move subregions into new region and remove from parentlist
                w.SubRegions = moving;
                foreach (var s in moving)
                {
                    player.TellSystem(Chat.Aqua, "New subregion: " + s);
                    parentList.Remove(s);
                }
                parentList.Add(w);
                RegionLoader.Save(regions);
                return(w);
            }
        }
Exemplo n.º 5
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);
        }